CSDN博客

img jackychu

CreateThread 和AfxBeginThread的编码区别

发表于2008/9/28 13:02:00  1217人阅读

 class CThread1
{
public:
 CThread1();
 ~CThread1();
public:
 static DWORD WINAPI ThreadPoc(LPVOID lparam);
 DWORD MainFunc();
 void StopServ();

 DWORD m_dwID;
 CCTestDlg* m_pMainWnd;
 afx_msg void ThreadMsgFunction(WPARAM wParam,LPARAM lParam);
private:
 HANDLE m_hStop;
};

 

class CThread3 : public CWinThread
{
 DECLARE_DYNCREATE(CThread3)

protected:
 CThread3();           // protected constructor used by dynamic creation
 virtual ~CThread3();
 afx_msg void ThreadMsgFunction(WPARAM wParam,LPARAM lParam);

public:
 virtual BOOL InitInstance();
 virtual int ExitInstance();
 void StopThread();

protected:
 DECLARE_MESSAGE_MAP()

private:
 void MainFunc();
 BOOL m_bStopThread;

};

 

 DWORD dwThread1,dwThread2;
 HANDLE hThread1,hThread2;
 m_pThread1 = new CThread1;
 m_pThread2 = new CThread2;
 hThread1 = ::CreateThread(NULL,0,CThread1::ThreadPoc,m_pThread1,0,&dwThread1);
 hThread2 = ::CreateThread(NULL,0,CThread2::ThreadPoc,m_pThread2,0,&dwThread2);
 m_pThread3 = NULL;
 m_pThread3 = (CThread3*)AfxBeginThread(RUNTIME_CLASS(CThread3));

 if(hThread1)
 {
  
  m_Arry.Add(dwThread1);
  m_pThread1->m_pMainWnd = this;
 }

 if(hThread2)
 {
  m_Arry.Add(dwThread2);
  m_pThread2->m_pMainWnd = this;
 }

 if(m_pThread3)
 {
  m_Arry.Add(m_pThread3->m_nThreadID);
 }

0 0

相关博文

我的热门文章

img
取 消
img