码迷,mamicode.com
首页 > 编程语言 > 详细

C++ CreateThread 实例

时间:2015-02-05 14:51:57      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

//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);
}

 

C++ CreateThread 实例

标签:

原文地址:http://www.cnblogs.com/Neu400753645/p/4274805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!