From: Dave on 31 Jan 2007 17:43 I'm having trouble figuring out how to create and use a timer in Windows when you don't want to build an actual windowed application, but rather are making a console app. All examples I've found so tie timers directly into the windows. For Example: http://msdn2.microsoft.com/en-us/library/microsoft.win32.systemevents.createtimer(VS.80).aspx Any suggestions? PS I am NOT using dot net
From: Bertel Brander on 31 Jan 2007 18:36 Dave skrev: > I'm having trouble figuring out how to create and use a timer in > Windows when you don't want to build an actual windowed application, > but rather are making a console app. All examples I've found so tie > timers directly into the windows. > > For Example: > > http://msdn2.microsoft.com/en-us/library/microsoft.win32.systemevents.createtimer(VS.80).aspx > > Any suggestions? You can use normal windows timers in consols apps: #include <windows.h> #include <iostream> int main() { SetTimer(0, 1024, 1000, 0); SetTimer(0, 1025, 750, 0); MSG Message; while(GetMessage(&Message, 0, 0, 0)) { if(Message.message == WM_TIMER) { std::cout << "Timer" << std::endl; } } } But you need to have a message loop, as above. I we know more of what you want to do, we could probably give you better advice. -- Just another homepage: http://damb.dk But it's mine - Bertel
From: Dave on 31 Jan 2007 19:40 Certainly, thanks for the help! I have an application that itself owns numerous classes. I'm implementing a state pattern, where each class is a state. These state objects are owned in turn by a state manager, who is instantiated by main. Some events cause timers to start. When some timers expire they cause state transitions. Sometimes I will need to stop the timers early. Other times I'll need to 'tick' a value and reschedule them. Is there any way I can simply specify a function handler to be called when the timer expires? I really don't want to have to have my main handle all possible timer events as they are elements of the states and not main. here http://msdn2.microsoft.com/en-us/library/ms644901.aspx they have an example that doesn't need the GetMessage loop (very last example) though my attempts to recreate it have failed and I believe it's because I am not registering a window in the SetTimer command. another question: How do I stop a timer? Would that just be 'KillTimer'? How about rescheduling the timer? Is that just another SetTimer call? On Jan 31, 6:36 pm, Bertel Brander <ber...(a)post4.tele.dk> wrote: > Dave skrev: > > > I'm having trouble figuring out how to create and use a timer in > > Windows when you don't want to build an actual windowed application, > > but rather are making a console app. All examples I've found so tie > > timers directly into the windows. > > > For Example: > > >http://msdn2.microsoft.com/en-us/library/microsoft.win32.systemevents... > > > Any suggestions? > > You can use normal windows timers in consols apps: > > #include <windows.h> > #include <iostream> > > int main() > { > SetTimer(0, 1024, 1000, 0); > SetTimer(0, 1025, 750, 0); > MSG Message; > while(GetMessage(&Message, 0, 0, 0)) > { > if(Message.message == WM_TIMER) > { > std::cout << "Timer" << std::endl; > } > } > > } > > But you need to have a message loop, as above. > I we know more of what you want to do, we could probably give > you better advice. > > -- > Just another homepage:http://damb.dk > But it's mine - Bertel
From: Grzegorz Wróbel on 31 Jan 2007 20:01 Dave wrote: > Certainly, thanks for the help! > > I have an application that itself owns numerous classes. I'm > implementing a state pattern, where each class is a state. These > state objects are owned in turn by a state manager, who is > instantiated by main. > > Some events cause timers to start. When some timers expire they cause > state transitions. Sometimes I will need to stop the timers early. > Other times I'll need to 'tick' a value and reschedule them. > > Is there any way I can simply specify a function handler to be called > when the timer expires? I really don't want to have to have my main > handle all possible timer events as they are elements of the states > and not main. > > here http://msdn2.microsoft.com/en-us/library/ms644901.aspx they have > an example that doesn't need the GetMessage loop (very last example) > though my attempts to recreate it have failed and I believe it's > because I am not registering a window in the SetTimer command. > > another question: How do I stop a timer? Would that just be > 'KillTimer'? How about rescheduling the timer? Is that just another > SetTimer call? I think you need SetWaitableTimer()/CancelWaitableTimer(). -- Grzegorz Wr�bel http://www.4neurons.com/ 677265676F727940346E6575726F6E732E636F6D
From: JD on 31 Jan 2007 19:52 One technique I've used is to run an imitation timer thread that does a waitforsingleobject with a timeout. Sort of like: (initialization and errors ignored) HANDLE eventTimer; while (true) { WaitForSingleObject(eventTimer, 250); <timer has fired> } Mike "Dave" <davechandler(a)gmail.com> wrote in message news:1170283433.753622.132120(a)h3g2000cwc.googlegroups.com... > I'm having trouble figuring out how to create and use a timer in > Windows when you don't want to build an actual windowed application, > but rather are making a console app. All examples I've found so tie > timers directly into the windows. > > For Example: > > http://msdn2.microsoft.com/en-us/library/microsoft.win32.systemevents.createtimer(VS.80).aspx > > Any suggestions? > > PS I am NOT using dot net >
|
Next
|
Last
Pages: 1 2 3 Prev: STL stream - precision() and setprecision() Next: Color in console output? |