/*******************************************************}

{                                                       }

{       File : Thread.h                                 }

{       Created by Tsviatko Jongov                      }

{       http://tsviatko.jongov.com                      }

{                                                       }

{       Base thread class.                              }

{                                                       }

{*******************************************************/

   

#ifndef __THREAD_H__

#define __THREAD_H__

   

class CThread

{

protected:

    HANDLE m_ThreadHandle;

public:

    CThread()

    {

        m_ThreadHandle = CreateThread(NULL, NULL, CThread::StaticThread, (void *)this, CREATE_SUSPENDED, NULL);

    }

   

    virtual ~CThread()

    {

        CloseHandle(m_ThreadHandle);

    }

   

    static DWORD WINAPI StaticThread(LPVOID lpParameter)

    {

        if (NULL == lpParameter)

        {

            return  (DWORD)-1;

        }

       

        return  ((CThread *)lpParameter)->ThreadFunc();

    }

   

    DWORD ResumeThread()

    {

        return ::ResumeThread(m_ThreadHandle);

    }

   

    void WaitFor()

    {

        WaitForSingleObject(m_ThreadHandle, INFINITE);

    }

   

    void SetThreadPriority(int Priority)

    {

        ::SetThreadPriority(m_ThreadHandle, Priority);

    }

   

    virtual int ThreadFunc(void) = 0;

};

   

#endif // __THREAD_H__