如何在 Windows Mobile 暂停时运行代码?
我想在 Windows Mobile PocketPC 正在(或似乎)被暂停时运行一些 C++ 代码。 我指的一个例子是 HTC Home 插件,它显示(除其他外)一个选项卡,其中 HTC 音频管理器可用于播放 mp3 文件。 当我按下开/关按钮时,显示屏变黑,但音频继续播放。 正如预期的那样,唯一重新打开的按钮是开/关按钮。
到目前为止,我尝试的是捕获硬件按钮按下(有效)并关闭视频显示(有效)。 这种方法不起作用的是,当(意外地)按下设备上的任意键时,视频显示就会打开。 我认为这不是 HTC 音频管理器中采用的方法。
我猜测需要一些低级 API 魔法才能实现此功能,或者播放音频的代码在某个中断级别运行,或者设备进入不同的挂起模式。
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.
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先看一下博客条目为了了解各种电源状态。 您基本上需要的是强制 ScreenOff 状态。 看一下 SetSystemPowerState 函数。
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.
我在 xda-developers 论坛 上找到了源代码解释了要做什么,并且它按照想法运作。 要点是:
RequestPowerNotifications(hMsgQueue) 请求电源通知, PBT_POWERINFOCHANGE | PBT_TRANSITION)
POWER_BROADCAST
类型的结构。PBT_TRANSITION
消息类型。 当设备关闭时,例如用户按下关闭按钮,pPwrBrodcast->SystemPowerState
字段将包含一个字符串“无人值守”。SystemIdleTimerReset() 告诉设备不要关闭
PowerPolicyNotify()
离开无人值守模式,使用ReleasePowerRequirement()
释放任何设备并使用StopPowerNotifications()
停止接收电源通知。I found sourcecode on the xda-developers forum that explains what to do, and it works as thought. The main points are:
PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE)
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.RequestPowerNotifications(hMsgQueue, PBT_POWERINFOCHANGE | PBT_TRANSITION)
POWER_BROADCAST
.PBT_TRANSITION
message type. The fieldpPwrBrodcast->SystemPowerState
then contains a string "unattended" when the device is shut off, e.g. by the user pressing the off buttonSystemIdleTimerReset()
to tell the device to not shut offPowerPolicyNotify()
to leave unattended mode, release any devices withReleasePowerRequirement()
and stop receiving power notifications withStopPowerNotifications()
.