How to: Prevent Automatic Power Down
You can override the automatic suspend that occurs when no user input has occurred for a period of time. To prevent automatic power down, call the Windows CE SystemParametersInfo function for each of the three time-out values, SPI_GETBATTERYIDLETIMEOUT, SPI_GETEXTERNALIDLETIMEOUT, and SPI_GETWAKEUPIDLETIMEOUT, as shown in the following code. Your application must call the SystemIdleTimerReset function more frequently than any of the nonzero time-out values.
DWORD batIdle, acIdle, wakeUpIdle, shortestIdle;
TCHAR szOutput[200];
// Get the values.
SystemParametersInfo(SPI_GETBATTERYIDLETIMEOUT,0,&batIdle,0);
SystemParametersInfo(SPI_GETEXTERNALIDLETIMEOUT,0,&acIdle,0);
SystemParametersInfo(SPI_GETWAKEUPIDLETIMEOUT,0,&wakeUpIdle,0);
// Determine which is the lowest nonzero value.
shortestIdle=batIdle;
shortestIdle=((acIdle>0)&&(acIdle<shortestIdle)) ? acIdle : (((wakeUpIdle>0)&&(wakeUpIdle<shortestIdle)) ? wakeUpIdle : shortestIdle);
if (shortestIdle==0)
// If all values are zero, the device can never time out.
wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power Idle Timeout: %d\nWakeup Idle Timeout: %d\nThe device will not time out."),batIdle, acIdle, wakeUpIdle);
else
{
// Otherwise, you need to reset the idle timer more
// frequently than the lowest time-out value.
wsprintf(szOutput,_T("Battery Idle Timeout: %d\nAC Power
Idle Timeout: %d\nWakeup Idle Timeout: %d\nYou need to
call SystemIdleTimerReset at least every %d
sec"),batIdle, acIdle, wakeUpIdle, shortestIdle-1);
}
MessageBox(hWnd,szOutput,_T("Results"),MB_OK);
See Also
How to: Determine Available Memory
How to: Determine Battery Status
How to: Program Applications to Turn the Smartphone Backlight Off and On
Managing Variables, Stacks, and Heaps on Mobile Devices
System Out of Memory Dialog Box
Last updated on Friday, April 22, 2005
© 2005 Microsoft Corporation. All rights reserved.
Send feedback on this topic to the authors.