Jump to content
  • Advertisement
Sign in to follow this  
Ender1618

Win32 PeekMessage loop problem

This topic is 3663 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

So, I am using a typical win32 window and game loop:
    RECT reqRect;
    reqRect.left = 0;
    reqRect.top = 0;
    reqRect.right = 1280;
    reqRect.bottom = 1024;

    AdjustWindowRect(&reqRect,WS_OVERLAPPEDWINDOW,FALSE);

    int winWidth = reqRect.right - reqRect.left;
    int winHeight = reqRect.bottom - reqRect.top;

    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
					  GetModuleHandle(NULL), LoadIcon (NULL, IDI_APPLICATION), 
					  LoadCursor (NULL, IDC_ARROW), NULL, NULL,_T("D3D Test"), 
					  NULL };
	
    RegisterClassEx( &wc );

    // Create the application's window
    HWND hWnd = CreateWindow( _T("D3D Test"), _T("D3D Test"), 
		                      WS_OVERLAPPEDWINDOW, 10, 10, winWidth, winHeight,
		                      GetDesktopWindow(), NULL, wc.hInstance, NULL );

    g_renderer.Initialize(hWnd,TRUE,TRUE);

    // Show the window
    ShowWindow( hWnd, SW_SHOWDEFAULT );
    UpdateWindow( hWnd );

    // Enter the message loop
    MSG msg;
    ZeroMemory( &msg, sizeof(msg) );
    while( msg.message != WM_QUIT )
    {
	if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
	{
		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}
	else
		g_renderer.ProcessFrame();
    }

    // Clean up everything and exit the app
    g_renderer.Shutdown();
    UnregisterClass( _T("D3D Tutorial 1"), wc.hInstance );



Every so often I get an erroneous WM_QUIT message (such as when is hit a key on the keyboard), none of my code is firing off a WM_QUIT message, and when I run spy++ on my window i don't ever see this message. I changed the second param of my peekmessage to be my current windows hwnd, that seems to solve the problem, but I am guessing that will break any possibility of using a win32 context menu with this window (since the loop wont process child window messages)? Does anyone have any clue where this WM_QUIT might be coming from, or how to track down where it is coming from?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

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