WM_POWERBROADCAST message did not hit MFC Dlg

I am trying to catch the WM_POWERBROADCAST message when the system goes to sleep.

I am 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 just doesn't work. Meanwhile the win32 app works fine. I tried to route a message handler to the Dlg class in vain.

I am creating an application with VS6.0. Where am I going wrong?

0


a source to share


2 answers


On the message card

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 related cases around wParam values.

+2


a source


The documentation of this post specifically says :

The window receives this message through its WindowProc function.



Have you tried rewriting this method in your main window?

0


a source







All Articles