MFC Dlg 中未捕获 WM_POWERBROADCAST 消息

发布于 2024-07-19 05:41:30 字数 728 浏览 3 评论 0原文

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

我正在这样做:

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 类中,但没有成功。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡渣熟男 2024-07-26 05:41:30

在您的消息映射

ON_MESSAGE( WM_POWERBROADCAST, OnPowerBroadcast )

实现

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

中,请务必检查 MSDN 对于 wParam 值周围的一些特定于操作系统的情况。

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.

橘香 2024-07-26 05:41:30

此消息的文档特别

窗口通过其 WindowProc 函数接收此消息。

您是否尝试过在主窗口上覆盖此方法?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文