辩论赛计时器
1、打开VC++6.0,点击“新建”按钮,点击MFC Appwizard,在工程名称一栏输入想要的工程名称,在位置一栏输入想保存的路径,然后点击确定:

2、打开对话框,在对话框上面添加控件如图所示:

3、为计时器添加
count count2,ksorzt,ksorzt2,minute,second,minute2,second2几个成员变量如图,并在构造函数中初始化:


4、为对话框中的控件添加成员变量,如图所示:

5、在:OnInitDialog()中添加代码:(改变编辑框中的字体)

6、添加OnTimer()消息处理函数:并添加如下代码:
void CJssDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(ksorzt)
{
if(count>0)
{
minute=count/60;
second=count%60;
CString str;
str.Format("%d"":""%d",minute,second);
m_strTime=str;
UpdateData(false);
--count;
}
else
{
m_strTime="时间到!";
UpdateData(false);
}
}
if(ksorzt2)
{
if(count2>0)
{
minute2=count2/60;
second2=count2%60;
CString str2;
str2.Format("%d"":""%d",minute2,second2);
m_strTime2=str2;
UpdateData(false);
--count2;
}
else
{
m_strTime2="时间到!";
UpdateData(false);
}
}
CDialog::OnTimer(nIDEvent);
}
7、为正方和反方的开始和暂停按钮添加消息响应函数:
void CJssDlg::OnButton1()
{
// TODO: Add your control notification handler code here
ksorzt=true;
}
void CJssDlg::OnButton2()
{
// TODO: Add your control notification handler code here
ksorzt=false;
}
void CJssDlg::OnButton3()
{
// TODO: Add your control notification handler code here
ksorzt2=true;
}
void CJssDlg::OnButton4()
{
// TODO: Add your control notification handler code here
ksorzt2=false;
}
其中button1和button2为正方的开始和暂停按钮,button3和button4为反方的开始和暂停按钮
8、为正方和反方的从新开始按钮添加消息相应函数:
void CJssDlg::OnButton5()
{
// TODO: Add your control notification handler code here
ksorzt=false;
count=600;
m_strTime="10:0";
UpdateData(false);
}
void CJssDlg::OnButton6()
{
// TODO: Add your control notification handler code here
ksorzt2=false;
count2=600;
m_strTime2="10:0";
UpdateData(false);
}
9、编译联接,运行。