標籤:void com ado lock 小程式 import 好的 collect span
有時候我們需要關閉螢幕來休息一下或者在本上寫東西,但是螢幕亮著的時候會分心,但是關閉顯示器又太麻煩了,所以直接來一個小程式(非小程式)。還有一種情況,有時候晚上要離開電腦旁了,但是電腦還在做事情,不想關電腦,又因為晚上黑乎乎的,螢幕亮著會被罵的,綜合以上情況,這端代碼非常適合你。
如果你不會編譯代碼,沒關係,我這裡有編譯好的可執行檔,下載連結http://www.yxxrui.cn/article/71.shtml
using System;using System.Collections.Generic;using System.Runtime.InteropServices;using System.Text;namespace LockAndCloseWindow{ class Program { //系統訊息 private const uint WM_SYSCOMMAND=0x112; //關閉顯示器的系統命令 private const int SC_MONITORPOWER=0xF170; //2為PowerOff, 1為省電狀態,-1為開機 private const int MonitorPowerOff=2; //廣播訊息,所有頂級表單都會接收 private static readonly IntPtr WND_BROADCAST = new IntPtr(0xffff); static void Main(string[] args) { LockWorkStation();//鎖定螢幕 System.Threading.Thread.Sleep(10); SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MonitorPowerOff); //關閉顯示器 } //鎖定螢幕 [DllImport("user32.dll")] public static extern bool LockWorkStation(); //關閉顯示器 [DllImport("user32.dll")] private static extern IntPtr SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam); }}
伊人部落格:原文連結:http://www.yxxrui.cn/article/70.shtml
Windows鎖定螢幕然後關閉顯示器,可執行程式