MFC多线程
class CUIThread : public CWinThread
{
DECLARE_DYNCREATE(CUIThread)
protected:
CUIThread(); // protected constructor used by dynamic creation
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CUIThread)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~CUIThread();
// Generated message map functions
//{{AFX_MSG(CUIThread)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
-
重载函数InitInstance()和ExitInstance()。
BOOL CUIThread::InitInstance()
{
CFrameWnd* wnd=new CFrameWnd;
wnd->Create(NULL,“UI Thread Window”);
wnd->ShowWindow(SW_SHOW);
wnd->UpdateWindow();
m_pMainWnd=wnd;
return TRUE;
} -
创建新的用户界面线程 void CUIThreadDlg::OnButton1()
{
CUIThread* pThread=new CUIThread();
pThread->CreateThread();
}