[comp.windows.ms] Yielding control

sshirk@emdeng.Dayton.NCR.COM (Stephanie.Shirk) (03/21/90)

Has anyone tried forcing an application to yield control to others?  You're
supposed to be able to do this by calling PeekMessage or GetMessage (even
outside your message loop).  I'm not having much luck!  I'm also trying to
do this from a DLL, which means I don't have access to the handle of the 
window of the application currently in the DLL (although there probably is
some way to get that, too).  Some of the things I've tried include:

  -- Yield(), which is actually defined to be used only by Windows 
  applications that don't use windows (thanks a lot!).  It didn't do
  anything.

  -- PeekMessage() without removing a message, which didn't do anything.

  -- Calling PostAppMessage() with a WM_USER message (this function lets you
  use the task handle instead of requiring the window handle).  Then calling
  PeekMessage() with a -1 handle (as defined).  PeekMessage returned 0 (no
  message found) and did not yield control.

  -- Calling PostAppMessage as above and then calling GetMessage with a NULL
  handle.  It returned nonzero but did not yield control.  (I didn't check 
  yet to see if anything showed up in my message structure.)  The SDK doc
  didn't say anything about using a -1 handle like it did for PeekMessage. 

I also tried PeekMessage with a NULL window handle and removing any message.
This sort of worked at first (I managed to click on another window but that
was about it).  Of course that probably isn't a good way to do it anyway.

Thanks for any ideas you have!

Stephanie Shirk  --  NCR E&M-Dayton
email:  sshirk@emdeng.Dayton.NCR.COM

-- 
Stephanie Shirk -- NCR E&M Dayton
e-mail:  sshirk@emdeng.Dayton.NCR.COM 

rommel@lan.informatik.tu-muenchen.dbp.de (Kai-Uwe Rommel) (03/22/90)

In article <291@emdeng.Dayton.NCR.COM> sshirk@emdeng.UUCP (Stephanie.Shirk) writes:
>
>Has anyone tried forcing an application to yield control to others?  You're
>supposed to be able to do this by calling PeekMessage or GetMessage (even
>outside your message loop).  I'm not having much luck!  I'm also trying to
...
>Stephanie Shirk  --  NCR E&M-Dayton
>email:  sshirk@emdeng.Dayton.NCR.COM


You have to call TranslateMessage() and DispatchMessage() too after
calling PeekMessage() if you get a nonzero result from PeekMessage().
Use PM_REMOVE mode on PeekMessage(). I am using this sequence
successfully.

if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
{
  TranslateMessage(&msg);
  DispatchMessage(&msg);
}

If you have enough time , you can replace the if by a while. Add
TranslateAccelerator() as needed like in the main message loop.

Kai Uwe Rommel
Munich
rommel@lan.informatik.tu-muenchen.dbp.de