Launch System Screensaver from C# Windows Form

后端 未结 1 952
后悔当初
后悔当初 2020-12-10 16:05

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

相关标签:
1条回答
  • 2020-12-10 16:48

    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);
    }
    
    0 讨论(0)
提交回复
热议问题