Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch System Screensaver from C# Windows Form

Tags:

c#

screensaver

Hopefully this is a simple one, but can anyone provide some simple c# code that will launch the currently configured screensaver?

like image 993
Erik Avatar asked Nov 06 '08 05:11

Erik


1 Answers

Here is a good site showing how to work with all aspects of the screensaver. See the comments at the end for the code to start the screensaver.

http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx

    [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
    private static extern IntPtr GetDesktopWindow();

    [DllImport("user32.dll")]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

    //...

    private const int SC_SCREENSAVE = 0xF140;
    private const int WM_SYSCOMMAND = 0x0112;

    //...

    public static void SetScreenSaverRunning()
    {
    SendMessage

(GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0);
}
like image 134
Inisheer Avatar answered Sep 24 '22 10:09

Inisheer