Sunil Jagadish

Power Management API in Platform SDK

leave a comment »

I demonstrated the Power Management API of the Microsoft Platform SDK during the launch of Microsoft's Academic Projects Program here in Bangalore.

Microsoft Platform SDK is a colelction of powerful APIs which you can play around with to do a bit of system-level programming. You could use the Microsoft VC++ compiler to compile your programs.

The Power Management Demo I showed is pretty simple and straight-forward. The user is intimated through an alert when there is a change in power source. In a real-time scenario one could perform actions to change the execution state/processor consmption of the application when the computer is running on battery. This is done using one simple function:

BOOL GetSystemPowerStatus(


to which you would have to pass the reference of an object of type SYSTEM_POWER_STATUS structure. The power source is indicated by the value of the structure variable ACLineStatus (0 – Battery, 1 – AC Power & 255 – Unknown).

In the main window message processing function (WndProc), you can invoke this function when the WM_POWERBROADCAST message is received.


BOOL ret;


ret = GetSystemPowerStatus(&sps);


MessageBox(hWnd,TEXT("You are on AC power"),TEXT("Power Management Demo"),0);


MessageBox(hWnd,TEXT("You are on battery power"),TEXT("Power Management Demo"),0);

By responding to the PBT_APMQUERYSUSPEND message, an application can put off a suspend request from the operating system. The application will need to respond with a BROADCAST_QUERY_DENY, if the application cannot allow the system operations to be suspended. The Power Management API has other useful features to support automatic wake-up using the System Wake-up Events.

[Download Source]

Read about using Microsoft Visual C++ 2005 Express with Platform SDK.


Written by Sunil

2005.11.30 at 05:21 AM

Posted in .NET, Programming

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: