Solved

How to re-start a timer in VC++?

Posted on 2000-03-11
14
494 Views
Last Modified: 2010-04-10
I need a timer in a VC++ application. I use the Timer Object (COM) to do this. To my surprise, once the timer is stopped, it cannot be restarted (using timer.SetEnabled(TRUE/FALSE) function).
Somebody tell me how to solve the problem?

Is this Timer Object in VC++ different from the timer in VB resource panel (there is no similar problem in VB application).
0
Comment
Question by:yzmao
  • 6
  • 5
  • 3
14 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 2608678
What sort of timer are you using?

You can use SetTimer() for a "windows timer" but this is only suitable for low resolution timing where accuracy is not crucial.

You can use the Multi-mediat timers for high'er resolution timing.  Look a timeSetEvent().
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2608893
->I need a timer in a VC++ application. I use the Timer Object (COM) to do this. To my surprise, once the timer is stopped, it cannot be restarted (using timer
========================
As nietod said,since you are in VC++,you'd better use SetTimer() to set a clock.Or use other high-resolution timer functions.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2608894
check:
timeGetTime()
QueryPerformanceCounter()QueryPerformanceFrequency()
GetTickCount()

Regards
W.Yinan
 
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:yzmao
ID: 2609639
I appreciate very much all your answers. So it is not that good if I use COM timer? -- There is a COM Timer in the resource library called Timer Object. I thought I can use it directly.

I don't need the accuracy -- what the timer needs to do is that, every half a second, it triggers an event to check the URL on the browser. But I need to stop the timer and restart it when necessary. I thought for this the Timer Object is the easiest.

I'll try follow your answer. Give me more instructions if you think it is necessary.

yzmao

0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609672
You can use settimer() if accuracy is not important.
In your winmain(),add SetTimer(hwnd,0,500,0);
And in your window message-procdure,add handler of WM_TIMER/Or OnTiemr() in MFC

bool bwork=TRUE;
case WM_TIMER:
if(bwork)
{
//do whatever you want and change bwork to FALSE to stop the timer
}

Feel free to ask.

Regards
W.Yinan
0
 
LVL 22

Expert Comment

by:nietod
ID: 2609681
You must have a window and a message loop to use a window timer.  Do you?

I think SetTimer had been my suggestion.  :-)
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609698
->I think SetTimer had been my suggestion.  :-)
===========================
So what ?

I'v withdrawed it...

Anyway , hope code above helpful

Regards
W.Yinan
0
 
LVL 22

Expert Comment

by:nietod
ID: 2609719
Usually, you don't submit an answer that was proposed by another expert in a comment.  It is the EE equivalent of plaugerism.  

For example, on the "last" question where you said the client was making the wrong type of project (it was looking for main()), I submitted a comment, since you had the right answer first.  In that case however, the client accepted my comment as an answer, even though it really was suggested by you first.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609729
:)
I like you ,nietod.
You are very frank.

Good luck and leading a happy life.

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2609734
->Usually, you don't submit an answer that was proposed by another expert in a comment.  It is the EE equivalent of plaugerism.  
=========================
Thanks.
I know this.
In this case I readed that  yzmao said "I'll try follow your answer. Give me more instructions if you think it is necessary."

So ,I think he has already chosen SetTimer() and need more.
Thus I do this.

Regards
W.Yinan
0
 

Author Comment

by:yzmao
ID: 2610118
It seems I caused some trouble. Sorry about that. I appreciate everyone's effort.

For this question, I may use my own method -- not turn off the timer, just set a flag. It works now.

But I will use your solutions sometime later.

Cheers,

yzmao
0
 
LVL 22

Expert Comment

by:nietod
ID: 2610223
>> It seems I caused some trouble.
Not at all.    

wyn's the trouble maker.   :-)    Not really.

>> not turn off the timer, just set a flag.
>> It works now.
I don't understand.

You can stop the windows timer with KillTimer().
0
 

Author Comment

by:yzmao
ID: 2610750
As I said, there is a COM component called Timer Object that we can use in a VC++ application. But once it is turned off (by calling SetEnabled(FALSE), it could not be turned on again -- that is the original question.

See, if I didn't turn it off but use a flag to invoke a certain procedure, then I can get the desired result. It is working now.

Thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2611820
I see.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question