如何自动关闭屏幕
我想用vs2005的c++设计一个定时关闭屏幕的程序,请问如何实现? 善用google在Windows CE中,显示的控制是通过Ext­Escape函数。这是一个显示和打印机驱动的后门。Windows CE显示驱动支持许多设备转义代码(escape codes),这些被公布在Platform Builder中。对于我们的目的来说,只有两个转义代码被用到:SETPOWERMANAGEMENT来设置显示的电源状态和QUERYESCSUPPORT来查询是否SETPOWERMANAGEMENT被驱动支持。下面的例子打开或关闭系统显示通过显示驱动,并且支持完全的转义代码:
//
// Defines and structures taken from pwingdi.h in the Platform Builder
//
#define QUERYESCSUPPORT 8
#define SETPOWERMANAGEMENT 6147
#define GETPOWERMANAGEMENT 6148
typedef enum _VIDEO_POWER_STATE {
VideoPowerOn = 1,
VideoPowerStandBy,
VideoPowerSuspend,
VideoPowerOff
} VIDEO_POWER_STATE, *PVIDEO_POWER_STATE;
typedef struct _VIDEO_POWER_MANAGEMENT {
ULONG Length;
ULONG DPMSVersion;
ULONG PowerState;
} VIDEO_POWER_MANAGEMENT, *PVIDEO_POWER_MANAGEMENT;
//----------------------------------------------------------------------
// SetVideoPower - Turns on or off the display
//
int SetVideoPower (BOOL fOn) {
VIDEO_POWER_MANAGEMENT vpm;
int rc, fQueryEsc;
HDC hdc;
// Get the display dc.
hdc = GetDC (NULL);
// See if supported.
fQueryEsc = SETPOWERMANAGEMENT;
rc = ExtEscape (hdc, QUERYESCSUPPORT, sizeof (fQueryEsc),
(LPSTR)&fQueryEsc, 0, 0);
if (rc == 0) {
// No support, fail.
ReleaseDC (NULL, hdc);
return -1;
}
// Fill in the power management structure.
vpm.Length = sizeof (vpm);
vpm.DPMSVersion = 1;
if (fOn)
vpm.PowerState = VideoPowerOn;
else
vpm.PowerState = VideoPowerOff;
// Tell the driver to turn on or off the display.
rc = ExtEscape (hdc, SETPOWERMANAGEMENT, sizeof (vpm),
(LPSTR)&vpm, 0, 0);
// Always release what you get.
ReleaseDC (NULL, hdc);
return 0;
}
前面的代码通过调用ExtEscape和QUERYESCSUPPORT命令来查询是否支持转移代码。被查询的命令首先交给输入缓冲,如果SETPOWERMANAGEMENT命令被支持,程序就填充VIDEO_POWER_MANAGEMENT结构并再次调用ExtEscape设置电源状态。
页:
[1]