接收屏保通知 [英] Receive screensaver notification
问题描述
我想在屏幕保护程序即将启动时在我的 C++ 应用程序中收到通知.我尝试使用 wParam == SC_SCREENSAVE
收听 WM_SYSCOMMAND
消息,其中 有些人认为应该这样做.那没有用.Spy++ 甚至显示我的窗口没有收到任何 WM_SYSCOMMAND
消息.有趣的是,当我关闭显示器时,我确实收到了带有 wParam == SC_MONITORPOWER
的消息.我理解错了吗?还是我只是错过了什么?
I want to receive a notification in my C++ application when a screensaver is about to start. I tried listening to WM_SYSCOMMAND
messages with wParam == SC_SCREENSAVE
which some people think should do the trick.
That didn't work. Spy++ even showed that my window didn't receive any WM_SYSCOMMAND
message. Interesting thing is when I turned off the monitor I did receive the message with wParam == SC_MONITORPOWER
. Am I understanding it wrong? Or did I just miss something?
为了测试,我使用了默认的 Windows 屏幕保护程序(带有 Windows 徽标的屏幕保护程序).
For testing I used the default windows screensaver (the one with windows logo).
推荐答案
看来只有当我的窗口有焦点时,我才会收到 SC_SCREENSAVE 消息.解决这个问题的方法是设置 全局钩子.这需要我 将回调函数放在单独的DLL 并且还有一个关于钩子减慢系统速度的可怕信息,所以我决定放弃响应屏幕保护程序启动的想法.
It appears that I will receive the SC_SCREENSAVE message only when my window has focus. The way around this is to set global hook. That would require me to put the callback function in a separate DLL and there is also this scary message about hooks slowing down the system so I decided to drop the idea of responding to screensaver start.
这篇关于接收屏保通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!