Never ending Win32 Message loop [closed]
开发者_如何学JAVA
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this questionI have the following code:
MSG mssg;
// run till completed
while (true) {
// is there a message to process?
while(PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) {
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
}
if(mssg.message == WM_QUIT){
break;
}
// our stuff will go here!!
Render();
listeners->OnUpdate();
}
Once it enters the inner loop with peekmessage it does not exit until the application is closed. Thus if I place a breakpoint at Render() and OnUpdate(), they will never be called during the lifetime of the application.
This runs contrary to what I'm being told here and here. How do I do this properly?
A typical game loop has this form:
MSG mssg;
bool notdone = true;
// run till completed
while ( notdone ) {
// is there a message to process?
if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) {
if (mssg.message == WM_QUIT) notdone = false;
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
} else {
// our stuff will go here!!
Render();
listeners->OnUpdate();
}
}
精彩评论