zoukankan      html  css  js  c++  java
  • Windows锁定屏幕然后关闭显示器,可执行程序

    有时候我们需要关闭屏幕来休息一下或者在本上写东西,但是屏幕亮着的时候会分心,但是关闭显示器又太麻烦了,所以直接来一个小程序(非微信小程序)。还有一种情况,有时候晚上要离开电脑旁了,但是电脑还在做事情,不想关电脑,又因为晚上黑乎乎的,屏幕亮着会被骂的,综合以上情况,这端代码非常适合你。

    如果你不会编译代码,没关系,我这里有编译好的可执行文件,下载链接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

  • 相关阅读:
    退背包
    杜教筛BM
    Petya and Array CodeForces
    AC自动机模板
    KMP模板
    Docker系列器九:docker-compose与docker-compose.yml语法
    Fabric的简单Web应用
    ubuntu防火墙
    ubuntu16.04 HyperLedger Fabric 1.2.0 开发环境搭建
    crypto-config.yaml
  • 原文地址:https://www.cnblogs.com/yxxrui/p/6661809.html
Copyright © 2011-2022 走看看