community.borland.com

Article #17169: Windows screen saver on/off in code

 Question and Answer Database

FAQ2169C.txt   Windows screen saver on/off in code
Category   :Windows API
Platform    :All
Product    :C++Builder  1.x

Question:
How do I turn the Windows Screen Saver on in code?

Answer:
The following function tests to see if the WIndows Screen Saver is
available, and if so, turns it on:

// function prototype
bool TurnScreenSaverOn();

//function implementation
bool TForm1::TurnScreenSaverOn()
{
    bool b;
    if ((SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,&b,0))!= true)
    	exit;
    if(!b)
    	exit;
    PostMessage(Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
    return true;
}

//function call
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TurnScreenSaverOn();
}

7/2/98 10:32:32 AM
 

Last Modified: 01-SEP-99