Game Development Reference
In-Depth Information
If we made it this far in
InitWindowsApp
, then the initialization is
complete; we return true to indicate everything went successfully.
The Message Loop
Having successfully completed initialization, we can begin the heart of
the program, the message loop. In Hello World, we have wrapped the
message loop in a function called
Run
.
int Run()
{
MSG msg;
::ZeroMemory(&msg, sizeof(MSG));
while(::GetMessage(&msg, 0, 0, 0) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return msg.wParam;
}
The first thing done in
Run
is an instantiation of a variable called
msg
of
type
MSG
, which is the message structure that represents a Windows
message. Its definition is as follows:
typedef struct tagMSG {
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
hwnd
—Identifies the window the message is for
message
—A predefined constant value identifying the message
(e.g.,
WM_QUIT
)
wParam
—Extra information about the message. This is dependent
upon the specific message.
lParam
—Extra information about the message. This is dependent
upon the specific message.
time
—The time the message was posted
pt
—The (x, y) coordinates of the mouse cursor in screen coordi-
nates when the message was posted
Next we enter the message loop.
GetMessage
will always return true
unless a
WM_QUIT
message is posted; therefore, the loop continues
until a
WM_QUIT
message is received. The
GetMessage
function
Search WWH ::
Custom Search