Today to find out how to get the system from sleep, hibernate wake-up message, wrote an MFC dialog box program, posted part of the core code:
Wake-up message capture Lresult Csystemresumedmessagedlg::windowproc (UINT message, WPARAM WPARAM, LPARAM LPARAM) {//TODO: Add dedicated code here and/ or call the base class if (message = = Wm_powerbroadcast) && (WParam = = pbt_apmresumeautomatic)) {showsystemresumedtips ();// Prompt operation after capturing wake-up message}return cdialog::windowproc (message, WParam, LParam);}
Wake-up message capture reference: http://bbs.csdn.net/topics/320261685
Previously wrote a system to implement shutdown, restart, sleep, hibernate implementation, together with the code:
/*mysystemshutdown function: Implement system shutdown, restart parameters: Dwshutdownflag:ewx_shutdown shutdown ewx_reboot Restart Bforce: Enforce return value: True returned, otherwise return false*/ BOOL Mysystemshutdown (DWORD dwshutdownflag = Ewx_shutdown,bool BForce = FALSE) {HANDLE htoken; Token_privileges TKP; Get a token for this process. if (! OpenProcessToken (GetCurrentProcess (), Token_adjust_privileges | Token_query, &htoken)) return (FALSE); Get the LUID for the shutdown privilege. Lookupprivilegevalue (NULL, Se_shutdown_name, &TKP. Privileges[0]. LUID); Tkp. Privilegecount = 1; One privilege to set TKP. Privileges[0]. Attributes = se_privilege_enabled; Get The shutdown privilege for this process. AdjustTokenPrivileges (Htoken, FALSE, &TKP, 0, (ptoken_privileges) NULL, 0); if (GetLastError () = ERROR_SUCCESS) return FALSE; if (bForce) {Dwshutdownflag |= ewx_force;//forcibly terminates the process. When this flag is set, Windows does not send messages wm_queryendsession and wm_endsession messages to programs that are currently running in the system. This may cause the application to lose data. }if (! ExitWindowsEx (Dwshutdownflag, Shtdn_reason_major_operatingsystem | Shtdn_reason_minor_uPgrade | shtdn_reason_flag_planned)) return FALSE; return TRUE;} /*mysystemsleep function: To realize the system sleep, sleep function parameters: Bhibernate:true Sleep false Sleep return value: Return TRUE if successful, otherwise return False*/bool Mysystemsleep (BOOL Bhibernate = TRUE)//{hmodule hmodule = NULL; BOOL BRet = false;//boolean WINAPI setsuspendstate (//__in Boolean hibernate,//__in boolean Forcecriti cal,//__in BOOLEAN disablewakeevent//); typedef bool (WINAPI *psetsuspendstate) (BOOL hibernate,bool Forcecritica L,bool disablewakeevent) hmodule = LoadLibrary (_t ("PowrProf.dll")); if (hmodule) {Psetsuspendstate psetsuspendstate = Null;psetsuspendstate = (psetsuspendstate):: GetProcAddress (hmodule, "setsuspendstate");//Set backup file name function pointer if ( Psetsuspendstate = NULL) {BRet = Psetsuspendstate (bhibernate,0,0);} FreeLibrary (hmodule);} return bRet;}
Program Source Connection: http://download.csdn.net/detail/daiafei/8673013
Windows system shutdown, restart, sleep, hibernate, and wake-up messages