Pressing F10 pause main loop?

Started by
14 comments, last by Cocalola 10 years, 10 months ago

Hi

I have compiled a Win32 with a DX9 demo using C++ in VS2010. My application runs fine, but if I press F10 the main loop pauses, the same way it pauses when I drag the window around.

If I press F10 in other window like calculator the file menu appears, but not in my application. How can I disable this feature?

Advertisement

Its going to deal with your message pump, you need to do a message peek instead of waiting for a message, any chance you could post your current windows message pump?

edit here is a decent message pump:


   for(;;)    
    {
        //look for a message
        while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
        {
            //check that we arent quitting
            if(msg.message==WM_QUIT) break;
            //translate message
            TranslateMessage(&msg);
            //dispatch message
            DispatchMessage(&msg);
            
        }
        Program_Running();  //This is where you want to do all of your applications logic.
        
    }

Does the same thing happen when you press Alt?

I mention this because most likely what's happening is that F10 is trying to trigger the menubar (or the window's menu if there's nothing else). This is the default behavior. You probably want to override the keyboard events to prevent that from happening.

Also shouldn't that if be a while? You'll want to process all pending events before continuing. This may also have something to do with the issue. Try changing that first.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

That was my reply, yes it should be while!

Also a quick warning before I forget, you shouldn't just handle WM_KEYDOWN and WM_KEYUP, but also WM_SYSKEYDOWN and WM_SYSKEYUP (you can treat those latter two the same way as the former two, really). The main difference is that the latter trigger when you press F10 or Alt with another key (i.e. the shortcuts that would trigger the menubar). Make sure you're handling all four events, not just the first two.

EDIT: also that's what I get for not paying attention, thought the two posts were from the same user =P (which happens quite often too...)

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

I found some code that disables the F10 menu thingy by not dispatching it but rather return 0;


switch(message)
	{
	case WM_SYSCOMMAND:
        {
            switch (wParam)
            {    
                // Disables System Menu (F10 Key)       
                case SC_KEYMENU:
                {
                    return 0;
                }//SC_KEYMENU
                break;
                default:
                {
                    return DefWindowProc(hWnd, message, wParam, lParam);

                }//default

            }//switch
            
        }//WM_SYSCOMMAND

	case WM_DESTROY:
		PostQuitMessage(0);
		break;

It fixes the issue.

However, if I press F1 - F12, how are those posted to my window? I though they were WM_CHARs but they are not...

I don't know if it is safe not to not return DefWindowProc(hWnd, message, wParam, lParam);

because if I spam F10 for about 10 seconds and exit I get this error:

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Runtime Error!
Program: C:\Users\Admin\...
R6016
- not enough space for thread data
---------------------------
OK
---------------------------

Dude... your message loop is all wrong... you shouldn't have 2 loops and it need an if/else condition, not only an if.

Forget the syskey msg...

That's how it should be done.


//-----------------------------------------------------------------------------
// The game loop...
//-----------------------------------------------------------------------------
void CVortez3DEngine::GameLoop()
{
	MSG msg;
	bool done = false;

	// Empty the nessages queue if this isn't the first loop
	static bool IsFirstLoop = true;
	if(!IsFirstLoop)
		while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE));

	// Application loop.
	while(!done){
		if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){
			
			// If a quit message is received then stop the loop
			if(msg.message == WM_QUIT)
				done = true;
			
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		} else {
			// Reset the polygon rendered counter
			NumPolygonsDrawed = 0;
			// Update the scene and render a frame
			UpdateScene(EngineTimer.Tick());
    		        RenderScene();
		}
	}

	// Tell the application that we've run the game loop before
	IsFirstLoop = false;
}

What I posted above is not my message loop, it is a part of my WinProc function.


// Process the Messages
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	WinInput *pInput = NULL;

	if(message == WM_NCCREATE)
	{
		pInput = reinterpret_cast<WinInput *>(((LPCREATESTRUCT)lParam)->lpCreateParams);

		SetLastError(0);
		if(SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pInput)) == 0)
		{
			const DWORD ErrorCode(GetLastError());
			if(ErrorCode != 0)
			{
				return FALSE;
			}
		}

	}
	else
	{
		pInput = reinterpret_cast<WinInput *>(GetWindowLong(hWnd, GWL_USERDATA));
	}

	switch(message)
	{
	case WM_SYSCOMMAND:
            switch (wParam)
            {    
                // Disables System Menu (F10 Key)       
                case SC_KEYMENU:
                    return 0;
					break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
					break;
            }
			break;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_CHAR:
		pInput->PushInputChar(wParam);
		break;
	case WM_MOUSEMOVE:
		break;
	case WM_LBUTTONDOWN:
		break;
	case WM_LBUTTONUP:
		break;
	}

	return DefWindowProc(hWnd, message, wParam, lParam);
}

This is my message loop


while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		if(msg.message == WM_QUIT)
			return FALSE;

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

which is called once a frame.

Ok, after testing F10 with my code, it show the same symptome as you said, the game freeze. Im pretty sure this can be solve in the message loop however.

Gonna do some more tests.

Edit: i was talking to Yewbie:

Its going to deal with your message pump, you need to do a message peek instead of waiting for a message, any chance you could post your current windows message pump?

edit here is a decent message pump:

for(;;)
{
//look for a message
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//check that we arent quitting
if(msg.message==WM_QUIT) break;
//translate message
TranslateMessage(&msg);
//dispatch message
DispatchMessage(&msg);

}
Program_Running(); //This is where you want to do all of your applications logic.

}

How does the for loop ever stop with this code???

This topic is closed to new replies.

Advertisement