• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    CCreateThreadEx
    Last Modify : 27 December, 2010(02:17)
    //
    // DATE		: May 10, 2007
    // CODER	: Kurome (aucd29@gmail.com)
    // VERSION	: 1.0
    //
    //
    // ------------------------------------------------------
    // NOTE
    // ------------------------------------------------------
    // * Thread를 손 쉽게 이용을 해 보도록 하자.
    //
    
    #include "StdAfx.h"
    #include "CreateThreadEx.h"
    
    CCreateThreadEx::CCreateThreadEx(void)
    {
    
    }
    
    CCreateThreadEx::~CCreateThreadEx(void)
    {
    
    }
    
    void CCreateThreadEx::Init(LPTHREAD_START_ROUTINE lpFunc, LPVOID lpArg)
    {
    	m_hThread = ::CreateThread(NULL, 0, lpFunc, lpArg, 0, &m_dwThreadID);
    
    	if (m_hThread == NULL)
    	{
    		AfxMessageBox(L"can not create thread");
    	}
    }
    
    BOOL CCreateThreadEx::IsAlive(void)
    {
    	ASSERT(m_hThread);
    	DWORD dwThreadExitCode;
    	GetExitCodeThread(m_hThread, &dwThreadExitCode);
    
    	// STILL_ACTIVE == live
    	return dwThreadExitCode==STILL_ACTIVE ? TRUE : FALSE;
    }
    
    void CCreateThreadEx::Supend(void)
    {
    	ASSERT(m_hThread);
    	SuspendThread(m_hThread);
    }
    
    void CCreateThreadEx::Resume(void)
    {
    	ASSERT(m_hThread);
    	ResumeThread(m_hThread);
    }
    
    void CCreateThreadEx::Kill(void)
    {
    	ASSERT(m_hThread);
    	TerminateThread(m_hThread, 0);
    }
    
    BOOL CCreateThreadEx::SetPriority(int nPriority)
    {
    	/*
    	THREAD_PRIORITY_BELOW_NORMAL
    	THREAD_PRIORITY_NORMAL
    	THREAD_PRIORITY_HIGHEST
    	THREAD_PRIORITY_ABOVE_NORMAL
    	THREAD_PRIORITY_ERROR_RETURN
    
    	THREAD_PRIORITY_TIME_CRITICAL
    	THREAD_PRIORITY_IDLE
    	*/
    	ASSERT(m_hThread);
    	return ::SetThreadPriority(m_hThread, nPriority);;
    }
    
    #pragma once
    
    class CCreateThreadEx
    {
    protected:
    	DWORD m_dwThreadID;
    	HANDLE m_hThread;
    
    public:
    	CCreateThreadEx(void);
    	~CCreateThreadEx(void);
    	void Init(LPTHREAD_START_ROUTINE lpFunc, LPVOID lpArg);
    	BOOL IsAlive(void);
    	void Supend(void);
    	void Resume(void);
    	void Kill(void);
    	BOOL SetPriority(int nPriority = THREAD_PRIORITY_IDLE);
    };
    

    Comment


    입력하3 1498664894



    Locations of visitors to this page