// SplashDlg.cpp : implementation file
//

#include "stdafx.h"
#include "RYLLogin.h"
#include "SplashDlg.h"


// CSplashDlg dialog

IMPLEMENT_DYNAMIC(CSplashDlg, CDialog)
CSplashDlg::CSplashDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSplashDlg::IDD, pParent)
{
	m_nFade = 0;
}

CSplashDlg::~CSplashDlg()
{
}

void CSplashDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CSplashDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CSplashDlg message handlers

void CSplashDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting	
	//CClientDC dc(NULL);
	RenderBack( dc, m_btmSplash, 0, 0 );
}

BOOL CSplashDlg::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default

	return CDialog::OnEraseBkgnd(pDC);
}

void CSplashDlg::RenderBack( CDC &rDC, CBitmap &rBitmap, int Px, int Py , int SizeX, int SizeY )
{
	CBitmap *pOldBitmap;
	CDC memDC;
	memDC.CreateCompatibleDC(&rDC);
	pOldBitmap=memDC.SelectObject(&rBitmap);	
	CSize sBitmap=rBitmap.GetBitmapDimension();

	BITMAP bmInfo;
	rBitmap.GetBitmap(&bmInfo);	

	if( SizeX == -1 && SizeY == -1 )
		rDC.BitBlt(Px,Py,bmInfo.bmWidth,bmInfo.bmHeight,&memDC,0,0,SRCCOPY);
	else
		rDC.BitBlt(Px,Py,SizeX,SizeY,&memDC,0,0,SRCCOPY);

	memDC.SelectObject(pOldBitmap);
}



BOOL CSplashDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// TODO:  Add extra initialization here

	SetWindowPos( &wndTopMost, 0, 0, 463, 143,  SWP_NOMOVE );
 
	SetTimer( WM_FADETIMER, 10, NULL );

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CSplashDlg::OnTimer(UINT nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	m_nFade+=1;

	if( m_nFade >= 180 )
	{
		KillTimer( nIDEvent );
		OnOK();
	}
	CDialog::OnTimer(nIDEvent);
}
