Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

xDS4Lx

PeekMessage

This topic is 5891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, First I know how to use Win32 but ive never done a message loop using PeekMessage. I just started learning some GL and just changed my message loop to use peek message now instead it looks like this:
    
BOOL bRet = FALSE;
while(!bRet)
{	::PeekMessage(&msg, hWnd, NULL, NULL, PM_REMOVE);
	if(msg.message == WM_QUIT)
	{	bRet = TRUE;			
	}
	else
	{	glWin.Render();
		TranslateMessage(&msg);
		DispatchMessage(&msg);		
	}
}
    
The problem is that when I exit the program the applications process is still active. This happens no matter what I have tried, I know that with GetMessage this happens if you use a HWND for the window handle instead of null, so I tried that and the problem still ocurs. If needed I can post more code. Thanx in advance [edited by - xds4lx on August 26, 2002 10:29:24 PM]

Share this post


Link to post
Share on other sites
Advertisement
Actually I just found out what the problem was. It occured if i trped the WM_DESTROY message. So I just changed my WM_CLOSE handler to this:

  
case WM_CLOSE:
{ if(MessageBox(NULL,"Sure you want to exit?","Close?",MB_YESNO) == IDYES)
{ PostQuitMessage(0);
}
return(0);
}

From:

  
case WM_CLOSE:
{ if(::MessageBox(NULL,"Sure you want to Quit?","Close?", MB_YESNO) == IDYES)
{ ::DestroyWindow(hWnd);
}
return(0);

}
case WM_DESTROY:
{ PostQuitMessage(0);
return(0);
}

Share this post


Link to post
Share on other sites
Im just wondering if anyone knows why the origional way I was handling shut down didnt work? It works for all other windows applications ive done (non 3D related)

Share this post


Link to post
Share on other sites
WM_CLOSE default action is to call DestroyWindow(), and WM_DESTROY is sent when window is being destroyed.

"The PostQuitMessage function indicates to Windows that a thread has made a request to terminate (quit). It is typically used in response to a WM_DESTROY message." - MSDN

I guess is your OpenGL thingie (your glWin?) that gives you this problem.

Share this post


Link to post
Share on other sites
You answered the wrong question there man. I want to know why the propper code fails (calling DestroyWindow from a WM_CLOSE message and PostQuitMessage from a WM_DESTROY message) and calling PostQuitMessage works when calling it from the WM_CLOSE.

EDIT: I can post all the code if that would help.

[edited by - xds4lx on August 28, 2002 11:30:58 PM]

Share this post


Link to post
Share on other sites
I was also quite surprise that your orginal code didn''t work. I followed MSDN ways and so far no problem, even with Directxxxxxx (oh ok, no yet try OpenGL).
That''s why I suspect something is wrong... in other places.

Share this post


Link to post
Share on other sites
Theres is nothing wrong anywhere else in the program. Ive been doing Win32 for a few years, but this is my first dive into the world of 3D graphics. Everything was fine untill I had changed the message loop from using GetMessage to PeekMessage. I know everything is fine with the Win32 wrapper because it is one that I have used in lots of other Win32 applications. Could it possibly be the window styles used? Maybe I should use WM_PARENTNOTIFY?

Share this post


Link to post
Share on other sites
Actually, unless you didn't post all your code, there is something wrong. Here we go:
What most Win32 programs should do is what xDS4Lx had originally: on WM_CLOSE, do any processing for saving and such, then call DestroyWindow(). When DestroyWindow() is called, the window is destroyed, then a WM_DESTROY message is sent to the WindowProc for the window that was destroyed (or maybe the message is sent first; I'm not completely certain). When WM_DESTROY is received, then any last-minute processing such as freeing variables can be done, and lastly PostQuitMessage(0) should be called. The PeekMessage() loop, upon detecting that message (the Quit message), exits -- and then what? The program will continue to run until the main function, inside which the PeekMessage() loop resides, returns a value (usually msg.wParam, which is 0 if there were no errors). So, unless you already have this, put a line in your program at the end of your WinMain() function saying:
return msg.wParam;
and go back to the original WindowProc layout.


Twilight Dragon
Win32 API Programmer
www.freewebz.com/j-world

[edited by - TDragon on August 29, 2002 4:41:54 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!