使用 AFX 消息映射捕获窗口关闭事件,处理函数永远不会被调用

问题描述 投票:0回答:1

我有一个 Windows C++ 应用程序,我想正常关闭它。根据我的研究,QueryEndSession、EndSession 和 Powerbroadcast 是我们感兴趣的 Windows 事件。

所以我像这样将它们插入到我的消息映射中


    BEGIN_MESSAGE_MAP(CProgView, CFormView)
        
        ON_WM_QUERYENDSESSION()
        ON_WM_ENDSESSION()
        ON_WM_POWERBROADCAST()
    
    END_MESSAGE_MAP()

并在.h中添加了需要的函数


    afx_msg BOOL OnQueryEndSession();
    afx_msg void OnEndSession(BOOL);
    afx_msg UINT OnPowerBroadcast(UINT, LPARAM);

和.cpp


    BOOL CProgView::OnQueryEndSession()
    {
        return 0;
    }
    
    void CProgView::OnEndSession(BOOL b)
    {
    
        int x = 1;
    
    }
    
    UINT CProgView::OnPowerBroadcast(UINT nPowerEvent, LPARAM nEventData)
    {
        return 0;
    }

但是当我尝试关闭或模拟关闭时,它会失败并且我的断点不会被命中。

C:\Program Files (x86)\Windows Kits\10\App Certification Kit>rmlogotest.exe 5112

LOGO 验证失败。无法关闭注册进程 ID 5112,错误代码为 0000015f

Debugging Information --
# of Proc/Svcs   : 1
Reboot ReasonCode: 00000000

    Session 1, Pid 5112, Type 1, Status 1 - progName ()

我错过了什么?

visual-c++ shutdown afx message-map
1个回答
1
投票

@Dxiv 指出这些处理程序需要位于顶级窗口中,这是正确的。

© www.soinside.com 2019 - 2024. All rights reserved.