有没有办法检测 Windows 中的监视器状态(打开或关闭)? [英] Is there any way to detect the monitor state in Windows (on or off)?

查看:65
本文介绍了有没有办法检测 Windows 中的监视器状态(打开或关闭)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道在 Windows (XP/Vista/2000/2003) 中是否有获取当前监视器状态(打开或关闭)的 API?

Does anyone know if there is an API to get the current monitor state (on or off) in Windows (XP/Vista/2000/2003)?

我所有的搜索似乎都表明没有真正的方法可以做到这一点.

All of my searches seem to indicate there is no real way of doing this.

这个帖子 尝试使用 GetDevicePowerState 根据微软的文档,它不适用于显示设备.

This thread tries to use GetDevicePowerState which according to Microsoft's docs does not work for display devices.

在 Vista 中,我可以收听 GUID_MONITOR_POWER_ON但是当手动关闭监视器时,我似乎没有收到事件.

In Vista I can listen to GUID_MONITOR_POWER_ON but I do not seem to get events when the monitor is turned off manually.

在 XP 中,我可以挂接到 WM_SYSCOMMAND SC_MONITORPOWER,寻找状态 2.这仅适用于系统触发断电的情况.

In XP I can hook into WM_SYSCOMMAND SC_MONITORPOWER, looking for status 2. This only works for situations where the system triggers the power off.

WMI Win32_DesktopMonitor 类似乎也没有帮助.

The WMI Win32_DesktopMonitor class does not seem to help out as well.

编辑:这是讨论 comp.os.ms-windows.programmer.win32 表明没有可靠的方法来做到这一点.

Edit: Here is a discussion on comp.os.ms-windows.programmer.win32 indicating there is no reliable way of doing this.

其他人有任何其他想法吗?

Anyone else have any other ideas?

推荐答案

GetDevicePowerState 有时适用于监视器.如果它存在,您可以打开 \\.\LCD 设备.完成后立即关闭它.

GetDevicePowerState sometimes works for monitors. If it's present, you can open the \\.\LCD device. Close it immediately after you've finished with it.

从本质上讲,您不走运——没有可靠的方法来检测显示器电源状态,除了编写设备驱动程序并过滤显示驱动程序链上下的所有电源 IRP.而且这也不是很可靠.

Essentially, you're out of luck—there is no reliable way to detect the monitor power state, short of writing a device driver and filtering all of the power IRPs up and down the display driver chain. And that's not very reliable either.

这篇关于有没有办法检测 Windows 中的监视器状态(打开或关闭)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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