Game Development Reference
In-Depth Information
for an application. The application constantly checks the message
queue for messages in a message loop , and when it receives one it dis-
patches it to the window procedure of the particular window that the
message is for. (Remember that an application can contain several win-
dows within it.) The window procedure is a special function that is
associated with each window of the application. (Every window has a
window procedure, but several windows can share the same window
procedure. Therefore, we don't necessarily have to write a window pro-
cedure for each window.) The window procedure is a function we
implement that handles specific messages. For instance, we may want
to destroy a window when the Escape key is pressed. In our window
procedure we would write:
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
::DestroyWindow(MainWindowHandle);
return 0;
The messages that a window doesn't handle are usually forwarded to a
default window procedure, which then handles the message.
To summarize, the user or an application does something to gener-
ate an event. The OS finds the application that the event was targeted
toward, and it sends that application a message in response. The mes-
sage is then added to the application's message queue. The application
is constantly checking its message queue for messages. When it
receives a message, the application dispatches it to the window proce-
dure associated with the window for which the message is targeted.
Finally, the window procedure executes instructions in response to the
message.
Figure 1 summarizes the event-driven programming model.
Search WWH ::




Custom Search