Re: MsgWaitForMultipleObjects

Tech-Archive recommends: Fix windows errors by optimizing your registry



William DePalo [MVP VC++] <willd.no.spam@xxxxxxxx> wrote in message
news:ukZcNgRsFHA.3504@xxxxxxxxxxxxxxxxxxxxxxx
> "nly" <nlyee2001@xxxxxxxxx> wrote in message
> news:egEcr$QsFHA.4044@xxxxxxxxxxxxxxxxxxxxxxx
> > In the sample usage of MsgWaitForMultipleObjects at:
> >
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
> > e/waiting_in_a_message_loop.asp
> >
> > what confusing is the part below:
> >
> > // Read all of the messages in this next loop,
> > // removing each message as we read it.
> > while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
> >
> >
> > // If it is a quit message, exit.
> > if (msg.message == WM_QUIT)
> > return 1;
> > // Otherwise, dispatch the message.
> > DispatchMessage(&msg);
> > } // End of PeekMessage while loop.
> >
> > // Wait for any message sent or posted to this queue
> > // or for one of the passed h.andles be set to signaled.
> > result = MsgWaitForMultipleObjects(cObjects, lphObjects,
> > FALSE, INFINITE, QS_ALLINPUT);
> >
> > PeekMessage() is peeking on ths same queue as
MsgWaitForMultipleObjects()
> > waits on, correct?
> >
> > MsgWaitForMultipleObjects() isn't waiting "...for any message sent or
> > posted
> > to this queue", correct?
> >
> > Thnaks in advance!
> >
> >
>
> For each iteration of the loop, first the message queue is checked. If
there
> are any messages in the queue they are removed.
>
> Once the queue is drained then the code waits on any of the objects
> specified in the call to MsgWaitForMultipleObjects() to be signaled OR the
> arrival of the next message, whichever happens first.
>
> Then the loop repeats until a WM_QUIT message is encountered.
>
> Regards,
> Will
>
>
Thanks! What if don't remove the messages in the queue? Does this mean that
MsgWaitForMultipleObjects() will never be signaled at all?

Why is it necessary that for MsgWaitForMultipleObjects() to be signaled, all
messages in the queue have to be removed?

Will the queued message(s) block MsgWaitForMultipleObjects() to be signaled?


.



Relevant Pages

  • Re: WaitForSingleObject freezes application
    ... Use MsgWaitForMultipleObjectsEx/MWMO_INPUTAVAILABLE get around that unread ... >>If you need wait on object in UI thread, MsgWaitForMultipleObjects can be ... Everytime you resume waiting, timeout is reset, so ... > function to check the queue. ...
    (microsoft.public.vc.mfc)
  • Re: MsgWaitForMultipleObjects
    ... > PeekMessage() is peeking on ths same queue as MsgWaitForMultipleObjects() ... Then the loop repeats until a WM_QUIT message is encountered. ...
    (microsoft.public.vc.language)
  • Re: MsgWaitForMultipleObjects
    ... > Does this mean that MsgWaitForMultipleObjects() will never be signaled at ... waiting on is signalled or when there is a message in the queue. ... WAIT_OBJECT_0 + nCount where nCount is the number of handles. ... UI threads must pump messages in a timely way. ...
    (microsoft.public.vc.language)