找传奇、传世资源到传世资源站!

编程实现关闭显示器

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

编程实现关闭显示器,通过API关闭显示器。
from clipboard
using System;using System.Collections.Generic;using System.Linq;using System.Runtime.InteropServices;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace TurnOffMonitor{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { private const uint WM_SYSCOMMAND = 0x0112; private const uint SC_MONITORPOWER = 0xF170; private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff); [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, uint wParam, int lParam); public MainWindow() { InitializeComponent(); } private void BtnTurnOffMonitor_Click(object sender, RoutedEventArgs e) { IsDisplay(false); } /// <summary> /// 是否打开显示器 /// </summary> /// <param name="isDisplay"></param> public void IsDisplay(bool isDisplay) { if (isDisplay) { SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1); //打开显示器; } else { SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2); //关闭显示器; } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复