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++ MT-multithreading and servers » thread sample and overrideCursor
thread sample and overrideCursor [message #29815] Fri, 19 November 2010 12:45 Go to previous message
ratah is currently offline  ratah
Messages: 107
Registered: July 2010
Experienced Member
Hi everybody,

I give a little modification to thread sample i found here.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class TestThread : public TopWindow
{
	protected:
		bool stop;
		void buttonCb(void);
		Thread thr1, thr2;
		virtual void thrCb(void);
		virtual void thrPerso(void);
		
		ProgressIndicator progress;
		int32 icounter;
		Button button;
		StatusBar status;
		
		Image ImgCrs;
		
	public:
		typedef TestThread CLASSNAME;

		TestThread();

};

void TestThread::thrCb(void)
{
	for(;!stop;)
	{		
		if(progress < 30)
			progress++;
		else
		{
			// I stop progress bar here
			// Inside the thread, so thr1 always run!!!!
			
			stop = false;
			OverrideCursor(ImgCrs);
			UpdateRefresh();
			break;			
		}
			
		Sleep(100);
	}
}

void TestThread::thrPerso(void)
{
	for(;!stop; )
	{
		icounter++;
		status.Set(IntStr(icounter));
		
		Sleep(100);
	}
}

void TestThread::buttonCb(void)
{
	if(stop)
	{
		stop = false;
		button.SetLabel("STOP");
		
		ImgCrs = OverrideCursor(Image::Wait());
		thr1.Run(THISBACK(thrCb));
		thr2.Run(THISBACK(thrPerso));
	}
	else
	{
		OverrideCursor(ImgCrs);
		
		stop = true;
		thr1.Wait();
		button.SetLabel("START");
	}
	
	
}

TestThread::TestThread()
{
	SetRect(0, 0, 300, 150);
	Add(button);
	button.TopPos(90, 30).HCenterPos(100);
	button.SetLabel("START");
	Add(progress);
	progress.TopPos(30, 40).HCenterPos(250);
	progress.Set(0, 100);
	icounter = 0;
	AddFrame(status);
	status.Set(" ");

	stop = true;
	button <<= THISBACK(buttonCb);
		
}

GUI_APP_MAIN
{
	TestThread().Run();
}


thread 1: incrementation of progress bar
thread 2: incrementation of counter in status bar


I have a question about Cursor Image,
Why image cursor doesn't change at once? I need to move it to turn back to the original arrow cursor???

Thank you for your responses

Ratah
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Httpclient timeout
Next Topic: OpenMP
Goto Forum:
  


Current Time: Sun Apr 28 02:55:26 CEST 2024

Total time taken to generate the page: 0.04603 seconds