MFC的多线程启动使用的是:AfxBeginThread(),是对CWinThread的一层外包装。直接使用CWinThread会获得更好的控制,还可以储存“线程间通讯”数据。下面是一个简单的CWinThread的子类,其中使用了MFC中未公开的两个东东。程序里面有注释啦。
#include <afxwin.h>
CWinApp TheApp;
class CUserThread : public CWinThread
{
public: // Member functions
CUserThread(AFX_THREADPROC pfnThreadProc);
static UINT ThreadFunc(LPVOID param);
public: // Member data
int m_nStartCounter;
private: // The "real" startup function
virtual void Go();
};
CUserThread::CUserThread(AFX_THREADPROC pfnThreadProc)
: CWinThread(pfnThreadProc, NULL) // Undocumented constructor
{
m_bAutoDelete = FALSE;
// Set the pointer to the class to be the startup value.
// m_pThreadParams is undocumented,
// but there is no work-around.
m_pThreadParams = this;
}