How can my program know when the screen saver is activated or deactivated?

Started by
3 comments, last by GameDev.net 19 years, 4 months ago
I basically have a program that sits in the background (using a tray icon), and I want it to do stuff whenever the screen saver is activated or deactivated. How do I go about doing this? Does Windows send a message to every top-level window when that happens? What message? I can't seem to find anything very helpful on MSDN.
Advertisement
"Before Windows starts the screensaver, it broadcasts a WM_SYSCOMMAND message with WPARAM set to SC_SCREENSAVE. If any program catches the message and returns true, the screensaver will not start."
Ok, thanks, but what about when the screen saver is deactivated?
I'm not sure that event can be trapped in a simple way.
But you can determine if a screensaver is running with SystemParametersInfo(), specifying SPI_GETSCREENSAVERRUNNING (Google for this). Perhaps you can set an interval that checks for this condition.
Good luck.
You may be able to set a boolean when the screen saver is running, and then use something like the following (from a C++Builder program, so modify accordingly):

void __fastcall TForm1::WndProc(TMessage & msg) {   if (msg.Msg==WM_ACTIVATEAPP && msg.WParam==TRUE && screenSaverRunningC) {      //do whatever...      screenSaverRunningC = false;      }

This topic is closed to new replies.

Advertisement