WM_POWERBROADCAST 消息未在 MFC Dlg 中捕获 [英] WM_POWERBROADCAST message not caught in MFC Dlg

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

问题描述

当系统进入睡眠模式时,我尝试捕捉 WM_POWERBROADCAST 消息.

I try to catch WM_POWERBROADCAST message when the system goes into sleep mode.

我正在这样做:

BOOL CPowManApp::PreTranslateMessage(MSG* pMsg) 
{
    if(pMsg->message == WM_POWERBROADCAST || pMsg->message == WM_POWER)
    {
        CString strMessage;

        strMessage.Format(_T("%d WM_POWERB%s wParam %x lParam %x"),
                         pMsg->time,
                         pMsg->message == WM_POWER?_T(""):_T("BRAODCAST"),
                         pMsg->wParam,
                         pMsg->lParam);

        OutputDebugString(strMessage);
    }

    return CWinApp::PreTranslateMessage(pMsg);
}

它根本不起作用.同时,一个 win32 应用程序工作得很好.我试图将消息处理程序放在 Dlg 类中是徒劳的.

It simply doesn't work. Meanwhile a win32 app works just fine. I tried to put the message handler in the Dlg class in vain.

我正在使用 VS6.0 构建应用程序.我哪里错了?

I'm building the app with VS6.0. Where am I wrong?

推荐答案

在你的消息映射中

ON_MESSAGE( WM_POWERBROADCAST, OnPowerBroadcast )

实施

LRESULT CDialogDlg::OnPowerBroadcast(WPARAM wParam, LPARAM lParam)
{
    switch (wParam)
    {
        case PBT_...
    }
}

请务必查看 MSDNwParam 值周围的一些特定于操作系统的情况.

Be sure to check MSDN for some OS-specific cases around the wParam values.

这篇关于WM_POWERBROADCAST 消息未在 MFC Dlg 中捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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