且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从C#Windows窗体启动系统屏幕保护程序

更新时间:2023-10-28 07:59:04

下面是显示如何使用屏幕保护程序的各方面工作的好发部位。查看评论在年底为code以启动屏幕保护程序。

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.$c$cproject.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);
}