我通过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 XPif (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