How can I run code on Windows Mobile while being suspended?

眉间皱痕 提交于 2019-11-29 08:45:23

I found sourcecode on the xda-developers forum that explains what to do, and it works as thought. The main points are:

  • Set the device to send a notification when going into "unattended" mode. This is done with PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE)
  • For every device that you need during unattended mode, call SetPowerRequirement(L"gpd0:", D0, POWER_NAME|POWER_FORCE, NULL, NULL); The "gpd0:" device is the GPS Intermediate driver; replace or duplicate call with any device you need, e.g. "wav1:" for audio, "dsk1:" for memory card or "com1:" for serial port 1.
  • Create a message queue and request power notifications using RequestPowerNotifications(hMsgQueue, PBT_POWERINFOCHANGE | PBT_TRANSITION)
  • Every time a power notification is sent, the message queue is filled with a struct of type POWER_BROADCAST.
  • Look for PBT_TRANSITION message type. The field pPwrBrodcast->SystemPowerState then contains a string "unattended" when the device is shut off, e.g. by the user pressing the off button
  • In this transition, just call SystemIdleTimerReset() to tell the device to not shut off
  • Repeat when the transition occurs again
  • When shutting down, call PowerPolicyNotify() to leave unattended mode, release any devices with ReleasePowerRequirement() and stop receiving power notifications with StopPowerNotifications().

At first have a look at this blog entry in order to understand the various power states. What you basically need is to force the ScreenOff state. Have a look at the SetSystemPowerState function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!