Advertisement

PeekMessage() doesnt properly close window

Started by August 06, 2000 11:46 PM
3 comments, last by outRider 24 years, 4 months ago
I read somewhere that GetMessage() waits for a message before returning anything and so I changed my loop from: while(GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } to this, so that the app wouldn't be hung up waiting for a message: while(!quit) { if (PeekMessage(&Msg,NULL,0,0,PM_REMOVE)) { GetMessage(&Msg, NULL, 0, 0); TranslateMessage(&Msg); DispatchMessage(&Msg); } } The problem is that with the second version closing the window doesn't end the app, it destroys the window so that it's not visible anymore, but if I ctrl+alt+del I still see it open and have to manually close it. Doing it like I did the first time completely closes the window, so I know that my WndProc is doing its job, but theres some problem with me using PeekMessage(). ------------ - outRider - Edited by - outRider on 8/6/00 11:53:20 PM
try it this way

    for(;<img src="wink.gif" width=15 height=15 align=middle>		{		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))		{			if(msg.message==WM_QUIT) break;			TranslateMessage(&msg);			DispatchMessage(&msg);		}                Prog_Loop();          }    


you dont need to call GetMessage



+---------------------------------------------
Help me program my 3d game
I just got a new copy of Lear C++ in 21 days!
+---------------------------------------------

Edited by - terminate on August 7, 2000 1:24:01 AM
Those who dance are considered insane by those who cannot hear the music.
Advertisement
quote: Original post by outRider

to this, so that the app wouldn''t be hung up waiting for a message:


while(!quit)
{
if (PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
{
GetMessage(&Msg, NULL, 0, 0);
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}



You are using the PM_REMOVE flag with PeekMessage. This flag removes a waiting message from the queue. Then you do a GetMessage. This retrieves the next message. So you are losing a message in there. That is why the window wasn''t closed. It never got the message.

Drop the GetMessage from that loop.
Steve 'Sly' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers
Try this - it works fine

while (1){	if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))	{		if (GetMessage (&msg, NULL, 0, 0))		{			TranslateMessage (&msg);			DispatchMessage (&msg);		}		else		{			return msg.wParam;		}	}	else	{                // Your program stuff        }}    


- - - - - - - - - - - - - -
Andreas Mähler
Wolf359 Interactive
Thanks, it works fine now.

------------
- outRider -

This topic is closed to new replies.

Advertisement