Article View: comp.windows.ms.programmer
Article #1407Re: PeekMessage() question.
From: Mark Epperson
Date: Fri, 22 Feb 1991 03:20
Date: Fri, 22 Feb 1991 03:20
58 lines
2753 bytes
2753 bytes
In article <149000004@eriador> mguyott@eriador.prime.com writes:
>
>I would like to use PeekMessage() in a yield loop so that other applications
>will be able to run while my application is doing some serious number
>crunching. However, I have one concern and that has to do with the
>WM_QUIT message. Will PeekMessage() remove a WM_QUIT message from the
>windows message queue? If it does can I requeue the message? Perhaps
>via PostMessage()? Thanks in advance for any help. Marc
>----
>Two of the worst things we teach our children are that a knowledge of science
>is nice but not necessary, and a knowledge of sex is necessary but not nice.
>
>Marc Guyott Constellation Software, Inc. (508) 620-2800
> Framingham, Mass. 01701 USA Ext. 3135
>mguyott@primerd.prime.com ...!{uunet, decwrl}!primerd.prime.com!mguyott
Here is a tried and true way to make sure that you yield properly:
-------- C U T H E R E ------------------------------------------
/*
This is based on information which is not generally
available. Neither PeekMessage() nor Yield() will yield
if there is a message in the applications queue. So...
GetInputState() (which is 3X faster than PeekMessage()) is
used to see if there are any mouse, keyboard or, timer input
records which will result in message being put into your queue. If
this is false the Yield() will probably work and is thus called,
otherwise PeekMessage() is called with the NO_YIELD flag to get
the next message without yielding excessively and that message
is then dispatched. After all messages have been removed then Yield()
is called.
GetInputState() will fail if the input focus changes so...we enter
the PeekMessage() loop every 16th time to handle this eventuality.
NOTE:
This routine will allow your program to have multiple threads
so make sure the approiate controls are disabled or your WinProcs
take this into consideration.
*/
void AplYield()
{
static int delay = 0;
MSG msg;
LPMSG lpMsg;
if (!(delay++ & 0xf) || GetInputState())
{
lpMsg = &msg;
while (PeekMessage(lpMsg, NULL, 0, 0, PM_REMOVE|PM_NO_YIELD))
{
TranslateMessage(lpMsg);
DispatchMessage(lpMsg);
}
}
Yield();
}
Technical Details
Message-ID:
<11440@adobe.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!adobe!eppersonReferences:
<149000004@eriador>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!adobe!epperson From: epperson@adobe.COM (Mark Epperson) Newsgroups: comp.windows.ms.programmer Subject: Re: PeekMessage() question. Message-ID: <11440@adobe.UUCP> Date: 22 Feb 91 03:20:08 GMT References: <149000004@eriador> Reply-To: epperson@adobe.UUCP (Mark Epperson) Organization: Adobe Systems Incorporated, Mountain View Lines: 58