Home » U++ Library support » U++ Callbacks and Timers » how to use timer id? and how to kill a timer
Re: how to use timer id? [message #27501 is a reply to message #27500] |
Wed, 21 July 2010 12:54 |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
This code opens a window and uses a Thread to wait 5 seconds before starting window timer counting up:
class MyWindow : public TopWindow
{
typedef MyWindow CLASSNAME;
int count;
public:
MyWindow() : count(0) {}
virtual void Paint(Draw& w) { TopWindow::Paint(w); w.DrawText(4, 4, AsString(count)); }
void Count() { ++count; Refresh(); }
void CreateCounter(int interval) { SetTimeCallback(interval, THISBACK(Count)); }
};
void MyThread(Callback1<int> TimerCB)
{
for (int i = 0; i < 50; ++i) {
if (Thread::IsShutdownThreads())
return;
Sleep(100);
}
TimerCB(-1000);
}
GUI_APP_MAIN
{
MyWindow wnd;
Thread thrd;
wnd.SetRect(RectC(0, 0, 200, 200));
wnd.CenterScreen();
thrd.Run(callback1(MyThread, callback(&wnd, &MyWindow::CreateCounter)));
wnd.Run();
Thread::ShutdownThreads();
}
You'll need to give more information about what you're trying to achive if you need anything more complex than this.
[Updated on: Wed, 21 July 2010 12:56] Report message to a moderator
|
|
|
|
|
how to use timer id? and how to kill a timer
By: bonami on Tue, 20 July 2010 10:03
|
|
|
Re: how to use timer id?
By: mrjt on Wed, 21 July 2010 10:46
|
|
|
Re: how to use timer id?
By: bonami on Wed, 21 July 2010 11:28
|
|
|
Re: how to use timer id?
By: mrjt on Wed, 21 July 2010 12:54
|
|
|
Re: how to use timer id?
By: bonami on Thu, 22 July 2010 04:09
|
|
|
Re: how to use timer id?
By: mrjt on Thu, 22 July 2010 10:58
|
|
|
Re: how to use timer id?
By: bonami on Thu, 22 July 2010 11:32
|
|
|
Re: how to use timer id?
By: mrjt on Thu, 22 July 2010 12:10
|
|
|
Re: how to use timer id?
By: bonami on Fri, 23 July 2010 04:28
|
|
|
Re: how to use timer id?
By: mrjt on Fri, 23 July 2010 11:32
|
|
|
Re: how to use timer id?
By: bonami on Mon, 26 July 2010 04:16
|
Goto Forum:
Current Time: Fri May 03 18:20:46 CEST 2024
Total time taken to generate the page: 0.02250 seconds
|