永无止境的 Win32 消息循环 [英] Never ending Win32 Message loop

查看:39
本文介绍了永无止境的 Win32 消息循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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

一旦它通过 peekmessage 进入内循环,它就不会退出,直到应用程序关闭.因此,如果我在 Render() 和 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();
        }
}

这篇关于永无止境的 Win32 消息循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆