1. New Project
2. Add 3 control button IDs of Idc_btclose Idc_btreset idc_btlogout respectively "Turn Off computer", "Restart", "Log Off Computer"
3. Set permissions to implement shutdown in OnInitDialog
Static HANDLE htoken;static token_privileges tp;static LUID luid;openprocesstoken (getcurrentprocess (), TOKEN_ADJUST_ privileges| Token_query,&htoken); Lookupprivilegevalue (NULL,SE_SHUTDOWN_NAME,&LUID); tp. Privilegecount = 1;tp. Privileges[0]. Luid = Luid;tp. Privileges[0]. Attributes = se_privilege_enabled; AdjustTokenPrivileges (Htoken,false,&tp,sizeof (token_privileges), null,null);
4. "Turn Off Computer" button implementation function
void Cshutdowndlg::onbnclickedbtclose () {//TODO: Add control Notification Handler code ExitWindowsEx (ewx_poweroff,0) here; MessageBox ("hahaha", "This you all Believe");}
"Restart" button implementation function
void Cshutdowndlg::onbnclickedbtreset () {//TODO: Add control Notification Handler code ExitWindowsEx (ewx_reboot,0) here; MessageBox ("hahaha", "This you all Believe");}
"Log Off Computer" button implementation function
void Cshutdowndlg::onbnclickedbtlogout () {//TODO: Add control Notification Handler code ExitWindowsEx (ewx_logoff,0) here; MessageBox ("hahaha", "This you all Believe");}
Implementing a computer restart