Solved

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

Posted on 2000-03-11
14
502 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 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
Industry Leaders: 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

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

726 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