Howdy,
> > // Start the message loop.
> >
> > while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
> > {
> > if (bRet == -1)
> > {
> > // handle the error and possibly exit
> > }
> > else
> > {
> > TranslateMessage(&msg);
> > DispatchMessage(&msg);
> > }
> > }
> >
> > Looking at that above, I would say that DispatchMessage is what causes the
> > message to be processed (see (a) above).
>
> Excellent- now we're getting somewhere! What does TranslateMessag() do?
> What do the other parameters go GetEvent() mean? Is it possible to specify
> a timeout there?
TranslateMessage() is just something you need to do. But if you really want to
know: "The TranslateMessage function translates virtual-key messages
into character messages. The character messages are posted to
the calling thread's message queue, to be read the next time the
thread calls the GetMessage or PeekMessage function." (Platform SDK docs)
Other parameters to GetMessage():
BOOL GetMessage(
LPMSG lpMsg, // message information (a)
HWND hWnd, // handle to window (b)
UINT wMsgFilterMin, // first message (c)
UINT wMsgFilterMax // last message (d)
);
(a) Pointer to a MSG structure that receives message information from the
thread's message queue. This allows us to access WPARAM and LPARAM (the data)
right here. Makes me wonder why we'd need a callback function at all since we'd
be able to process all messages in this loop in the server. I'll check if we need
one when I get home later.
(b) Handle to window whose messages to retrieve. If NULL, then retrieves messages
for any window that belongs to the current thread.
(c) and (d) are used for filtering messages that have an integer value within a
certain range and are not useful to us.
There is no way you can specify a timeout using one these calls. It'd be a case
of endlessly looping PeekMessage() and then retrieving the message (by using
GetMessage()) and processing it. And perhaps sleeping every so often if this
takes up a lot of CPU time.
Cheers,
Alex.