#include <windows.h>
#include <stdio.h>
class ThreadClass
{
protected:
HANDLE m_hThread;
LPCTSTR m_szName;
public:
ThreadClass(LPCTSTR szName)
{
m_szName=szName;
m_hThread=INVALID_HANDLE_VALUE;
m_hThread=::CreateThread(NULL,0,ThreadProc,reinterpret_cast<LPVOID>(this),0,NULL);
}
virtual ~ThreadClass()
{
printf("ddddddddddddd");
::CloseHandle(m_hThread);
}
virtual void WaitForCompletion()
{
::WaitForSingleObject(m_hThread,INFINITE);
}
protected:
static DWORD WINAPI ThreadProc(LPVOID lpParam)
{
ThreadClass *pThis=reinterpret_cast<ThreadClass *>(lpParam);
pThis->DoStuff();
return (0);
}
virtual void DoStuff()
{
for(int n=0;n<20;++n)
{
printf("Thread: %s\n",m_szName);
Sleep(100);
printf("ID: %d\n",::GetCurrentThreadId());
Sleep(100);
printf("count: %d\n\n",n);
Sleep(100);
}
}
}
这个文件的头文件应该怎么样写?谢谢