Wednesday, February 18, 2009

[VC++] Programmatically starting/stoping screensaver

For starting windows screen saver send WM_SYSCOMMAND message to your own window with parameter SC_SCREENSAVE

PostMessage( WM_SYSCOMMAND, SC_SCREENSAVE );

For stopping windows screen saver - use SystemParametersInfo() for knowing whether screen saver is running or not and if running close the foreground window.

if( ::SystemParametersInfo( SPI_GETSCREENSAVERRUNNING,0,&bSaver,0 ))
{
if( bSaver )
{
::PostMessage (::GetForegroundWindow(), WM_CLOSE, 0L, 0L);
}
}

No comments: