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()?