Ok. So I started my project itself today. I decided to make a very cool program.
For that, I think I would need to learn about databases. As I need to store a lot of information in kind of a structured way, I think a database wouldn't be a bad idea. I found some online tutorials on those:
http://www.geekgirls.com/databasics_01.htm
I'm going to research that a little. I am still going to use the shaping of windows code, I think it's really cool. I don't know about control arrays, I guess I wouldn't need them as much. But even if I do, I found something interesting today. The member variables that I found once and didn't know what to do with them, could actually serve as a way to establish an array. They are kind of like pointers, but to the controls, and they can be represented as an array, so. That works for me.
Thursday, February 21, 2008
Tuesday, February 12, 2008
Shaping the windows
I just found this very cool code! I found out that MFC is good of course, but an empty Win32 would be much better, there are so much more opportunities in it. Although I can't see the dialog itself and arrange all the control elements on the form, I can do it through the code.
Therefore, I found a code to actually change the shape of the window. You would only need an original bmp image with a shape. In bmp format, the compiler sees white as blank space, so I can actually draw the shape of my window. I would just need the following code:
And all the other usual code routines.
I also found out I need to include "windows.h" in any windows application I do. There is also a huge code for just creating a new window and showing it on the screen, which I am trying to understand by lines now. It seems not so hard, but really cool!
Therefore, I found a code to actually change the shape of the window. You would only need an original bmp image with a shape. In bmp format, the compiler sees white as blank space, so I can actually draw the shape of my window. I would just need the following code:
BOOL CreateMainWnd(HINSTANCE hInstance)
{
HFONT buttonfont; /*create windows and set fonts*/
hwMain = CreateWindowEx(0,"Window Shaping","Window Shaping", WS_OVERLAPPED,50,50,450,350,0,0,hInstance,0);
hwStatica = CreateWindowEx(0,"Button","Sant Bani",WS_CHILD | WS_VISIBLE | SS_CENTER, 100,88,50,20,hwMain,0,hInstance,0);
hwStaticb = CreateWindowEx(0,"Button","Exit",WS_CHILD | WS_VISIBLE | SS_CENTER, 194,88,50,20,hwMain,0,hInstance,0);
buttonfont = CreateFont(16,0,FW_DONTCARE,FW_DONTCARE,FW_DONTCARE,
FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Arial");
SendMessage(hwStatica,WM_SETFONT,reinterpret_cast(buttonfont),MAKELPARAM(1, 0));
SendMessage(hwStaticb,WM_SETFONT,reinterpret_cast(buttonfont),MAKELPARAM(1, 0));
SetWindowPos(hwMain,HWND_TOPMOST,50,50,626,374, NULL);
ShowWindow(hwMain,1);
if(!hwMain)
return FALSE;
return TRUE;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
switch(wMsg) {
case WM_DESTROY:
PostQuitMessage(0); /*destroy window*/
return 0;
break;
case WM_PAINT:
HDC hdcTemp, bpHDC;
PAINTSTRUCT sentinel;
BITMAP bm;
bpHDC = BeginPaint(hwMain, &sentinel);
if(work) /*if its our first time painting, shape the window*/
{
ShowWindow(hwMain,0); /* window not visible until shaped*/
Mold(bpHDC);
ShowWindow(hwMain,1);
}
hdcTemp = CreateCompatibleDC(bpHDC); /*load and bitblt image to our hdc*/
hwBmp = LoadBitmap(hInst,MAKEINTRESOURCE(102));
SelectObject(hdcTemp,static_cast(hwBmp));
GetObject(static_cast(hwBmp),sizeof(bm),&bm);
BitBlt(bpHDC,0,-30,bm.bmWidth,bm.bmHeight,hdcTemp,0,0,SRCCOPY);
DeleteDC(bpHDC); /*delete uneeded objects to free up memory*/
DeleteDC(hdcTemp);
EndPaint(hwMain,&sentinel);
return 0;
break;
case WM_COMMAND:
/*put a couple of buttons there, just for fun*/
if(wParam == BN_CLICKED)
{
if(reinterpret_cast(lParam) == hwStatica)
ShellExecute(NULL, "open", "http://www.santbani.org", NULL, NULL, SW_SHOWNORMAL);
else if(reinterpret_cast(lParam) == hwStaticb)
DestroyWindow(hwMain);
}
return 0;
break;
case WM_LBUTTONDOWN:
SendMessage(hwMain,WM_SYSCOMMAND,SC_MOVE,0); /*tell the window the user wants to move the window*/
break;
default:
return DefWindowProc(hWnd,wMsg,wParam,lParam);
}
return FALSE;
}
And all the other usual code routines.
I also found out I need to include "windows.h" in any windows application I do. There is also a huge code for just creating a new window and showing it on the screen, which I am trying to understand by lines now. It seems not so hard, but really cool!
Thursday, February 7, 2008
Input/Output
As the control arrays still remain unsolved, I have met another problem when converting the code. The very first thing is input and output format. As I want the user to enter the numbers into textboxes, I was trying to find a code to convert all those variables. The first thing is, when I use AfxMessageBox, I can't do the same things I could with "cout". For example the line
cout << "cell(" <<>
would just give me huge error in AfxMessageBox. It says me that the first parameter should be a string value for this function. So I decided to put everything into another string variable before calling the function:
outString="cell("+(i+1)+","...."\n"
But then I find that I also need to convert the number into a string before that:
_itoa(i+1,buffer,10);
And then I find out that it doesn't convert it exactly into the type of string I want it to be converted into. So I have to use this:
...+(Char::ToString(buffer))+...
This is what the tutorial told me. But. The tutorial says I would need using namespace System
for that, but my compiler doesn't like it at all. So I'm kind of stuck here.
Actually I don't really need this, as I'm going to output everything in the same textboxes on the form, but anyways, how would I do that if I needed to?
I'm going to do more research on strings.
Sunday, February 3, 2008
Control arrays
So I'm now trying to convert my sudoku solver into a windows application. I created a new MFC and put a bunch of controls on the form and "explored" whatever I could do with them without touching the code itself.
Then I started converting the console code into a windosapp code. The first thing I ran into is that I can't create a control array as easily as in Visual Basic. The default naming of the controls doesn't give me such options, whatever I tried. As I need to get data from the cells the whole thing would look like.
That's what happens when put the event handler for my Clear button. (Haven't started with the Solve one yet) So what I run into is that I have to write 81*2=162(!) lines of code just for this little event! So I want to make a loop for that, but the problem is that I can't make an array of pointers, because the object the pointers point to is not an array. And I couldn't find the declaration of the CEdit class, as it is probably a default one and it's hiding somewhere I can't reach. I'm now trying to create a new array of the CEdit class, so that I can put them all in an array and maybe even use the same one pointer for each of them. The problem is I can't display my new class array objects on the form, I can't put them on the control panel and just "draw", because they are not default. So it's kind of complicated. I'll do some more research on that.
At least I got how the whole windowsapp thing works.
Then I started converting the console code into a windosapp code. The first thing I ran into is that I can't create a control array as easily as in Visual Basic. The default naming of the controls doesn't give me such options, whatever I tried. As I need to get data from the cells the whole thing would look like.
CEdit *pEdit1 = reinterpret_cast(this->GetDlgItem(IDC_EDIT1));
CEdit *pEdit2 = reinterpret_cast(this->GetDlgItem(IDC_EDIT2));
...
pEdit1->SetWindowText(_T(""));
pEdit2->SetWindowText(_T(""));
...
That's what happens when put the event handler for my Clear button. (Haven't started with the Solve one yet) So what I run into is that I have to write 81*2=162(!) lines of code just for this little event! So I want to make a loop for that, but the problem is that I can't make an array of pointers, because the object the pointers point to is not an array. And I couldn't find the declaration of the CEdit class, as it is probably a default one and it's hiding somewhere I can't reach. I'm now trying to create a new array of the CEdit class, so that I can put them all in an array and maybe even use the same one pointer for each of them. The problem is I can't display my new class array objects on the form, I can't put them on the control panel and just "draw", because they are not default. So it's kind of complicated. I'll do some more research on that.
At least I got how the whole windowsapp thing works.
Microsoft Visual C++
I just switched from Dev C++ to Microsoft Visual C++. This one is actually visual. So if you want to have more controls in front of your eyes, but not just in the code itself, you should use this one. It doesn't give as much freedom as Visual Basic, but at least I can see the forms and their controls. I also found out that for a beginner it's better to start with an MFC application: it writes the header and resource files automatically, so I don't have to write the codes I don't know yet. MFC is enough for the first applications, it helps to adjust.
Subscribe to:
Posts (Atom)