今天同学要我帮他写一个控制计算机关机的软件,要求关机时间要自己设定。。
这个程序是基于MFC对话框的,就四行代码:添加在按钮确定下面
void COff_PCDlg::OnButton1() { // TODO: Add your control notification handler code here UpdateData(TRUE); CString str; str.Format("shutdown -s -t %d",3600*m_nOff); system(str);//设置关机时间 }
其实这里就是用了:system("shutdown -s -t 3600");//1小时后关机
//上面这个是设置关机的。其中m_nOff是编辑框关联的int型变量。
顺便写了一个取消关机代码:添加在按钮取消下面
void COff_PCDlg::OnButton2() { // TODO: Add your control notification handler code here system("shutdown -a");//取消关机 }