Jump to content

  • Log In with Google      Sign In   
  • Create Account


Pressing F10 pause main loop?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 Tispe   Members   -  Reputation: 879

Like
-1Likes
Like

Posted 13 June 2013 - 02:08 PM

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?



Sponsor:

#2 yewbie   GDNet+   -  Reputation: 665

Like
-1Likes
Like

Posted 13 June 2013 - 02:26 PM

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.
        
    }

Edited by yewbie, 13 June 2013 - 02:46 PM.


#3 Sik_the_hedgehog   Crossbones+   -  Reputation: 1411

Like
1Likes
Like

Posted 13 June 2013 - 02:44 PM

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.

#4 yewbie   GDNet+   -  Reputation: 665

Like
-1Likes
Like

Posted 13 June 2013 - 02:45 PM

That was my reply, yes it should be while!



#5 Sik_the_hedgehog   Crossbones+   -  Reputation: 1411

Like
0Likes
Like

Posted 13 June 2013 - 02:57 PM

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...)


Edited by Sik_the_hedgehog, 13 June 2013 - 02:59 PM.

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.

#6 Tispe   Members   -  Reputation: 879

Like
1Likes
Like

Posted 13 June 2013 - 03:03 PM

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...



#7 Tispe   Members   -  Reputation: 879

Like
0Likes
Like

Posted 13 June 2013 - 03:15 PM

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   
---------------------------

Edited by Tispe, 13 June 2013 - 03:15 PM.


#8 Vortez   Crossbones+   -  Reputation: 2215

Like
-2Likes
Like

Posted 13 June 2013 - 05:54 PM

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;
}


Edited by Vortez, 13 June 2013 - 06:24 PM.

My 3D Engine.

#9 Tispe   Members   -  Reputation: 879

Like
0Likes
Like

Posted 13 June 2013 - 06:05 PM

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.



#10 Vortez   Crossbones+   -  Reputation: 2215

Like
0Likes
Like

Posted 13 June 2013 - 06:07 PM

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???


Edited by Vortez, 13 June 2013 - 06:23 PM.

My 3D Engine.

#11 Vortez   Crossbones+   -  Reputation: 2215

Like
-1Likes
Like

Posted 13 June 2013 - 06:13 PM

Solved: Just add those 2 lines and it's gonna be fine.

 

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

        if(msg.message == WM_SYSKEYDOWN && msg.wParam == VK_F10)
                continue;


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

}


Edited by Vortez, 13 June 2013 - 06:27 PM.

My 3D Engine.

#12 Tispe   Members   -  Reputation: 879

Like
0Likes
Like

Posted 13 June 2013 - 06:46 PM

I find this fix very strange. There has to be a better way. Maybe some flags in dwStyle when calling CreateWindowEx(...), but now my minimize button is gone...

dwStyle = WS_OVERLAPPEDWINDOW&~WS_THICKFRAME&~WS_MAXIMIZEBOX&~WS_SYSMENU;

Edited by Tispe, 13 June 2013 - 06:50 PM.


#13 Vortez   Crossbones+   -  Reputation: 2215

Like
-1Likes
Like

Posted 13 June 2013 - 06:51 PM

Well, it just bypass the calls to dispatch and translate message so it's like the key was never pressed for the application (WndProc don't get called).

 

I admit it's a bit ugly but it could easily be fixed by adding the code in a simple function.

 

ex:

bool IsF10KeydownMsg(MSG msg)
{
    return (msg.message == WM_SYSKEYDOWN && msg.wParam == VK_F10);
}
 

Or whatever suit your need.

 

Maybe there is another way, but i don't know it. This work just fine imo.


Edited by Vortez, 13 June 2013 - 06:53 PM.

My 3D Engine.

#14 Sik_the_hedgehog   Crossbones+   -  Reputation: 1411

Like
-1Likes
Like

Posted 13 June 2013 - 11:20 PM

Huh, can't you just handle WM_SYSKEYDOWN normally in the window procedure? That surely is a better idea? =|


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.

#15 Tispe   Members   -  Reputation: 879

Like
0Likes
Like

Posted 14 June 2013 - 03:36 AM

Huh, can't you just handle WM_SYSKEYDOWN normally in the window procedure? That surely is a better idea? =|

 

Handle in what way? By not returning DefWindowProc(hWnd, message, wParam, lParam); on the message? I think that causes errors further down the road if data is laying around not being fully processed.



#16 Cocalola   Members   -  Reputation: 108

Like
0Likes
Like

Posted 15 June 2013 - 01:57 AM

Is Vortez a good programmer ?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS