多线程编程之二——MFC中的多线程开发
2007-03-17 22:00:08 来源:WEB开发网用 MFC 类库编程实现用户界面线程
创建用户界面线程的步骤:
使用ClassWizard创建类CWinThread的派生类(以CUIThread类为例)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();
}
更多精彩
赞助商链接