Creating Threads with MFC

< BACK  NEXT >
[oR]

MFC provides the CWinThread class to provide support for creating threads, and is similar in many respects to CWinApp in the methods it supports. This class can be used to manage worker and user interface threads because, like CWinApp, it implements a message loop.

Although MFC provides a class to manage threads, you still need to create a global thread function that has the following prototype:

 UINT MFCThreadProc(LPVOID lpParameter); 

The MFC function AfxBeginThread can be called to create a worker thread using the thread function:

 CWinThread* pThread =   AfxBeginThread(MFCThreadProc, NULL); 

The function AfxBeginThread is passed a pointer to the thread function and a pointer to data to pass to the LPVOID parameter (which is, in this case, NULL). AfxBeginThread returns a pointer to a CWinThread object through which the newly created thread can be managed. For example, you can suspend and resume the thread by calling CWinThread::SuspendThread and CWinThread::ResumeThread. You can ignore the return result from AfxBeginThread if you do not need to manage the thread, and you do not have to delete the CWinThread object.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net