SendMessage/SC_MONITORPOWER 在运行 Windows 8 时不会打开监视器 [英] SendMessage/SC_MONITORPOWER won't turn monitor ON when running Windows 8

查看:31
本文介绍了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 时不会打开监视器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆