• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Tispe

Pressing F10 pause main loop?

15 posts in this topic

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?

-1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0