I am trying to make sense of 'The Message Loop'. This is how it looks:
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
So far I am clear(at least I hope so) with the concept.When the user interacts with windows application using keyboard and mouse,those events are converted to appropriate messages by the respective device drivers and posted to system message queue.
The OS removes messages from the queue one by one and examines each of them to send them to respective application's thread's queue that is responsible for having created the destination window.
Now in my application
MSG msg;
GetMessage(&msg, NULL, 0, 0);
removes the message from thread specific message queue and fills the MSG structure.
But TranslateMessage
is said to translate the virtual keystrokes to characters and post them back to the caller thread's message queue.
DispatchMessage
directs the OS to call the Windows Procedure of appropriate target window.
Two doubts:
1)What is the exact functionality of TranslateMessage;is it just to translate virtual keystrokes to character messages(I assume virtual keystrokes to be keystrokes other than alphabets and numbers),if character message is posted back to queue,isn't the loop broken?
2)What about the mouse events?are they directly dispatched?