fire event if screensaver starts

S

sanjana

hi i want to fire an event if the screen saver starts up
i have done it using a timer tick event where i have used the api
function to detect if screensaver has started..but this means
continuous polling at each timer click..

private void tick(object sender, System.EventArgs e)
{
const int SPI_GETSCREENSAVERRUNNING = 114;
int screenSaverRunning = -1;
// is the screen saver running?

int ok = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref
screenSaverRunning, 0);

if (ok == 0)
{
Console.WriteLine("Call to SystemParametersInfo failed.");

}
if (screenSaverRunning != 0)
{
// screen saver is running
MessageBox.Show("screensaver runs");

}
else
{
}
}





is there a better way of doing something like no use of timer..
i want someting like-- if screensaver starts then a event gets fired
and if screen saver stops another event gets fired..this wud avoid
getting in the loop of timer tick event..
So my question is "is it possible to just fire events if screen saver
starts or stops without using timer ??"
 
L

Larry Lard

sanjana said:
hi i want to fire an event if the screen saver starts up

There doesn't seem to be a Framework way of dealing with this, which
means you're going to have to do it the old-fashioned way.

Note that there isn't normally a global message sent when the
screensaver starts - only the active top level window gets a
WM_SYSCOMMAND message, with wParam set to SC_SCREENSAVE. So to be
notified of screensaver startup whether you are the active top level
window or not, you need to create a hook that catches that message then
sends a broadcast message of your own to all top level windows.

The full info is here in this Ask Dr GUI #48 article from way back:

<http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/drgui48.asp>

The other alternative, as you have found, is to poll
SystemParametersInfo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top