Windows GUI tend to follow a common trend:
Step:
1. Register a Window Class;
2. Create a (main) window of that class.
3. Enter the message loop.
You also provide a window procedure to handle message for the window you created.
The message loop generally looks like something like this:
1 2 3 4 5 6 7 8
|
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
|
This message loop gets messages from your window queue.
Now this look like all windows messages for your window will go through this queue - but that is not true.
Most messages that windows generate for your application are sent
directly to your Window Procedure.
Some message types that go through the queue and therefore are picked up and despatched by this loop are:
WM_PAINT
keyboard related messages.
mouse related messages
Now keyboard related messages arrive in the queue as Virtual key codes - the prupose of the
TranslateMessage() function is to translate keyboard messages into WM_CHAR messages.
The
DespatchMessage() function sends the message off to the window procedure.