3 回答

TA貢獻1772條經驗 獲得超8個贊
我通過USB連接的硬件設備遇到了這樣的問題。XP / Vista會在其中途進入睡眠/休眠狀態。很好,您說,當它恢復時它就可以繼續。如果硬件仍然連接!用戶習慣于在需要時拔出電纜。
您需要處理XP和Vista
在XP下,捕獲WM_POWERBROADCAST并查找PBT_APMQUERYSUSPEND wparam。
// See if bit 1 is set, this means that you can send a deny while we are busy
if (message.LParam & 0x1)
{
// send the deny message
return BROADCAST_QUERY_DENY;
} // if
else
{
return TRUE;
} // else
在Vista下使用SetThreadExecutionState像這樣
// try this for vista, it will fail on XP
if (SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED) == NULL)
{
// try XP variant as well just to make sure
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
} // if
當您完成應用后,將其恢復為正常
// set state back to normal
- 3 回答
- 0 關注
- 1243 瀏覽
添加回答
舉報