获取显示器是关闭还是打开【无解】

以下是收集的资料:

 


 

CCD API
http://msdn.microsoft.com/en-us/library/windows/hardware/ff539372(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/hardware/ff539370(v=vs.85).aspx

这组API从WIN7支持,但是也不能获取。



HANDLE hDevice = CreateFile("\\\\.\\LCD\\", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if ( hDevice==INVALID_HANDLE_VALUE ) {
return;
}
GetDevicePowerState(hDevice, &bOn);

该方法在CreateFile就失败了。


 

Here's a list of API functions related to multiple monitors:

ChangeDisplaySettingsEx: changes display settings
EnumDisplayDevices: enumerates all displays, including disabled ones
EnumDisplayMonitors: enumerates all enabled displays
EnumDisplaySettingsEx: gets display settings
GetMonitorInfo: gets information about a monitor such as the working area
MonitorFromPoint: returns the monitor containing a given point
MonitorFromRect: returns the monitor containing a given rectangle
MonitorFromWindow: returns the monitor containing a given window
API functions specific to Windows 7:

QueryDisplayConfig: returns current display settings
SetDisplayConfig: sets current display settings

----------------------------------------

http://www.cctry.com/forum.php?mod=viewthread&tid=62019

对自己感兴趣的事件进行处理.
键是:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify

楼主看看这个例子吧,肯定是你想要的!

Introduction
The Winlogon Notification Package is a DLL which exports functions that handle Winlogon.exe events. These event messages includes lock, unlock, logoff, logon, startup, shutdown, startscreensaver, stopscreensaver, and startshell.

This article demonstrates how to use the Winlogon Notification Package as an alternative to NT Services. The main benefits for doing this is better handling of user activities. In addition, the Winlogon Notification Package will be very lightweight and requires much less code then its NT service equivalent.

http://www.codeproject.com/Articles/877/Taking-Advantage-of-the-Winlogon-Notification-Pack


有无显示器:GetSystemMetrics(SM_CMONITORS)

这个显示器线拔掉仍然返回1.


 

 

RegisterPowerSettingNotification
only for vista/Windows Server 2008


GetDevicePowerState cannot be used to find out if the display monitor is currently powered up. This is an issue that has been solved in Windows Vista, as you will discover at the end of this article.


 

WM_POWERBROADCAST
WM_POWERBROADCAST doesn't notify display power events

Requirements
Client
Requires Windows Vista, Windows XP, or Windows 2000 Professional.

Server
Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.

Header
Declared in WinUser.h; include Windows.h.


 

GetSystemPowerStatus主要获取电池的状态

http://www.codemag.com/article/0512102

 


 

I've tried with WMI, using the Win32_DesktopMonitor and check the "Availability", but the value returned is always 3 (powered on), even when the monitor is physically turned off.

不管你是关闭还是打开显示器,返回值恒为3


 

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.

 


 

 

 

 

 

 

 

 

 

你可能感兴趣的:(获取)