Check to see if a Windows Mobile Device is Idle

断了今生、忘了曾经 提交于 2019-12-02 00:01:00

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2999465/check-to-see-if-a-windows-mobile-device-is-idle

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