Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!njin!uupsi!cci632!srw From: srw@cci632.cci.com (Steve Windsor) Newsgroups: comp.windows.ms.programmer Subject: PeekMessage() Control Loop Keywords: PeekMessage Message-ID: <1991May17.185648.20396@cci632.cci.com> Date: 17 May 91 18:56:48 GMT Reply-To: srw@op632.UUCP (Steve Windsor) Organization: CCI, Communications Systems Division, Rochester, NY Lines: 39 Ok all, here is the program segment that Paul Yao gave us in the Windows Applications Programming (Windows AP) Class. To break up long processing chunks, use PeekMessage(), which was originally implemented for the Windows spooler. This segment is intended to replace the GetMessage()...DispatchMessage() code segment in your main message loop: While ( TRUE ) { if ( ( PeekMessage( ,,,, PM_REMOVE ) ) /* Non zero indicates message */ { if ( msg.message == WM_QUIT ) break; TranslateMessage(); DispatchMessage(); } else /* zero, no message waiting */ { // do other work, another process, etc... // PeekMessage() implicitly tells Windows not to idle us if // there are no messages waiting, so it allows // us to do context switching. // An example is in the SDK sample code under // \WINDEV\EXAMPLES\TTY\TTY.C. } } /* end while */ Note I have not checked out the sample program, nor have i tried this segment of code, but it looks ok to me. If someone tries it, let me know. The PM_REMOVE switch in PeekMessage() removes the message from the queue AFTER processing by PeekMessage(). This will either help, or create more confusion. stephen windsor srw@op632.cci.com if PeekMessage( lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, wRemoveMsg )