15,979
社区成员
发帖
与我相关
我的任务
分享
#include<afxwin.h>
class MyShutDown:public CWinApp
{
public:
BOOL InitInstance();
};
class MyDialog:public CDialog
{
public:
MyDialog(CWnd* pParentWnd=NULL);
~MyDialog();
int SetTime1;
int nNum;
CString str;
protected:
virtual BOOL OnInitDialog();
afx_msg void OnStart();
afx_msg void OnTimer(UINT nIDEvent);
DECLARE_MESSAGE_MAP()
};
#include"ShutDown.h"
#include"resource.h"
#define IDT_TIMER1 101
MyShutDown theApp;
BOOL MyShutDown::InitInstance()
{
MyDialog dlg;
m_pMainWnd=&dlg;
dlg.DoModal();
return FALSE;
}
MyDialog::MyDialog(CWnd* pParentWnd):CDialog(IDD_DIALOG1,pParentWnd)
{
SetTime1=FALSE;
nNum=0;
};
MyDialog::~MyDialog()
{};
BEGIN_MESSAGE_MAP(MyDialog,CDialog)
ON_BN_CLICKED(IDC_START,OnStart)
ON_WM_TIMER()
END_MESSAGE_MAP()
BOOL MyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(theApp.LoadIcon(IDI_ICON1),FALSE);
return TRUE;
}
void MyDialog::OnStart()
{
GetDlgItem(IDC_EDIT1)->GetWindowText(str); //获取编辑框字符串
if(str.IsEmpty()) //判断字符串是否为空
{
MessageBox("请输入关机时间!");
return;
}
if(!SetTime1)
{
::SetTimer(m_hWnd,IDT_TIMER1,1000,NULL);
SetTime1=TRUE;
}
else
{
::KillTimer(m_hWnd,IDT_TIMER1);
SetTime1=FALSE;
}
}
void MyDialog::OnTimer(UINT nIDEvent)
{
nNum++;
int a;
a=atoi(str)-1;
GetDlgItem(IDC_EDIT1)->SetWindowText((char*)a);
if(atoi(str)==nNum)
ExitWindowsEx(EWX_SHUTDOWN,0);
}