SendMessage/SC_MONITORPOWER won#39;t turn monitor ON when running Windows 8(SendMessage/SC_MONITORPOWER 在运行 Windows 8 时不会打开监视器)
问题描述
我使用以下代码打开和关闭显示器:
I turn my monitors on and off by using the following code:
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MONITORPOWER = 0xF170;
private const int MonitorTurnOn = -1;
private const int MonitorShutoff = 2;
//Turn them off
SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorShutoff);
//Turn them on
SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorTurnOn);
这曾经按预期工作,但在安装 Windows 8 之后(我假设这个是原因,因为我看到其他人也有同样的问题)打开屏幕不起作用.我仍然可以将其关闭,但无论我使用 MonitorTurnOn 运行 SendMessage() 多少次,我仍然需要移动鼠标或按键才能重新打开监视器.
This used to work as intended, but after installing Windows 8 (I assume this is the reason, since I see others have the same issue) turning the screen on won't work. I can still turn it off, but no matter how many times I run SendMessage() with MonitorTurnOn, I still have to move the mouse or press a key to get the monitors back on.
关于如何在 Windows 8 上进行这项工作的任何建议?
Any suggestions on how to make this work on Windows 8?
推荐答案
我遇到了同样的问题,我找到的解决方案是移动鼠标:
I had the same problem, the solution I found is to move the mouse :
mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, NULL);
Sleep(40);
mouse_event(MOUSEEVENTF_MOVE, 0, -1, 0, NULL);
它将唤醒显示器.早珠
这篇关于SendMessage/SC_MONITORPOWER 在运行 Windows 8 时不会打开监视器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SendMessage/SC_MONITORPOWER 在运行 Windows 8 时不会打开监视器
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- c# Math.Sqrt 实现 2022-01-01