How to get WM_POWERBROADCAST message in CWinApp?(如何在 CWinApp 中获取 WM_POWERBROADCAST 消息?)
问题描述
我创建了继承CWinApp的类,这个类有一个定时器(使用窗口定时器).
I create the class that inherited CWinApp and this class has a timer (use a window timer).
当 PC 进入睡眠模式并唤醒时,定时器回调称为唤醒的确切时间.当PC从挂起恢复时,我想不调用定时器回调.
When PC go sleep mode and wake-up, timer callback is called exact time of wake-up. I want to make to not call the timer callback when PC is resuming from suspend.
所以我尝试使用 WM_POWERBROADCAST 消息.但是此消息没有在 PreTranslateMessage() API 中捕获.我也尝试了 SetWindowLong() 与我自己的 API,但仍然没有捕捉到 WM_POWERBROADCAST 消息.
So I tried to use WM_POWERBROADCAST message. But this message didn't catch in PreTranslateMessage() API. Also I tried SetWindowLong() with my own API but still didn't catch the WM_POWERBROADCAST message.
有没有办法在CWinApp中获取WM_POWERBROADCAST?
推荐答案
在 Visual Studio C++ MFC 应用程序中,您需要将 ON_MESSAGE() 添加到消息映射中以查找 WM_POWERBROADCAST 消息如本例:
In a Visual Studio C++ MFC application you will need to add an ON_MESSAGE() to your message map looking for the WM_POWERBROADCAST message as in this example:
BEGIN_MESSAGE_MAP(CFrameworkWndApp, CWinApp)
//{{AFX_MSG_MAP(CFrameworkWndApp)
ON_WM_CHAR()
ON_WM_TIMER()
/
本文标题为:如何在 CWinApp 中获取 WM_POWERBROADCAST 消息?
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
