请教在pocket pc电源设置关闭设备时间到了后,触发的系统消息是什么
我在开发中遇到了一个问题。在cmwap通讯中,我每个1分钟向服务器发送一个同步消息,如果我5分钟没有与服务器同步,服务器就认为我断开了,我发现在电源设置中设置关闭设备时间后,等到时间到是,关闭了设备,同时系统也把timer给关掉了,我无法向服务发送消息了,请问我能在应用中屏蔽掉这个消息吗?如何解决?
[解决办法]
通过RequestPowerNotifications来设置对Power状态的通知。
MSGQUEUEOPTIONS Msgqueueop;
Msgqueueop.dwSize = sizeof(MSGQUEUEOPTIONS);
Msgqueueop.dwMaxMessages = 0;
Msgqueueop.bReadAccess = TRUE;
Msgqueueop.cbMaxMessage = MAX_SIZE;
Msgqueueop.dwFlags = MSGQUEUE_NOPRECOMMIT;
HANDLE m_hMsgQueue = CreateMsgQueue(NULL,&Msgqueueop);
//HANDLE hr =
RequestPowerNotifications(m_hMsgQueue, PBT_TRANSITION); //POWER_NOTIFY_ALL
然后创建一个线程去监听Power改变的消息
DWORD ThreadID;
HANDLE m_hthread = CreateThread(NULL, 0,BroadcastQueueProcess,(PVOID)NULL,0,&ThreadID);
线程函数:
DWORD WINAPI BroadcastQueueProcess(PVOID pvParam)
{
HANDLE hMsgQueue = threadpara-> hMsgQueue;
WCHAR cMsg[MAX_SIZE];
DWORD dwByteRead, dwFlag;
while(TRUE)
{
DWORD dw = WaitForSingleObject(hMsgQueue, INFINITE);
switch(dw)
{
case WAIT_OBJECT_0:
{
//BOOL br =
ReadMsgQueue(hMsgQueue,(LPVOID)cMsg,MAX_SIZE, &dwByteRead,INFINITE,&dwFlag);
POWER_BROADCAST *PB = (POWER_BROADCAST*)cMsg;
if(!wcscmp(PB-> SystemPowerState, L "unattended "))
{
}
else if(!wcscmp(PB-> SystemPowerState, L "suspend "))
{
}
else if(!wcscmp(PB-> SystemPowerState, L "on "))
{
}
}
default:
break;
}
}
return 0;
}
代码不全,自己整理整理