关闭/打开显示器:无法打开 [英] Turn off/on monitor: can't turn on

查看:41
本文介绍了关闭/打开显示器:无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谷歌上找到了这个:

I found this on google:

版本 1:

SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2); //turn off
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1);  //turn on

版本 2:

HWND h = FindWindow(0, 0);
SendMessage(h, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
SendMessage(h, WM_SYSCOMMAND, SC_MONITORPOWER, -1);

在我的笔记本电脑上(Win8.1+Visual Studio 2010):对于这两个版本,关闭都有效,但开启无效.当执行开启代码时,屏幕会立即亮起然后再次熄灭.

On my laptop(Win8.1+Visual Studio 2010): For both versions, turnoff works but turnon doesn't. When turnon code is executed, the screen is on and then off again immediately.

另一个有趣的事情:在我的桌面(Win8.1+VS2013),程序会卡在版本1的任何一行.但是,它可以通过版本2.关闭工作,但打开完全无效.

Another interesting thing: on my desktop(Win8.1+VS2013), the program will stuck on either line of version 1. But, it can go through version 2. Turn off works, but turn on is totally ineffective.

推荐答案

WM_SYSCOMMAND with SC_MONITOR 似乎因为 Windows 8 更先进的节能功能而无法唤醒显示器功能,而 sleep 工作正常.

WM_SYSCOMMAND with SC_MONITOR appears to be broken to wake up the monitor since Windows 8's more advanced energy saving features, whilst sleep works fine.

你也可以在核心系统级别触发一个小的鼠标移动来触发正确的唤醒,示例代码在 C# 中,但应该很容易移植到 C++:

You could alternatively trigger a small mouse move at the core system level to trigger waking up correctly, example code in C# but should be easily ported to C++:

void Main( object )
{
  int MOUSEEVENTF_MOVE = 0x0001;

  mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, UIntPtr.Zero);
  System.Threading.Thread.Sleep( 40 );
  mouse_event(MOUSEEVENTF_MOVE, 0, -1, 0, UIntPtr.Zero);
}

文档.正式您应该使用 SendInput,但 mouse_event 不会很快消失(自 Vista 以来它已被半弃用).

Documentation. Formally you should use SendInput, but mouse_event isn't going anywhere soon (it's been semi-deprecated since Vista).

这篇关于关闭/打开显示器:无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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