Click here to Skip to main content
15,906,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to run a thread as a member function of a class? Pin
Eytukan14-Jun-05 2:06
Eytukan14-Jun-05 2:06 
GeneralRe: How to run a thread as a member function of a class? Pin
David Crow14-Jun-05 2:20
David Crow14-Jun-05 2:20 
GeneralRe: How to run a thread as a member function of a class? Pin
Bob Stanneveld14-Jun-05 21:17
Bob Stanneveld14-Jun-05 21:17 
AnswerRe: How to run a thread as a member function of a class? Pin
Cedric Moonen14-Jun-05 1:57
Cedric Moonen14-Jun-05 1:57 
AnswerRe: How to run a thread as a member function of a class? Pin
Michael Dunn14-Jun-05 4:21
sitebuilderMichael Dunn14-Jun-05 4:21 
GeneralRe: How to run a thread as a member function of a class? Pin
Eytukan14-Jun-05 2:14
Eytukan14-Jun-05 2:14 
Generali'm Noosed down by the THREADS!! Pin
Eytukan14-Jun-05 2:25
Eytukan14-Jun-05 2:25 
GeneralSolution for the thread Pin
Eytukan15-Jun-05 6:11
Eytukan15-Jun-05 6:11 
bob,david,cedric,michael, and paul........
paul the link u gave is ultimate.. thank u so much. really resourceful.i think i wont be disturbing u guys again.. everything's there Smile | :)

The Thread Solution

It is almost always the case that you can use threads to do the job more easily. This is not without certain costs and hazards, but it ultimately is the better method.

Here's a solution to handling the invert-everything. Note that we have to move from the pure-C domain (which we interface to via a static method) to the MFC domain.

To the class (in this example, a CView-derived class), add the following declarations:

static UINT run(LPVOID p);
void run();
volatile BOOL running;
To start a thread, your handler does

void CMyView::doInvert()
{
running = TRUE;
AfxBeginThread(run, this);
}

UINT CMyView::run(LPVOID p)
{
CMyView * me = (CMyView *)p;
me->run();
return 0;
}

void CMyView::run()
{
for(int x=y = 0; running && y < image.height; y++)
for(int x = 0; running && x < image.width; x++)
changePixel(x, y);
running = FALSE;
}
The command to stop the thread is very simple:

void CMyView::OnStop()
{
running = FALSE;
}
That's all there is to it!
Laugh | :laugh:


vivek
AnswerRe: How to run a thread as a member function of a class? Pin
Paul Steane14-Jun-05 19:28
Paul Steane14-Jun-05 19:28 
Generalplease check out this link Pin
Eytukan15-Jun-05 6:20
Eytukan15-Jun-05 6:20 
GeneralCreate an application to clear Heap Memory Pin
Member 137164714-Jun-05 3:36
Member 137164714-Jun-05 3:36 
GeneralRe: Create an application to clear Heap Memory Pin
David Crow14-Jun-05 1:35
David Crow14-Jun-05 1:35 
GeneralRe: Create an application to clear Heap Memory Pin
Anonymous14-Jun-05 6:34
Anonymous14-Jun-05 6:34 
QuestionHelp Me! How to access a file with filename have space letters? Pin
lewislewis_lewis14-Jun-05 3:35
lewislewis_lewis14-Jun-05 3:35 
AnswerRe: Help Me! How to access a file with filename have space letters? Pin
David Crow14-Jun-05 1:28
David Crow14-Jun-05 1:28 
Generalerror code is 18 Pin
lewislewis_lewis14-Jun-05 4:59
lewislewis_lewis14-Jun-05 4:59 
GeneralRe: error code is 18 Pin
David Crow14-Jun-05 2:05
David Crow14-Jun-05 2:05 
GeneralYES! Pin
lewislewis_lewis14-Jun-05 5:26
lewislewis_lewis14-Jun-05 5:26 
GeneralRe: YES! Pin
David Crow14-Jun-05 5:49
David Crow14-Jun-05 5:49 
GeneralIf I get FileURL, Every thing is OK. Pin
lewislewis_lewis14-Jun-05 8:01
lewislewis_lewis14-Jun-05 8:01 
GeneralRe: If I get FileURL, Every thing is OK. Pin
David Crow14-Jun-05 8:03
David Crow14-Jun-05 8:03 
GeneralNo work using URL Pin
lewislewis_lewis14-Jun-05 8:50
lewislewis_lewis14-Jun-05 8:50 
GeneralRe: No work using URL Pin
David Crow14-Jun-05 8:54
David Crow14-Jun-05 8:54 
GeneralRe: No work using URL Pin
lewislewis_lewis14-Jun-05 9:06
lewislewis_lewis14-Jun-05 9:06 
GeneralRe: No work using URL Pin
David Crow14-Jun-05 9:14
David Crow14-Jun-05 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.