WM_POWERBROADCAST message not caught in MFC Dlg

若如初见. 提交于 2019-12-10 00:19:48

问题


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

I'm doing like :

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

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.

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


回答1:


In your message map

ON_MESSAGE( WM_POWERBROADCAST, OnPowerBroadcast )

Implementation

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

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




回答2:


The documentation of this message specifically says:

A window receives this message through its WindowProc function.

Have you tried to overwrite this method on your main window?



来源:https://stackoverflow.com/questions/867682/wm-powerbroadcast-message-not-caught-in-mfc-dlg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!