bool done = false;
while (!done)
{
PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE);
// Either I'm checking this wrong or quit
// messages aren't posting!
if (msg.message == WM_QUIT)
{
done = true;
}
else
{
/* some rendering code */
SwapBuffers(g_hdc);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
The Stupid Message loop Question
Okay, I've been staring at this for hours and I can't figure out for the life of me what's wrong. I was hoping someone on here would be kind enough to point out my (likely) trivial mistake.
I was trying to get a basic framework up and running and ran into problems getting my window to close by itself. Whenever I hit close, the program either freezes or the window closes but the message loop keeps on trucking. Either I'm checking msg.message wrong or PostQuitMessage is not properly posting to the queue (SendMessage(WM_QUIT) doesn't work either). I got this code from the book "OpenGL Game Programming" by Hawkins & Astle. This code is copied verbatim from the book.
Any ideas?
DoomGaze
[edited by - DoomGaze on March 3, 2003 2:11:58 PM]
[edited by - DoomGaze on March 3, 2003 2:13:11 PM]
DoomGaze
Not sure if this'll help, but the relevant code from TOTWGPG 2nd ed. is:
I remember that it worked correctly and the only differences (aside from the hwnd parameter, rendering line and the above Game_Main call) wouldn't seem to affect this.
[edited by - kordova on March 3, 2003 2:39:08 PM]
while (TRUE) { PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); if (msg.message == WM_QUIT) break; else { TranslateMessage(&msg); DispatchMessage(&msg); } //main game processing goes here Game_Main(); }
I remember that it worked correctly and the only differences (aside from the hwnd parameter, rendering line and the above Game_Main call) wouldn't seem to affect this.
[edited by - kordova on March 3, 2003 2:39:08 PM]
I''ve also got this book and that code differs slightly in mine, this is how it is written in my copy (copied exactly)
its only a small difference but it might be worth trying out
while(!done){ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) //pending message? { if(msg.message == WM_QUIT) //if a quit message has been { //recieved you want to quit the done = TRUE //application } else { //do stuff TranslateMessage(&msg); //translate the message DispatchMessage(&msg); //dispatch the message to Windows } }}
its only a small difference but it might be worth trying out
um...humm...
i don't know whats going on...change the hwnd parameter to NULL, and see if that helps.
[edited by - MattS423 on March 3, 2003 3:01:26 PM]
i don't know whats going on...change the hwnd parameter to NULL, and see if that helps.
[edited by - MattS423 on March 3, 2003 3:01:26 PM]
Programmers of the world, UNTIE!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement