Game Development Reference
In-Depth Information
destroyed. Our code is quite simple; when we receive a
WM_LBUTTON-
DOWN
message, we display a message box that prints out “Hello,
World”:
case WM_LBUTTONDOWN:
::MessageBox(0, "Hello, World", "Hello", MB_OK);
return 0;
When our window gets a
WM_KEYDOWN
message, we test what key was
pressed. The
wParam
passed into the window procedure specifies the
virtual key code
of the specific key that was pressed. Think of virtual
key codes as an identifier for a particular key. The Windows header files
have a list of virtual key code constants that we can use to then test for
a particular key (for example, to test if the Escape key was pressed, we
use the virtual key code constant
VK_ESCAPE
).
Note:
Remember, the
wParam
and
lParam
parameters are used to
specify extra information about a particular message. For the
WM_KEY-
DOWN
message, the
wParam
specifies the
virtual key code
of the specific
key that was pressed. The MSDN library will specify the information
that the
wParam
and
lParam
parameters carry for each Windows
message.
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
::DestroyWindow(MainWindowHandle);
return 0;
When our window gets destroyed, we post a quit message (which ter-
minates the message loop).
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
At the end of our window procedure, we call the
DefWindowProc
function. This function is a default window procedure. In our Hello
World application, we only handle three messages; we use the default
behavior specified in
DefWindowProc
for all the other messages that
we receive but don't necessarily need to handle ourselves. For exam-
ple, Hello World can be minimized, maximized, resized, and closed.
This functionality is provided to us through the default window proce-
dure, as we do not handle the window messages to perform this
functionality. Note that
DefWindowProc
is a Win32 API function.
Team-Fly
®
Search WWH ::
Custom Search