Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
mrjt is currently offline  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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Time callbacks when ticks overlap
Next Topic: Callbacks with 'Disable' feature
Goto Forum:
  


Current Time: Fri May 03 18:20:46 CEST 2024

Total time taken to generate the page: 0.02250 seconds