我有一个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;
}
}
我认为这可能会越来越近,但我想知道该设备是否真的没有被使用。
答案 0 :(得分:1)
您正在使用正确的函数,只需检查状态(按位标志):
if ((systemPowerStates & POWER_STATE_IDLE) == POWER_STATE_IDLE) {
idle = true;
}
POWER_STATE_IDLE = 0x00100000
。
编辑:回答您的评论,查看RequestPowerNotification功能。当电源状态发生变化时,您将收到POWER_BROADCAST消息。