CWinThreadを継承したCCustThread(CustThread.h) |
#if !defined(AFX_CUSTTHREAD_H__72F1ABDE_7CB7_4B19_908E_AE9ECFFC81CB__INCLUDED_) #define AFX_CUSTTHREAD_H__72F1ABDE_7CB7_4B19_908E_AE9ECFFC81CB__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define WM_QUITTHREAD WIN_APP + 0x100 ///////////////////////////////////////////////////////////////////////////// // CCustThread スレッド class CCustThread : public CWinThread{ DECLARE_DYNCREATE(CCustThread) protected: CCustThread(); // 動的生成に使用されるプロテクト コンストラクタ // アトリビュート public: // オペレーション public: void SetStop(); // オーバーライド // ClassWizard は仮想関数のオーバーライドを生成します。 //{{AFX_VIRTUAL(CCustThread) public: virtual BOOL InitInstance(); virtual int ExitInstance(); virtual int Run(); //}}AFX_VIRTUAL // インプリメンテーション protected: virtual ~CCustThread(); // 生成されたメッセージ マップ関数 //{{AFX_MSG(CCustThread) // メモ - ClassWizard はこの位置にメンバ関数を追加または削除します。 //}}AFX_MSG DECLARE_MESSAGE_MAP() private: BOOL m_bStop; }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ は前行の直前に追加の宣言を挿入します。 #endif // !defined(AFX_CUSTTHREAD_H__72F1ABDE_7CB7_4B19_908E_AE9ECFFC81CB__INCLUDED_) |
CWinThreadを継承したCCustThread(CustThread.cpp) |
#include "stdafx.h" #include "CThreadSample.h" #include "CustThread.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CCustThread IMPLEMENT_DYNCREATE(CCustThread, CWinThread) CCustThread::CCustThread(){ } CCustThread::~CCustThread(){ } BOOL CCustThread::InitInstance(){ return TRUE; } int CCustThread::ExitInstance(){ return CWinThread::ExitInstance(); } BEGIN_MESSAGE_MAP(CCustThread, CWinThread) //{{AFX_MSG_MAP(CCustThread) // メモ - ClassWizard はこの位置にマッピング用のマクロを追加します。 //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CCustThread メッセージ ハンドラ int CCustThread::Run(){ while(m_bStop){ ・・・なにか処理・・・ } return 0; } void CJPLoadMainThread::SetStop(){ m_bStop = TRUE; } |
CRuntimeClass *pRuntime = RUNTIME_CLASS(CCustThread); CCustThread *pThread = (CCustThread*)pRuntime->CreateObject(); pThread->CreateThread(0, 0, NULL); |
CWinThread *m_pThread; ・・・・ if(::WaitForSingleObject(m_pThread->m_hThread)){ ・・・・ } |
CWinThread *m_pThread; ・・・・ if(m_pThread->SuspendThread() != 0xFFFFFFFF){ delete m_pThread; } ・・・・ |