Jump to content
  • Advertisement
Sign in to follow this  
Samurai Jack

PeekMessage trouble

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

Greetings! I have some trouble with peek message in my game loop. It is just a small structure like this: RegisterClass() ok. CreateWindow() ok. MSG Msg; ZeroMemory(&Msg, sizeof(MSG)); while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) (. TranslateMessage(&Msg); DispatchMessage(&Msg);.) The problem is, whenever I outsource the loop in to a method like this: UINT GetWindowMsg(void) if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) (. TranslateMessage(&Msg); DispatchMessage(&Msg);.) return Msg.message; My window program hangs whenever I press the "X" to close the window. How comes? Why does the upper example work normaly but the lower does not? I use it like this: while (GetWindowMsg() != WM_QUIT) if (isEscape) PostQuitMessage(0); I have also overriden the WM_Destroy message to post a quit message but it does not help. My program reaches the WM_DESTROY message in the window loop but it does not completly close. The program loops forever, but not in my while loop. Any suggestions? Thank you in advacne!

Share this post


Link to post
Share on other sites
Advertisement
Show how you handle WM_DESTROY. Here's what your window procedure should look like:

LRESULT CALLBACK WndProc(UINT msg, HWND wnd, WPARAM wparam, LPARAM lparam)
{
...
switch (msg)
{
...

case WM_CLOSE:
DestroyWindow(wnd);
return 0:

...

case WM_DESTROY:
return PostQuitMessage(0);

...
}

return DefWindowProc(msg, wnd, wparam, lparam);
}


Be sure that you handle WM_CLOSE and generate a WM_DESTROY as a consequence. Code, of course, helps us see what your problem is (what on earth were you posting, with all those parentheses and things? check out the site FAQ for information on how to correctly post code!)

Share this post


Link to post
Share on other sites
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!