Click to See Complete Forum and Search --> : Problem with displaying time with Timers


Shahzad
April 11th, 1999, 01:43 AM
I have dialog box with several edit controls, one of which displays time after each second. The problem is that when it displays time, each second the other edit boxes value is also repainted because I have used UpdateData(false) statement in OnTimer fuction. So when I write in these edit boxes, it display old values each second, and I cann't write in them. Here is my code in OnTimer() function.

void CCMSTesterDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default

int hr,min,sec;
m_Time=COleDateTime::GetCurrentTime();
hr =m_Time.GetHour();
min = m_Time.GetMinute();
sec = m_Time.GetSecond();

m_Time.SetTime(hr,min,sec);

UpdateData(false); // this statement updates other controls as well, and
// i write in them, each second they display the old
// values again. so I can't write in them!
CDialog::OnTimer(nIDEvent);

}
Please let know how can I display the continous time, without updating other Edit controls.

April 11th, 1999, 03:25 AM
Create a CString object and use the "Format" function to write your time values to the string. Something like:

CString TimeVals;
TimeVals.Format("%02d:%02d:%02d", hr, min, sec);

You can then use SetDlgItemText to update your edit control.

setDlgItemText(IDC_TIMEVALS, (LPCTSTR)TimeVals);

Hope this helps.