Game Development Reference
In-Depth Information
retrieves a message from the message queue and fills in the members
of our MSG structure. If GetMessage returns true, then two more
functions get called: TranslateMessage and DispatchMessage .
TranslateMessage has Windows perform some keyboard transla-
tions, specifically virtual key messages to character messages.
DispatchMessage finally dispatches the message to the appropriate
window procedure.
The Window Procedure
We mentioned previously that the window procedure is where we write
the code we want to execute in response to a message that our window
receives. In Hello World, we name the window procedure WndProc .It
is prototyped as:
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
This function returns an integer of type LRESULT (which is a long )
identifying the success or failure of the function. The CALLBACK identi-
fier specifies that the function is a callback function, which means that
Windows will be calling this function externally. As you can see from
the Hello World source code, we never explicitly call the window proce-
dure ourselves—Windows calls it for us when the window needs to
process a message.
The window procedure has four parameters in its signature:
hwnd —Identifies the window the message is for
uMsg —A predefined value that identifies the particular message.
For example, a quit message is defined as WM_QUIT . The prefix
WM stands for “Window Message.” There are over a hundred pre-
defined window messages. See the MSDN library for details.
wParam —Extra information about the message, which is depend-
ent upon the specific message
lParam —Extra information about the message, which is depend-
ent upon the specific message
Our window procedure handles three messages: the WM_LBUTTON-
DOWN , WM_KEYDOWN , and WM_DESTROY messages. A WM_LBUTTON-
DOWN message is sent when the user clicks the left mouse button on
the window's client area. A WM_KEYDOWN message is sent when a key
is pressed. A WM_DESTROY message is sent when the window is being
Search WWH ::




Custom Search