i want to start a timer when the dialog box is loaded. the timer should be displayed in a edit control. timer shud start in this format
00:00:00
eg:- 00:00:03
it shud go on till the dialog box is closed. pls let me know how this can be done
Printable View
i want to start a timer when the dialog box is loaded. the timer should be displayed in a edit control. timer shud start in this format
00:00:00
eg:- 00:00:03
it shud go on till the dialog box is closed. pls let me know how this can be done
Look at ::SetTimer().
Cheers
use function
SetTimer() and handle the message WM_TIMER in your code.
Where Can I Find The Timer Control? Its Not Present In The Toolbar That Is Displayed Normalyy. Should I Add The Timer Control Separately
The timer is not a control. . it's a function as humptydumpty said.. .
i have put the code as follows
BOOL CStatusDlg::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData( TRUE );
m_TIME = SetTimer(1, 2000, 0);
UpdateData( FALSE );
return TRUE;
}
is this rite? m_TIME is a member variable of a edit control. i gave this but nothing is displayed in edit control. i want the timer to start of as soon as the dialog box is loaded.
Take a look at this for reference.
That looks fine, but you also need to handle WM_TIMER, as suggested by HD. You can look into the above link for reference that how you can do that.Quote:
Originally Posted by sudeep_br3
Just a side issue, even though your code will work, as Ejaz mentioned, you don't need the calls to UpdateData(...)
Regards
No. Look at the documentation for the return value of SetTimer. Why do you think that would be what you'd want in the edit control?Quote:
Originally Posted by sudeep_br3
Assuming you're counting elapsed seconds,
Create a member variable of type CTime in your dialog.
In OnInitDialog initialize it using CTime::GetCurrentTime;
In OnInitDialog set a timer to go off every second.
Handle the WM_TIMER message;
Create a new CTime object initialized with CTime::GetCurrentTime.
Subtract the first CTime that's a member of your dialog class from the new one you created in OnTimer. The result is a CTimeSpan.
Use GetTotalSeconds of whatever methods you feel appropriate from your CTimeSpan object.
Format them appropriately and use SetWindowText to put the value in your edit control.
the code is not working . can some one give me the correct and complete code
sir this procedure seems to be correct but can u give me the code?
You have all the steps in this thread to help you on your way. Have you looked at the link golanshahar gave you? I remember msdn giving a few examples... have you also looked on MSDN regarding CTime and CTimeSpan?
that is where i got this code from but its not working i mean nothing is apearing in edit control
Have you done UpdateData()?
BOOL CStatusDlg::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData( TRUE );
m_TIME = SetTimer(1, 2000, 0);
UpdateData( FALSE );
return TRUE;
}
this is the code i have put. even wheni removed updatedata() it dint work
just try to Find in MSDN for WM_TIMER and there they have given sample program and other things in detail hope this will helps you.
If you're still using the code you posted, it can't possibly do what you want. I gave you the steps you need to follow. Give them a try.Quote:
Originally Posted by sudeep_br3
when the dialog loaded you settime-> SetTimer(1000,id);
void classname::OnTimer(UINT nIDEvent)
{
//CFormView::OnTimer(nIDEvent);
SYSTEMTIME now ;
GetSystemTime(&now) ;
COleDateTime dt_now(0, 0, 0, now.wHour, now.wMinute, now.wSecond) ;
COleDateTime diff(0, 0, 0, 5, 30, 0) ;
dt_now = dt_now + diff ;
int nHr ;
nHr = dt_now.GetHour() ;
CString strTimeofDay ;
/*strTimeofDay = "AM" ;
if(nHr > 12)
{
nHr -= 12 ;
strTimeofDay = "PM" ;
}*/
m_dtTime = dt_now ;
m_strTime.Format("%02d:%02d:%02d %s",
nHr,
dt_now.GetMinute(),
dt_now.GetSecond(),
strTimeofDay) ;
SetDlgItemText(Text_box id, m_strTime) ;
}
you will get the result - 00:00:00
u havent declared the two variables m_strTime and m_dtTime. what type r these two? i want to display timer value in edit control whose member variable is m_SPACE. which among the two is the member variable for edit control.
Quote:
Originally Posted by sudeep_br3
hai friend m_strtime->CString m_strtime;
m_dttime-> ColeDateTime m_dttime;
m_space=m_strtime;//m_space is your varibale for text box
updatedata(0);
if there any dought quote me
got the solution thank you