Article View: comp.windows.ms.programmer
Article #2703Re: What does Yield do?
From: John Ciccarelli
Date: Thu, 16 May 1991 19:54
Date: Thu, 16 May 1991 19:54
36 lines
2218 bytes
2218 bytes
In article <1991May16.121553.3876@maytag.waterloo.edu> dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
> I'm porting a DOS program to Windows [which] has some long loops where it
> occasionally writes to one window... so everything else comes to a
> halt.... I'm trying to civilize it by putting occasional calls to Yield...
Don't use Yield. The docs say Yield isn't for windowed apps.
Use PeekMessage instead. The basic idea is:
while ( something that takes a long time ) {
<one iteration of stuff that takes a long time>
MyYield();
} /* end while */
/* "Yield to other apps" function */
void MyYield() {
while ( PeekMessage( lpMsg, hWndApp, 0, 0, PM_NOREMOVE ) ) {
ProcessMessage( lpMsg ); /* Get/Translate/Dispatch logic of WinMain */
} /* end while */
} /* end function */
Your ProcessMessage function should contain the Get/Translate/Dispatch
body of your WinMain message loop. WinMain's message loop and MyYield's
while loop both call it, guaranteeing that messages always get processed
the same way.
Since the GetMessage contained in ProcessMessage will remove the message,
PeekMessage is called with PM_NOREMOVE. Even if there are no messages
in the queue, PeekMessage will allow other apps to run, which is what
you want. The interface to ProcessMessage must handle the WM_QUIT
properly, of course.
/John
--
John Ciccarelli (jciccare@adobe.com, {sun|decwrl}!adobe!jciccare, 415-962-6677)
Adobe Systems, 1585 Charleston Road, Mountain View, California USA 94039-7900
Technical Details
Message-ID:
<15315@adobe.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!widener!ukma!rex!spool.mu.edu!mips!swrinde!elroy.jpl.nasa.gov!decwrl!adobe!jciccareReferences:
<1991May16.121553.3876@maytag.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!unix.cis.pitt.edu!dsinc!widener!ukma!rex!spool.mu.edu!mips!swrinde!elroy.jpl.nasa.gov!decwrl!adobe!jciccare From: jciccare@adobe.COM (John Ciccarelli) Newsgroups: comp.windows.ms.programmer Subject: Re: What does Yield do? Summary: Use PeekMessage instead Keywords: PeekMessage Yield GetMessage Message-ID: <15315@adobe.UUCP> Date: 16 May 91 19:54:52 GMT References: <1991May16.121553.3876@maytag.waterloo.edu> Reply-To: jciccare@adobe.com (John Ciccarelli) Followup-To: comp.windows.ms.programmer Organization: Adobe Systems, Mountain View, CA Lines: 36