Game Development Reference
In-Depth Information
If WinMain succeeds, it should return the wParam member of the
WM_QUIT message. If the function exits without entering the message
loop, it should return 0. The WINAPI identifier is defined as:
#define WINAPI __stdcall
This specifies the calling convention of the function, which means how
the function arguments get placed on the stack.
Note: In the signature of WinMain in the Hello World sample, we
use the type PSTR as the third argument instead of LPSTR . This is
because with 32-bit Windows there are no longer “long pointers.”
PSTR is simply a char pointer (e.g., char* ).
WNDCLASS and Registration
Inside WinMain , we call the function InitWindowsApp . As you can
guess, this function does all the initialization of our program. Let's jump
into this function and examine it. InitWindowsApp returns either
true or false—true if the initialization was a success, false if something
went wrong. In the WinMain definition, we pass a copy of our applica-
tion instance to InitWindowsApp as well as the show command
variable. Both are obtained from the WinMain parameter list.
if(!InitWindowsApp(hInstance, nShowCmd))
The first task at hand in initialization of a window is to describe our
window and register it with Windows. We describe our window with
the WNDCLASS data structure. Its definition:
typedef struct _WNDCLASS {
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
} WNDCLASS;
style —Specifies the class style. In our example, we use
CS_HREDRAW combined with CS_VREDRAW . These two bit flags
indicate that the window is to be repainted when either the hori-
zontal or vertical window size is changed. For the complete list of
the various styles with description, see the MSDN library.
wc.style = CS_HREDRAW | CS_VREDRAW;
Search WWH ::




Custom Search