Windows鎖定螢幕然後關閉顯示器,可執行程式

來源:互聯網
上載者:User

標籤: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鎖定螢幕然後關閉顯示器,可執行程式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.