-
April 20th, 2006, 06:19 AM
#1
Starting Timer In Vc++
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
-
April 20th, 2006, 06:21 AM
#2
Re: Starting Timer In Vc++
Look at ::SetTimer().
Cheers
-
April 20th, 2006, 06:23 AM
#3
Re: Starting Timer In Vc++
use function
SetTimer() and handle the message WM_TIMER in your code.
-
April 20th, 2006, 06:35 AM
#4
Re: Starting Timer In Vc++
Where Can I Find The Timer Control? Its Not Present In The Toolbar That Is Displayed Normalyy. Should I Add The Timer Control Separately
-
April 20th, 2006, 06:37 AM
#5
Re: Starting Timer In Vc++
The timer is not a control. . it's a function as humptydumpty said.. .
-
April 20th, 2006, 06:54 AM
#6
Re: Starting Timer In Vc++
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.
-
April 20th, 2006, 06:54 AM
#7
Re: Starting Timer In Vc++
Take a look at this for reference.
-
April 20th, 2006, 06:56 AM
#8
Re: Starting Timer In Vc++
Originally Posted by sudeep_br3
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.
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.
-
April 20th, 2006, 07:00 AM
#9
Re: Starting Timer In Vc++
Just a side issue, even though your code will work, as Ejaz mentioned, you don't need the calls to UpdateData(...)
Regards
I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)
-
April 20th, 2006, 07:06 AM
#10
Re: Starting Timer In Vc++
Originally Posted by sudeep_br3
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.
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?
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.
-
April 20th, 2006, 07:08 AM
#11
Re: Starting Timer In Vc++
the code is not working . can some one give me the correct and complete code
-
April 20th, 2006, 07:10 AM
#12
Re: Starting Timer In Vc++
sir this procedure seems to be correct but can u give me the code?
-
April 20th, 2006, 07:14 AM
#13
Re: Starting Timer In Vc++
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?
I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)
-
April 20th, 2006, 07:15 AM
#14
Re: Starting Timer In Vc++
that is where i got this code from but its not working i mean nothing is apearing in edit control
-
April 20th, 2006, 07:19 AM
#15
Re: Starting Timer In Vc++
Have you done UpdateData()?
I don't mind that you think slowly but I do mind that you are publishing faster than you think. Wolfgang Pauli, physicist, Nobel laureate (1900-1958)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|