Check if your Windows Mobile device is in standby mode

I have a Windows Mobile 5 program (compact framework 3.5) that should be able to detect when the device is down.

Now I'm just checking 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 come close, but I would like to know if the device is really not in use.

+3
source share
1 answer

You are using the correct function, just check the states (which are bitwise flags):

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

a POWER_STATE_IDLE = 0x00100000.

:, , RequestPowerNotification. POWER_BROADCAST.

+1

Source: https://habr.com/ru/post/1749062/


All Articles