Visual C++/MFC Thread Question
-
Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..
-
Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..
I could mail you a simple examlpe. It popups message dialogs after a specified time span. Abortion is also included...
-
Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..
Here is a useful link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/\_mfc\_afxbeginthread.asp Try something like this to get you started: INT MyThread( LPVOID ptr ); int main( int argc, char** argv ) { CWinThread* T; DWORD dwWait; T = AfxBeginThread( MyThread, NULL ); dwWait = WaitForSingleObject( T->m_hThread, INFINITE ); return 0; } /* main() */ INT MyThread( LPVOID ptr ) { AfxMessageBox( "Hello, world!" ); return 0; }
-
Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..
create a worker thread.. UINT ClassName ::Thread1(LPVOID lp) { ClassName *cn = (ClassName*)lp; cn->Thread1(); } //// define the functionality inside the thread void ClassName::Thread1() { while(1) { AfxMessageBox("In thread"); Sleep(millisec); } } in the function, Anyfun() { CWinThread *cwt; cwt=AfxBeginThread(Thread1,this); } you can suspend the thread by cwt->SuspendThread(); resume by cwt->ResumeThread(); ExitInstance() will delete it Regards, V
-
create a worker thread.. UINT ClassName ::Thread1(LPVOID lp) { ClassName *cn = (ClassName*)lp; cn->Thread1(); } //// define the functionality inside the thread void ClassName::Thread1() { while(1) { AfxMessageBox("In thread"); Sleep(millisec); } } in the function, Anyfun() { CWinThread *cwt; cwt=AfxBeginThread(Thread1,this); } you can suspend the thread by cwt->SuspendThread(); resume by cwt->ResumeThread(); ExitInstance() will delete it Regards, V
-
to have a better look on a Thread... click on [View Thread] Below!!:laugh: jus fr fun, V............v
Vivekuniq wrote: click on [View Thread] Below!! I have Clicked [View Thread] and................... I got nothing............:->
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..
-