7 楼jiangsheng(蒋晟.Net[MVP])回复于 2006-01-23 09:34:25 得分 0 Q: How to detect the power state of the monitor? A: The GetDevicePowerState function is supposed to retrieve the current power state of the specified device. However, Apps may fail to use GetDevicePowerState on the display, as they can't get a handle on "\\.\Display#", while the # index is 1-based, or "\\.\LCD", for security reasons.
If you are trying to do this on Windows XP, then you can use SetupDiGetDeviceRegistryProperty and Property: SPDRP_DEVICE_POWER_DATA to get the power management information. This is documented in the Windows XP DDK.
The WMI Class Win32_DesktopMonitor does not report the power state. use SPI_GETPOWEROFFACTIVE or DeviceIOControl with IOCTL_VIDEO_GET_POWER_MANAGEMENT will simply reports power management is enabled or not. SPI_GETPOWEROFFACTIVE just determines whether the power-off phase of screen saving is enabled or not.
BTW, you can always use the SetThreadExecutionState or other APIs (you have used) to switch ON the monitor no matter the monitor is in the ON or OFF state.
A: The GetDevicePowerState function is supposed to retrieve the current power state of the specified device. However, Apps may fail to use GetDevicePowerState on the display, as they can't get a handle on "\\.\Display#", while the # index is 1-based, or "\\.\LCD", for security reasons.
If you are trying to do this on Windows XP, then you can use SetupDiGetDeviceRegistryProperty and Property: SPDRP_DEVICE_POWER_DATA to get the power management information. This is documented in the Windows XP DDK.
The WMI Class Win32_DesktopMonitor does not report the power state. use SPI_GETPOWEROFFACTIVE or DeviceIOControl with IOCTL_VIDEO_GET_POWER_MANAGEMENT will simply reports power management is enabled or not. SPI_GETPOWEROFFACTIVE just determines whether the power-off phase of screen saving is enabled or not.
BTW, you can always use the SetThreadExecutionState or other APIs (you have used) to switch ON the monitor no matter the monitor is in the ON or OFF state.
References
http://msdn.microsoft.com/library/en-us/Display_r/hh/Display_r/VideoMiniport_Functions_b47b2224-5e0b-44af-9d04-107ff1299381.xml.asp
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_desktopmonitor.asp