// CPAMDgQu.cpp : implementation file
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"

#include "EMECDgQu.hpp"

#include "_MInterf.hpp"

//External Modules
#include "IncTUT.h"
//End of External Modules

#define C_QUESTION_DIALOG_TIMER		69	//An Id for the timer
#define C_TEMPO_TIMER							60	//(ms)
#define C_NUMBER_OF_FRAMES				15	

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPA_Meca_QuestionDialog dialog

BEGIN_MESSAGE_MAP(CPA_Meca_QuestionDialog, CDialog)
	//{{AFX_MSG_MAP(CPA_Meca_QuestionDialog)
	ON_BN_CLICKED(IDNO, OnNo)
	ON_BN_CLICKED(IDYES, OnYes)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


//**************************************************************************
CPA_Meca_QuestionDialog::CPA_Meca_QuestionDialog(CWnd* pParent, CString csMessage)
	: CDialog(CPA_Meca_QuestionDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPA_Meca_QuestionDialog)
	m_csMessage = csMessage;
	//}}AFX_DATA_INIT

	m_hOldInstance = AfxGetResourceHandle();
	AfxSetResourceHandle(g_stMecaDLLIdentity.hModule);
}

//**************************************************************************
CPA_Meca_QuestionDialog::~CPA_Meca_QuestionDialog()
{
	AfxSetResourceHandle(m_hOldInstance);
}

//***************************************************************************
void CPA_Meca_QuestionDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPA_Meca_QuestionDialog)
	DDX_Text(pDX, IDC_STATIC_QUESTION, m_csMessage);
	//}}AFX_DATA_MAP
}


/////////////////////////////////////////////////////////////////////////////
// CPA_Meca_QuestionDialog message handlers

//***************************************************************************
BOOL CPA_Meca_QuestionDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//Init. timer
	SetTimer(C_QUESTION_DIALOG_TIMER, C_TEMPO_TIMER, NULL);

	//Loads Bitmaps
	m_cbBitmap.LoadBitmap(IDB_BITMAP_QUESTION);
 
	//////////////
	//////////////
	//Registers for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vRegisterControlID(IDYES, "TMe_QuestionDialog_YesButton", TUT_e_Button);
	TUT_M_vRegisterControlID(IDNO, "TMe_QuestionDialog_NoButton", TUT_e_Button);

	//End of Registers for TUT Module
	//////////////

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

//***************************************************************************
void CPA_Meca_QuestionDialog::OnDestroy() 
{
	//////////////
	//////////////
	//UnRegisters for TUT Module
	TUT_M_vGetTutDll();
	
	TUT_M_vUnregisterControlID(IDYES);
	TUT_M_vUnregisterControlID(IDNO);
	
	//End of UnRegisters for TUT Module
	//////////////

	CDialog::OnDestroy();
}

//***************************************************************************
void CPA_Meca_QuestionDialog::OnNo() 
{
	KillTimer(C_QUESTION_DIALOG_TIMER);
	
	EndDialog(IDNO);
}

//***************************************************************************
void CPA_Meca_QuestionDialog::OnYes() 
{
	KillTimer(C_QUESTION_DIALOG_TIMER);

	EndDialog(IDYES);
}

//***************************************************************************
void CPA_Meca_QuestionDialog::OnTimer(UINT nIDEvent) 
{
/*	static BOOL s_bFirstPass = TRUE;
	static char s_cCurrentBitmapIndex = -1; //To begin with first bitmap
	static char s_cIndexIncrement = 1;

	s_cCurrentBitmapIndex += s_cIndexIncrement;
	if ( ! s_bFirstPass )
	{
		if ( s_cCurrentBitmapIndex % (C_NUMBER_OF_FRAMES-1) == 0 )
			s_cIndexIncrement = -s_cIndexIncrement;
	}
	else
		s_bFirstPass = FALSE;

	((CStatic *)GetDlgItem(IDC_STATIC_IMAGE))->SetBitmap(HBITMAP(m_a_cbBitmaps[s_cCurrentBitmapIndex]));
  */
 	static BOOL s_bFirstPass = TRUE;
	static CRect crRect;
	static char s_cCurrentIndex = -1;
	static char s_cIndexIncrement = 1;
 
	s_cCurrentIndex += s_cIndexIncrement;
	
	if ( s_bFirstPass )
	{
		crRect.top = 0;
		crRect.bottom = 56;
		crRect.left = 0;
		crRect.right = 56;

		s_bFirstPass = FALSE;
	}
	else
	{
  		if ( s_cCurrentIndex % (C_NUMBER_OF_FRAMES-1) == 0 )
			s_cIndexIncrement = -s_cIndexIncrement;
	}

	//Computes Rect
	crRect.left = (56 * s_cCurrentIndex)/ C_NUMBER_OF_FRAMES;
	crRect.right = 56 - (56 * s_cCurrentIndex)/ C_NUMBER_OF_FRAMES;

	CClientDC dc(GetDlgItem(IDC_EDIT_BIDON));
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	memDC.SelectObject(m_cbBitmap);

	dc.StretchBlt(	crRect.left, 	  
					crRect.top, 
					crRect.Width(), 
					crRect.Height(), &memDC, 0, 0, 56, 56, SRCCOPY);

	CDialog::OnTimer(nIDEvent);
}

