views:

50

answers:

2

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:
http://bytes.com/topic/visual-basic-net/answers/349073-know-when-os-goes-into-screen-saver
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?

Edit: For testing I used the default windows screensaver (the one with windows logo).

A: 

This is a relatively complex task (although it would be nice if it were easy).

Some of these tests you'll find online only work if your window is in focus. If it's running in the background it may not receive such messages.

Other tests rely on a screensaver program running (check the currently set screensaver, and then watch the process list to see if it's active) but don't work if you go into powersave mode, or if your screensaver is a black screen (ie, no program, just monitor off).

I don't believe there's an ideal way to do this. You might want to go back to the beginning and think more carefully about why you need to detect this state, and what you are trying to accomplish. You might need a different solution.

Adam Davis
I want to notify user in an unobtrusive way. My idea was to display it when the screensaver starts or the monitor powers on. That way I won't be interrupting anything.
MMx
+1  A: 

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.

MMx