在Delphi区问了,无果!来这里问问各位大虾!
我使用GetDevicePowerState(delphi没有声明这个函数)
我声明如下:
Function GetDevicePowerState(AHandle: THandle; bo: Boolean): Boolean; StdCall External 'Kernel32.dll';使用:
procedure TForm1.Button1Click(Sender: TObject);
var
b: Boolean;
begin
b := False;
if GetDevicePowerState(GetDc(0), b) then ShowMessage('成功');
if b then ShowMessage('使用中');
end;
但是不能成功返回,不知道为什么?
我使用GetDevicePowerState(delphi没有声明这个函数)
我声明如下:
Function GetDevicePowerState(AHandle: THandle; bo: Boolean): Boolean; StdCall External 'Kernel32.dll';使用:
procedure TForm1.Button1Click(Sender: TObject);
var
b: Boolean;
begin
b := False;
if GetDevicePowerState(GetDc(0), b) then ShowMessage('成功');
if b then ShowMessage('使用中');
end;
但是不能成功返回,不知道为什么?
不能帮你
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_desktopmonitor.asp为何需要知道PowerState呢?
用SetThreadExecutionState就可以指定是ON或OFF的
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/setthreadexecutionstate.asp
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. Referenceshttp://msdn.microsoft.com/library/en-us/Display_r/hh/Display_r/VideoMiniport_Functions_b47b2224-5e0b-44af-9d04-107ff1299381.xml.asphttp://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_desktopmonitor.asp