[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2000-03-11
14
Medium Priority
?
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 300 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

650 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