// WaitThread.cpp : implementation file
//

#include "stdafx.h"
#include "InstallUtils.h"
#include "WaitThread.h"
#include "WaitSplasWindow.h"


// CWaitThread

IMPLEMENT_DYNCREATE(CWaitThread, CWinThread)

CWaitThread::CWaitThread(
    CString sMessage,
    CWnd*   pParent
    )
: m_pWaitSplasWindow(NULL)
, m_sMessageText(sMessage)
, m_pParent(pParent)
{
}

CWaitThread::~CWaitThread()
{
}

BOOL CWaitThread::InitInstance()
{
    BOOL        bRet;
    HINSTANCE   hDllModule;
    bRet = AfxOleInit();
    ASSERT(bRet);
    hDllModule = AfxGetInstanceHandle();
    AfxSetResourceHandle(hDllModule);
    m_pWaitSplasWindow = new CWaitSplasWindow(m_sMessageText, m_pParent);
    m_pMainWnd = m_pWaitSplasWindow;
    bRet = m_pWaitSplasWindow->Create(
        CWaitSplasWindow::IDD,
        m_pParent
        );
    ASSERT(bRet);
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    bRet = BringWindowToTop(*m_pMainWnd);
    return TRUE;
}

int CWaitThread::ExitInstance()
{
    BOOL    bRet;
    HWND    hParent;
    if (NULL != m_pParent)
    {
        hParent = m_pParent->Detach();
        delete m_pParent;
        m_pParent = NULL;
    }
    if (NULL != m_pWaitSplasWindow)
    {
        bRet = m_pWaitSplasWindow->DestroyWindow();
        delete m_pWaitSplasWindow;
        m_pWaitSplasWindow = NULL;
    }
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CWaitThread, CWinThread)
END_MESSAGE_MAP()


// CWaitThread message handlers
