检查 Windows Mobile 设备是否空闲

发布于 2024-09-04 23:35:14 字数 617 浏览 4 评论 0原文

我有一个 Windows Mobile 5 程序(紧凑框架 3.5),我需要能够检测设备何时处于空闲状态。

现在我只是检查背光是否关闭。像这样:

[DllImport("coredll.dll", EntryPoint = "sleep", SetLastError = true)]
internal static extern void sleep(int dwMilliseconds);

....

//Get the current power state of the system
int winError = CoreDLL.GetSystemPowerState(systemStateName, out systemPowerStates);
if (winError == 0)
{
    //If the backlight is off, consider the state to be idle.
    if (systemStateName.ToString() == "backlightoff")
    {
        idle = true;
    }
}

我认为这可能已经接近了,但我想知道该设备是否真的没有被使用。

I have a windows mobile 5 program (compact framework 3.5) that I need to be able to detect when the device is idle.

Right now I am just checking to see if the backlight is off. Like this:

[DllImport("coredll.dll", EntryPoint = "sleep", SetLastError = true)]
internal static extern void sleep(int dwMilliseconds);

....

//Get the current power state of the system
int winError = CoreDLL.GetSystemPowerState(systemStateName, out systemPowerStates);
if (winError == 0)
{
    //If the backlight is off, consider the state to be idle.
    if (systemStateName.ToString() == "backlightoff")
    {
        idle = true;
    }
}

I think this may be getting close, but I would like to know if the device is truly not being used.

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

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

发布评论

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

评论(1

悲欢浪云 2024-09-11 23:35:14

您使用的是正确的函数,只需检查状态(按位标志):

if ((systemPowerStates & POWER_STATE_IDLE) == POWER_STATE_IDLE) {
  idle = true;
}

使用 POWER_STATE_IDLE = 0x00100000

编辑:要回答您的评论,请查看 RequestPowerNotification 函数。当电源状态更改时,您将收到 POWER_BROADCAST 消息。

You're using the right function, simply check for the states (which are bitwise flags):

if ((systemPowerStates & POWER_STATE_IDLE) == POWER_STATE_IDLE) {
  idle = true;
}

with POWER_STATE_IDLE = 0x00100000.

Edit: to answer your comment, look at the RequestPowerNotification function. You'll receive POWER_BROADCAST message when the power state changes.

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