winapi - Prevent windows from going into sleep when my program is running? -
i have stop windows going sleep when program running.
and don't want prevent sleep-timer, want cancel sleep-event if press sleep-button or in other way actively tell computer sleep. therefore setthreadexecutionstate not enough.
or...i don't have prevent sleep completely, delay 5-10sec allow program finish task.
(i know bad program behavior it's personal use.)
i had problem hardware device connected via usb. xp /vista sleep/hibernate right in middle of ... great say, when resumes can continue. if hardware still connected!!! users have habit of pulling cables out whenever feel it.
you need handle xp , vista
under xp trap wm_powerbroadcast , pbt_apmquerysuspend wparam.
// see if bit 1 set, means can send deny while busy if (message.lparam & 0x1) { // send deny message return broadcast_query_deny; } // if else { return true; } // else
under vista use setthreadexecutionstate this
// try vista, fail on xp if (setthreadexecutionstate(es_continuous | es_system_required | es_awaymode_required) == null) { // try xp variant make sure setthreadexecutionstate(es_continuous | es_system_required); } // if
and when app has finished set normal
// set state normal setthreadexecutionstate(es_continuous);
Comments
Post a Comment