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 » Community » Newbie corner » Thread with parametarized callback?
Re: Thread with parametarized callback? [message #37768 is a reply to message #37765] Sun, 11 November 2012 10:09 Go to previous messageGo to previous message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
I think I solved part of my problem. However: I don't think the solution I used it a good / neat one. I placed the Threading part of the code in the GUI class. I was planning on putting that into the worker class.

The following code works. I now get my controls updated on by one though a callback while still having the GUI responsive.

void MovieManager::ButtonImdbSearch()
{
	int row = mMovieList.GetClickRow(); // variable needed to identify the value which to search for
	if (row >= 0)
	{
		mStatusBar.Set(STATUS_SEARCHING_IMDB);            // Set status to "Searching IMDb..."
		mImdbCtrls.Clear();                               // Clear current search results
		Thread().Run(THISBACK1(RunImdbSearchAsync, row)); // Start new thread in function below
	}
}

void MovieManager::RunImdbSearchAsync(int row)
{
	ImdbManager im;
	mStatusBar.AddFrame(mMainStatusInfoCtrl);                 // Still having trouble here, adding progressbar to statusbar
	im.WhenSearchGetCount = THISBACK(ImdbSearchGetCount);     // Callback that reports total search result count once to populate progressbar
	im.WhenImdbMovie = THISBACK(ImdbMovieFound);              // Callback that will update GUI by creating control
	im.ImdbSearch(mMovieList.Get(row, 0));                    // Run the operation...
	mStatusBar.Set(STATUS_READY);                             // Operation done, set status to "Ready"
	mStatusBar.RemoveFrame(mMainStatusInfoCtrl);              // remove the progressbar from the statusbar
}

void MovieManager::ImdbSearchGetCount(int pParam)
{
	mStatusProgress.Set(0, pParam);
}
void MovieManager::ImdbMovieFound(ImdbMovie pParam)
{
	int i = mImdbCtrls.GetCount() > 0 ? mImdbCtrls.GetCount() - 1: 0;
	ImdbSearchResult *m = new ImdbSearchResult();
	m->SetValues(CtrlImg::save(), pParam.cTitle, pParam.cUrl);
	mImdbCtrls.Add(m);
	mImdbSearchResults.Add(mImdbCtrls[i].HSizePos().TopPos(IMDBCTRLHEIGHT * i, IMDBCTRLHEIGHT));
	mScrollBar.SetTotal(mImdbCtrls.GetCount() * IMDBCTRLHEIGHT);
}
 
Read Message
Read Message
Read Message
Previous Topic: Error meaning
Next Topic: broken pick semantics
Goto Forum:
  


Current Time: Fri Jul 18 06:46:21 CEST 2025

Total time taken to generate the page: 0.04927 seconds