Freiza Grandmaster Cheater
Reputation: 22
Joined: 28 Jun 2010 Posts: 662
|
Posted: Thu Feb 23, 2012 1:46 am Post subject: Win32 Tutorial Part 2b- Creating Window |
|
|
Step 2)-->
Register our defintion to operating system.
it is easy, just pass our definition to RegisterClass function
if not successful it will return NULL and our program will terminate.
| Code: | if(!RegisterClass(&wc))
{
MessageBox(NULL,L"Cannot register window",L"Title Bar",MB_OK);
return 0;
} |
Step 3) -->
Now , time have to come to actually create a window. We create our window by calling CreateWindow function. CreateWindow takes following parameter:
1) name of the class that we just REGISTERED to operating system. Here it is myClassname
2) Title message of the window. Here it is "My Title Window"
3) Sets Style of the window. We have used two constants.
a)WS_OVERLAPPEDWINDOW --> It means that our window will have border, a title bar, minimize button, maximize button, sysmenu etc.
b)WS_VISIBLE --> It means that our window will be visible by default.
4) Left positon of the window. Here we have set it to 100 pixels from the left of DESKTOP.
5) Top POSITION of the window. Here we have set it to 100 pixels from the top of the Desktop.
6 and 7) width and height of the window.
8.) Represents the parent of the window. Since this is an Top level window it have no parent. Hence it is set to NULL.
9) Is a HANDLE to Menu. Since we have not discussed about menu yet. So will will set this parameter to NULL.
10) Operating system maintains a table of created window. THIS parameter gives info to operating system that which program has created this window.
11) We'll discuss this parameter later. Till then set it to NULL.
| Code: | | HWND hwnd = CreateWindow(CLASS_NAME,L"My Title Window",WS_OVERLAPPEDWINDOW|WS_VISIBLE,100,100,500,500,NULL,NULL,hInstance,NULL); |
Here we are checking that if our window is created successfully or not. If not then we exit. If successful hwnd will contain handle to our newly created window.
| Code: | if (hwnd == NULL)
{
MessageBox(NULL,L"CreateWindow Failed",L"Create Window problem",0);
return 0;
} |
Btw, handle is nothing more than a unique number which is maintained by the operating system to distinguish different objects. There are many types of handles. For ex:- program instance handle (HINSTANCE),
Window handle (HWND) etc.
important typedef:
typedef void *LPVOID;
typedef void *PVOID;
typedef PVOID HANDLE;
typedef HANDLE HINSTANCE;
typedef HANDLE HWND;
|
|