开发者

Never ending Win32 Message loop [closed]

开发者 https://www.devze.com 2022-12-12 23:33 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. 开发者_如何学JAVA Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.
开发者_如何学JAVA

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 13 years ago.

Improve this question

I 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();
        }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号