如何在挂起时在Windows Mobile上运行代码?

时间:2021-06-02 02:23:48

I'd like to run some C++ code while the Windows Mobile PocketPC is (or seems) being suspended. An example what I mean is the HTC Home plugin that shows (among others) a tab where the HTC Audio Manager can be used to play back mp3 files. When I press the on/off button, the display goes black, but the audio keeps playing. The only button to switch back on is the on/off button, as expected.

我希望运行一些C ++代码,而Windows Mobile PocketPC(或似乎)被暂停。我的意思是一个例子是HTC Home插件,它显示了一个选项卡,其中HTC Audio Manager可以用来播放mp3文件。按下开/关按钮时,显示屏变黑,但音频仍在播放。正如预期的那样,唯一可以重新打开的按钮是开/关按钮。

What I tried so far is to capture hardware button presses (works) and switch off the video display (works). What doesn't work with this approach is that when (accidentally) pressing any key on the device, the video display is switched on. I think this isn't the approach taken in the HTC Audio Manager.

到目前为止我尝试捕获硬件按钮(工作)并关闭视频显示(工作)。无法使用此方法的是,当(意外地)按下设备上的任何键时,视频显示器将打开。我认为这不是HTC Audio Manager采用的方法。

I'm guessing on some low-level API magic for this to work, or that the code to play back audio runs at some interrupt level, or the device goes into a different suspend mode.

我猜测一些低级别的API魔法可以使用,或者播放音频的代码在某个中断级别运行,或者设备进入不同的挂起模式。

2 个解决方案

#1


4  

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

我在xda-developers论坛上找到了解释该做什么的源代码,并且它按照思路工作。要点是:

  • Set the device to send a notification when going into "unattended" mode. This is done with PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE)
  • 将设备设置为在进入“无人值守”模式时发送通知。这是通过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.
  • 对于无人参与模式下所需的每台设备,请调用SetPowerRequirement(L“gpd0:”,D0,POWER_NAME | POWER_FORCE,NULL,NULL); “gpd0:”设备是GPS中间驱动程序;用您需要的任何设备替换或复制电话,例如“wav1:”用于音频,“dsk1:”用于存储卡,“com1:”用于串行端口1。

  • Create a message queue and request power notifications using RequestPowerNotifications(hMsgQueue, PBT_POWERINFOCHANGE | PBT_TRANSITION)
  • 使用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.
  • 每次发送电源通知时,消息队列都会填充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
  • 查找PBT_TRANSITION消息类型。然后,当设备关闭时,字段pPwrBrodcast-> SystemPowerState包含字符串“无人值守”,例如,用户按下关闭按钮

  • In this transition, just call SystemIdleTimerReset() to tell the device to not shut off
  • 在此转换中,只需调用SystemIdleTimerReset()来告诉设备不要关闭

  • 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().
  • 关闭时,调用PowerPolicyNotify()以退出无人参与模式,释放具有ReleasePowerRequirement()的所有设备并停止使用StopPowerNotifications()接收电源通知。

#2


1  

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.

首先看看这篇博客文章,以了解各种电源状态。你基本上需要的是强制ScreenOff状态。看看SetSystemPowerState函数。

#1


4  

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

我在xda-developers论坛上找到了解释该做什么的源代码,并且它按照思路工作。要点是:

  • Set the device to send a notification when going into "unattended" mode. This is done with PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE)
  • 将设备设置为在进入“无人值守”模式时发送通知。这是通过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.
  • 对于无人参与模式下所需的每台设备,请调用SetPowerRequirement(L“gpd0:”,D0,POWER_NAME | POWER_FORCE,NULL,NULL); “gpd0:”设备是GPS中间驱动程序;用您需要的任何设备替换或复制电话,例如“wav1:”用于音频,“dsk1:”用于存储卡,“com1:”用于串行端口1。

  • Create a message queue and request power notifications using RequestPowerNotifications(hMsgQueue, PBT_POWERINFOCHANGE | PBT_TRANSITION)
  • 使用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.
  • 每次发送电源通知时,消息队列都会填充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
  • 查找PBT_TRANSITION消息类型。然后,当设备关闭时,字段pPwrBrodcast-> SystemPowerState包含字符串“无人值守”,例如,用户按下关闭按钮

  • In this transition, just call SystemIdleTimerReset() to tell the device to not shut off
  • 在此转换中,只需调用SystemIdleTimerReset()来告诉设备不要关闭

  • 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().
  • 关闭时,调用PowerPolicyNotify()以退出无人参与模式,释放具有ReleasePowerRequirement()的所有设备并停止使用StopPowerNotifications()接收电源通知。

#2


1  

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.

首先看看这篇博客文章,以了解各种电源状态。你基本上需要的是强制ScreenOff状态。看看SetSystemPowerState函数。