关闭显示器

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Runtime.InteropServices;
 6 using System.Diagnostics;
 7 
 8 
 9 namespace StopWatch
10 {
11     class SYSClass
12     {
13 
14         public const uint WM_SYSCOMMAND = 0x0112;
15         public const uint SC_MONITORPOWER = 0xF170;
16         [DllImport("user32")]
17         public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, uint wParam, int lParam);
18 
19         /// <summary>
20         /// 关闭显示器 
21         /// </summary>
22         public void CloseScreen()
23         {
24             
25             IntPtr windowHandle =  Process.GetCurrentProcess().MainWindowHandle;
26             SendMessage(windowHandle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);    // 2 为关闭显示器, -1则打开显示器 
27         }
28     }
29 }

 

使用 

new SYSClass().CloseScreen();

posted @ 2015-04-17 10:40  XE2011  阅读(239)  评论(0编辑  收藏  举报