计时器:
long m_secondCount; 时间一秒增加1
CString m_secondCountStr; 画面显示字符串
CStatic m_time; 画面控制成员变量
m_secondCount=0,m_secondCountStr="";要先初始化
32位用
afx_msg void OnTimer(UINT nIDEvent);
64位用
afx_msg void OnTimer(UINT_PTR nIDEvent);
BEGIN_MESSAGE_MAP(CMFCApplication2Dlg, CDialogEx)
END_MESSAGE_MAP()
void CTimer::OnTimer(UINT nIDEvent)
{
this->m_secondCount++;
int hour = this->m_secondCount/3600 ;
int minute = (this->m_secondCount - hour*3600)/60 ;
int second = this->m_secondCount - hour*3600 - minute*60;
m_secondCountStr.Format("d:d:d", hour, minute, second);
m_time.SetWindowText(m_secondCountStr);
CDialog::OnTimer(nIDEvent);
}
// 开始计时
void CTimer::OnBnClickedButtonTimeStart()
{
this->SetTimer(1, // timer identifier
1000, // five-minute interval
NULL); // no timer callback
}
// 终止计时
void CTimer::OnBnClickedButtonTimeEnd()
{
this->KillTimer(1);
}
进度条:
m_IdcProgressRate 进度条成员变量
int rate = 80;
百分比
int nLower, nUpper;
m_IdcProgressRate.GetRange(nLower, nUpper);
m_IdcProgressRate.SetStep((nUpper - nLower)/10);
m_IdcProgressRate.SetPos(rate
);