Skip to main content
GameDev.net gamedev.net
🔒 Locked

Forcing a Quit Message

Started by STRATERCAS Oct 4, 2005 at 11:20 PM 4 replies 700+ views
Original Post
STRATERCAS
STRATERCAS
Language C++ Platform Win32, DirectX9c SDK I have an Error box function that I have created to replace my calls to MessageBox() to use __TIMESTAMP__, __LINE__ etc. I also have a PostQuitMessage(0); Call under certain conditions. However, the PostQuitMessage only appears to register when my program loses focus (alt+tab, minimize etc). If it hasn't lost focus it goes on a wild tangent until it does lose focus. My assumption is it's not giving enough time from the message to register. I've tried Sleep();. This call is in the render loop, in this loop it's supposed to check for an invalid RECT let the user know and Quit. Then what I described happens. Just curious as to a way to accomplish this. I have look around but every tutorial on Quitting is the standard case WM_DESTROY: PostQuitMessage(0); return 0; WinProc code.
Daaark
Daaark
Are you trapping WM_QUIT and not responding to it? You don't need to give your program 'time to respond to the message'. The instructions it gets will be processed in the order they are received. Your message handler must be flaky. why don't you post your WndProc function?
NumberXaero
NumberXaero
I dont really understand the problem exactly under your setup, but have you tried
LRESULT SendMessage(HWND hWnd, INT Msg, WPARAM wParam, LPARAM lParam);
with WM_DESTROY? Id like to have some more info, to understand whats happening better.
STRATERCAS
STRATERCAS
The WinProc:

[source lang=c++]LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){	switch (msg)	{	case WM_DESTROY:		PostQuitMessage(0);		return 0;	}	return DefWindowProc(hWnd,msg,wParam,lParam);}



The game loop, where I am intentionaly feeding invalid data. In which the following block of code get's called.
[source lang=c++]void gameRun(HWND hWnd){	RECT src;	src.bottom = 512;	src.left	=0;	src.right	=600;	src.top		=0;	RECT dest;	dest.bottom = 2;	dest.left	=	0;	dest.right	=	2;	dest.top	=0;	for(int i = 0; i <200; i++)	{		test.Render(grassImage,src,dest);		dest.right += 4;		dest.bottom += 4;		dest.left  += 2;		dest.top  += 2;			}			test.Display();}

[source lang=c++]void F_DebugMessage(HWND hWnd, std::string timestamp, std::string file, std::string function, long line, std::string optionalMessage, bool QUIT) {////////////Bunch of string building code....	MessageBox(NULL, cErrorMessage, "ERROR", MB_OK|MB_ICONEXCLAMATION); 		if((bool)QUIT)	{                //I have tried PostMessage as well.                //I have tried PostQuitMessage as well.		SendMessage(hWnd, WM_DESTROY, NULL, NULL);	}}



I've ran this through the debugger and the PostQuitMessage in the WinProc does get called over and over and over ..... But, it doesn't happen until I minimize and such(I don't count the Task Manager :D). What boggles me is the WM_DESTORY does get reconized the PostQuitMessage get's called, but doesn't happen. It kind seems like it's trying to catch up or something but it just can't do it. After the messageBox that gets called get's clicked it just keeps doing the messageBox beep until you minimize(and/or etc). Then it finnaly quits.


I'm sorry what exactly do you mean by trapping it?
Daaark
Daaark
Try setting a gloabl variable, like bDone = true, and use that to break your main program loop maybe? I don't see where you call the message to send the quit message? Could be you are using a bad if statement or something that never gets called?

Trapping means.. you handle the message without calling the default message handler. Is that your whole WndProc?
STRATERCAS
STRATERCAS
Thanks a bunch I can't believe I forgot to try a global. I'm so used to trying to avoid them that I sometimes forget use them at all.

As for the Quit Message though, the QuitMessage was supposed to(at least in my mind) happen with PostQuitMessage(0); under the case WM_DESTROY in the WinProc. And I would send a WM_DESTROY message from my Debuging MessageBox function. This has worked up until I needed to send a Quit message in the middle of a loop. Thanks a million again.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.