辩论赛计时器

2025-11-06 04:02:38

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、编译联接,运行。

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢