Is there any way to detect the monitor state in Windows (on or off)?
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.
This thread tries to use GetDevicePowerState which according to Microsoft's docs does not work for display devices.
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.
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.
The WMI Win32_DesktopMonitor
class does not seem to help out as well.
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 sometimes works for monitors. If it's present, you can open the .LCD device. Close it immediately after you've finished with it.
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.
你可以连接网络摄像头,将它指向你的屏幕,并对你收到的图像做一些分析;)
在根据显示器状态做任何事情之前,请记住用户可以使用其他系统的远程桌面的计算机,这些计算机不需要连接到计算机的显示器 - 所以不要根据显示器状态关闭任何可视化。
链接地址: http://www.djcxy.com/p/47466.html上一篇: 在python中监视显示状态?