2010-06-08 123 views
3

我有一个windows mobile 5程序(compact framework 3.5),我需要能够检测到设备空闲时的情况。检查Windows Mobile设备是否空闲

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

[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; 
    } 
} 

我想,这可能会越来越接近,但我想知道,如果是真正不使用的设备。

回答

1

你使用正确的功能,只需检查状态(这是按位标志):

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

POWER_STATE_IDLE = 0x00100000

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

+0

这很好。 (它没有解决我的问题,但它的工作。)我想我将不得不去POWER_STATE_USERIDLE(0x01000000)。但是,经过很长的空闲时间后,我得到0x02000000,这在pm.h中没有定义。 – Vaccano 2010-06-08 17:40:47

+0

我仍然坚持这一点。我使用了您指定的方法,但POWER_STATE_IDLE从未设置。那是因为我们使用定时器来检查电源状态是否空闲?这是否阻止它进入闲置状态?如果是这样,如果检查导致它不闲置,你怎么能做到这一点? (一旦你检查你是否失去了闲置状态。) – Vaccano 2010-06-14 20:57:49

+0

甜!谢谢。我会试试看。 – Vaccano 2010-06-14 21:50:42