Launch System Screensaver from C# Windows Form

旧时模样 提交于 2019-11-27 06:11:13

问题


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


回答1:


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);
}


来源:https://stackoverflow.com/questions/267728/launch-system-screensaver-from-c-sharp-windows-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!