Question

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

Was it helpful?

Solution

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top