Tuesday, March 01, 2005

Programatically Powering PocketPC Screen On and Off

Another common request is how to power the Pocket PC screen on or of programatically. The solution to this problem is the ExtEscape API, with the SETPOWERMANAGEMENT flag set. Note that implementing support for this particular ExtEscape capability is OEM dependent. Therefore, it may not work on all devices. This is why we call ExtEscape with QUERYESCSUPPORT at the beginning of the PowerScreen function call.

#define QUERYESCSUPPORT 8

//The following are unique to Windows CE
#define GETVFRAMEPHYSICAL 6144
#define GETVFRAMELEN 6145
#define DBGDRIVERSTAT 6146
#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;

void PowerScreen(BOOL bPowerOn)
{
VIDEO_POWER_MANAGEMENT vpm, vpmQuery;
BOOL bCurrentState = FALSE;

int iESC = SETPOWERMANAGEMENT;
if (ExtEscape(g_hdc, QUERYESCSUPPORT,
sizeof(int), (LPCSTR)&iESC,
0, NULL)==0)
return;


//Prevent the screen manager from
//attempting to turn the screen on if it's
//already on, and from turning the

//screen off if it's already off.

//This is a problem on some platforms,

//such as the iPAQ H3800 PocketPC 2002 platform.

memset(&vpm, 0, sizeof(vpm));
vpm.Length = sizeof(vpm);
vpm.DPMSVersion = 0x0001;

memset(&vpmQuery, 0, sizeof(vpmQuery));
vpmQuery.Length = sizeof(vpmQuery);
vpmQuery.DPMSVersion = 0x0001;

//Query the current screen power status

::ExtEscape(g_hdc, GETPOWERMANAGEMENT,
vpm.Length, (LPCSTR)&vpm,
vpmQuery.Length, (LPSTR)&vpmQuery);

bCurrentState =

((vpmQuery.PowerState > VideoPowerOn) ? FALSE : TRUE);

if (bPowerOn == bCurrentState)
return;

memset(&vpm, 0, sizeof(vpm));
vpm.Length = sizeof(vpm);
vpm.DPMSVersion = 0x0001;
vpm.PowerState = (bPowerOn ? VideoPowerOn : VideoPowerOff);

::ExtEscape(g_hdc, SETPOWERMANAGEMENT,
vpm.Length, (LPCSTR)&vpm, 0, NULL);
}



1 Comments:

At 4:21 AM, Blogger Unknown said...

Your code same was very helpful... Thanks!

 

Post a Comment

<< Home