多语言展示
当前在线:1008今日阅读:23今日分享:25

辩论赛计时器

在学校里开辩论赛,要用到计时器,作为小规模的辩论赛再租专门的计时器,感觉就有点小题大做了,这里我做了一个小程序只需要一人专门计时,利用ppt投影到屏幕上就可以实现动态计时了。
工具/原料

VC++6.0

方法/步骤
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 defaultif(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

编译联接,运行。

推荐信息