WM_ENDSESSION消息有问题 [英] Problem with WM_ENDSESSION message

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

问题描述

我对 WM_ENDSESSION 消息有疑问.也就是说,当 WM_ENDSESSION 消息正在发送时,我想退出应用程序(WindowProc)的主循环...所以,我写了这样的东西:

I have a problem with WM_ENDSESSION message. Namely I would like to exit from the main loop of the application (WindowProc) when the WM_ENDSESSION message is sending... So, I wrote something like that:

LRESULT CALLBACK windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    //...       
    case WM_QUERYENDSESSION: return TRUE;       
    case WM_ENDSESSION: 
         if(wParam) PostQuitMessage(0);         
    break;    
    default:
        return DefWindowProc(hwnd,msg,wParam,lParam);
    }

    return 0;
}

...,但不起作用-应用程序未退出主循环...

..., but it doesn't work - application doesn't exit the main loop...

我在msdn上阅读了有关WM_QUERYENDSESSION和WM_ENDSESSION的信息,但找不到任何有用的信息...

I read about WM_QUERYENDSESSION and WM_ENDSESSION on msdn, but I couldn't find any helpful information...

任何主意,哪里出了错?

Any idea, where is the mistake?

推荐答案

我认为调用PostQuitMessage响应WM_QUERYENDSESSION没错.

I don't think it's wrong to call PostQuitMessage in response to WM_QUERYENDSESSION.

WM_ENDSESSION是世界的尽头.那时将工作推迟到稍后时间(调用PostQuitMessage)为时已晚.现在就做,否则您将永远没有机会做.另外,考虑您在做什么.正如雷蒙德·陈(Raymond Chen)曾经说过的那样:"[响应WM_ENDSESSION清理您的应用程序,就像]在拆除建筑物之前花时间蒸汽清洗地毯.浪费了精力."

WM_ENDSESSION is the end of the world. It's too late at that point to postpone work until a later time (calling PostQuitMessage). Do it now, or you'll never get a chance to do it. Also, consider what you are doing. As Raymond Chen once put it, "[cleaning up your app in response to WM_ENDSESSION is] like taking the time to steam-clean the rugs before you demolish the building. Wasted effort."

WM_QUERYENDSESSION授予您的窗口与用户交互的最后机会.您已代表用户决定您的应用程序将终止,并且希望正常退出,因此这是您安排应用程序的最后机会.

WM_QUERYENDSESSION grants your window a last-chance to interact with the user. You have decided on behalf of the user that your app will die and you want to gracefully exit, so this is your last opportunity to schedule it.

已更新

我不知道它甚至对PostQuitMessage都有效以响应WM_QUERYENDSESSION. MSDN文档指出:在系统处理WM_QUERYENDSESSION消息的结果之后,发送 WM_ENDSESSION消息到应用程序."

I don't know that will even work to PostQuitMessage in response to WM_QUERYENDSESSION. The MSDN docs state, "The WM_ENDSESSION message is sent to an application after the system processes the results of the WM_QUERYENDSESSION message."

已发送表示消息泵不会破解消息.当然,甚至文档作者也经常会混淆发送发布.

Sent implies that the message pump doesn't get a crack at messages. Of course, even the doc authors often confuse sent and posted.

这篇关于WM_ENDSESSION消息有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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