防止 Pocket PC 设备在断电时关闭应用程序

发布于 2024-07-09 09:50:48 字数 48 浏览 8 评论 0原文

如何防止袖珍 PC 设备在按下电源按钮时从我的应用程序关闭? 我正在使用 C#。

How can I prevent the pocket PC device from shutting down from my application when the power button pressed? I am using C#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

つ可否回来 2024-07-16 09:50:48

您可以使用 Microsoft.WindowsCE.Form.MessageWindows 类来拦截电源按钮事件。 该解决方案不可移植,因为不同机器上的硬件密钥会有所不同。

不过,我建议您不要完全禁用电源。 看看我在另一个问题中的回答 此处。 您还可以使用 openetcf 轻松创建断电事件处理程序并注册唤醒事件。 您应该根据您想要实现的目标来实现应用程序逻辑,例如每隔一分钟唤醒一次以运行一个进程。

You could use the Microsoft.WindowsCE.Form.MessageWindows class to intercept the Power Button event. This solution will not be portable, as the hardware key will be different in different machines.

I recommend however that you don't disable power down completely. Have a look at my answer in another question here. You could also use openetcf to easily create power down events handlers and register wake up events. You should implement the application logic based on what you are trying to achieve, for instance wake up every one minute to run a process.

雨后彩虹 2024-07-16 09:50:48

您可以尝试更改设备“BLK1:”(黑光设备)的电源要求。 请注意,所有设备和操作系统版本或供应商特定扩展上的行为可能有所不同。

为此,您可以编写类似 : 的内容

    [DllImport("coredll")]
    private extern static IntPtr SetPowerRequirement(string pvDevice, int deviceState, 
                int deviceFlags, IntPtr pvSystemState, int stateFlags);

    [DllImport("coredll")]
    private extern static int ReleasePowerRequirement(IntPtr handle);

并这样称呼它 :

    IntPtr handle = SetPowerRequirement("BLK1:", 0 /* D0, Full On */, 1, IntPtr.Zero, 0);
    // Do something that requires the device to stay on ...
    ReleasePowerRequirement(handle);

但这通常不是一个好的做法,让设备长时间打开背光可能会大大降低其自主性。

You can try changing the power requirements for the device "BLK1:", which is the blacklight device. Be aware that the behavior may not be the same on all devices and version of the OS or Vendor specific Extensions.

To do this, you can write something like :

    [DllImport("coredll")]
    private extern static IntPtr SetPowerRequirement(string pvDevice, int deviceState, 
                int deviceFlags, IntPtr pvSystemState, int stateFlags);

    [DllImport("coredll")]
    private extern static int ReleasePowerRequirement(IntPtr handle);

and call it this way :

    IntPtr handle = SetPowerRequirement("BLK1:", 0 /* D0, Full On */, 1, IntPtr.Zero, 0);
    // Do something that requires the device to stay on ...
    ReleasePowerRequirement(handle);

But this is generally not a good practice, leaving a device with the backlight on for extended periods might reduce dramatically its autonomy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文