摘要://ThreadBase.h#pragmaonce#include classCThreadBase{public:CThreadBase(void);~CThreadBase(void),staticDWORDWINAPIThreadProc(PVOIDpParam);virtualvoidRun()=0;voidStart();private:HANDLEm_hThread
//ThreadBase.h
#pragma once
#include<windows.h>
class CThreadBase
{
public:
CThreadBase(void);
~CThreadBase(void);
static DWORD WINAPI ThreadProc (PVOID pParam);
virtual void Run() = 0;
void Start();
private:
HANDLE m_hThread;
DWORD m_dwThreadID;
};
//ThreadBase.cpp
#include "StdAfx.h"
#include "ThreadBase.h"
CThreadBase::CThreadBase(void)
{
m_hThread = CreateThread(NULL,0,ThreadProc,this,CREATE_SUSPENDED,&m_dwThreadID);
}
CThreadBase::~CThreadBase(void)
{
CloseHandle(m_hThread);
}
DWORD WINAPI CThreadBase::ThreadProc (PVOID pParam)
{
if (NULL!=pParam)
{
((CThreadBase*)pParam)->Run();
}
return 0;
}
void CThreadBase::Start()
{
ResumeThread(m_hThread);
}