// WaitSplasWindow.cpp : implementation file
//

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


// CWaitSplasWindow dialog

IMPLEMENT_DYNAMIC(CWaitSplasWindow, CDialogEx)

CWaitSplasWindow::CWaitSplasWindow(
    LPCTSTR sMessageText, /*=NULL*/
    CWnd* pParent /*=NULL*/
    )
: CDialogEx(CWaitSplasWindow::IDD, pParent)
, m_sMessageText(sMessageText)
, m_oRtsddLogoPoint(11,11)
, m_oRtsddLogoRect(11,11,308,275)
, m_nAnimateTimer(0)
, m_nWaitImageID(0)
, m_oWaitImagePoint(442, 41)
, m_oWaitImageRect(442, 41, 561, 159)
{
    BOOL    bRet;
    bRet = m_oWaitImageList.Create(
        IDB_WAIT_HA,
        119,
        0,
        RGB(255, 255, 255)
        );
    ASSERT(bRet);
    m_oRtsddLogoImage.LoadFromResource(
        AfxGetInstanceHandle(),
        IDB_RTSDD_LOGO
        );
}

CWaitSplasWindow::~CWaitSplasWindow()
{
}

void CWaitSplasWindow::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Text(pDX, IDC_MESSAGE_TEXT, m_sMessageText);
}


BEGIN_MESSAGE_MAP(CWaitSplasWindow, CDialogEx)
    ON_WM_PAINT()
    ON_WM_TIMER()
    ON_WM_DESTROY()
END_MESSAGE_MAP()


// CWaitSplasWindow message handlers


BOOL CWaitSplasWindow::OnInitDialog()
{
    BOOL    bRet;
    CDialogEx::OnInitDialog();
    // TODO:  Add extra initialization here
    bRet = SetBackgroundImage(
        IDB_DIALOG_BACKGROUND,
        BACKGR_TOPLEFT,
        FALSE
        );
    ASSERT(bRet);
    m_nAnimateTimer = SetTimer(
        1,
        500,
        NULL
        );
    return TRUE;  // return TRUE unless you set the focus to a control
}


void CWaitSplasWindow::OnOK()
{
    // TODO: Add your specialized code here and/or call the base class
}


void CWaitSplasWindow::OnCancel()
{
    // TODO: Add your specialized code here and/or call the base class
}


void CWaitSplasWindow::OnPaint()
{
    BOOL        bRet;
    CPaintDC    dc(this); // device context for painting
    // TODO: Add your message handler code here
    // Do not call CDialogEx::OnPaint() for painting messages
    bRet = m_oWaitImageList.DrawEx(
        &dc,
        m_nWaitImageID,
        m_oWaitImagePoint,
        CSize(0, 0),
        CLR_NONE,
        CLR_NONE,
        ILD_NORMAL
        );
    ASSERT(bRet);
    bRet = m_oRtsddLogoImage.TransparentBlt(
        dc,
        m_oRtsddLogoRect,
        RGB(255, 0, 0)
        );
    ASSERT(bRet);
}


void CWaitSplasWindow::OnTimer(UINT_PTR nIDEvent)
{
    // TODO: Add your message handler code here and/or call default
    if (nIDEvent == m_nAnimateTimer)
    {
        m_nWaitImageID++;
        if (m_nWaitImageID >= 10)
        {
            m_nWaitImageID = 0;
        }
        InvalidateRect(m_oWaitImageRect, FALSE);
    }
    CDialogEx::OnTimer(nIDEvent);
}


void CWaitSplasWindow::OnDestroy()
{
    BOOL    bRet;
    CDialogEx::OnDestroy();
    // TODO: Add your message handler code here
    if (0 != m_nAnimateTimer)
    {
        bRet = KillTimer(m_nAnimateTimer);
        m_nAnimateTimer = 0;
    }
}
