// infodlg.cpp : implementation file
//

#include "stdafx.h"
#include "flsrom.h"
#include "flsinfo.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CInfoDlg dialog


CInfoDlg::CInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CInfoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_bJed=FALSE;
}


void CInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CInfoDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CInfoDlg)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CInfoDlg message handlers

void CInfoDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect rect,client; 

	GetDlgItem(IDC_STATIC0)->GetWindowRect(&rect);
	DrawFrame(&dc,rect,0);
	rect.InflateRect(2,2);
	DrawFrame(&dc,rect,1);
	GetDlgItem(IDC_STATIC1)->GetWindowRect(&rect);
	DrawFrame(&dc,rect,1);
	GetDlgItem(IDC_STATIC2)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,1);	
	GetDlgItem(IDC_STATIC3)->GetWindowRect(&rect);
	DrawFrame(&dc,rect,1);
	GetDlgItem(IDC_STATIC4)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,1);	
	GetDlgItem(IDC_STATIC5)->GetWindowRect(&rect);
	DrawFrame(&dc,rect,1);
	GetDlgItem(IDC_STATIC6)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,0);
	GetDlgItem(IDC_STATIC7)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,0);
	GetDlgItem(IDC_STATIC8)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,0);
	GetDlgItem(IDC_STATIC9)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,0);
	GetDlgItem(IDC_STATIC10)->GetWindowRect(&rect);	
	DrawFrame(&dc,rect,0);
	if(m_bJed)
	{
		GetDlgItem(IDC_STATIC11)->GetWindowRect(&rect);	
		DrawFrame(&dc,rect,1);
		GetDlgItem(IDC_STATIC12)->GetWindowRect(&rect);	
		DrawFrame(&dc,rect,0);
	}
}


void CInfoDlg::DrawFrame(CDC * pdc, CRect rect,UINT flag)
{
    
	ScreenToClient(&rect);
	rect.InflateRect(1,1);
	    
    CPen* pOldPen,*pPen=new CPen;
//    pPen->CreatePen(PS_SOLID, 1,RGB(0,0,0) );
    CPoint points[4];   
    if(flag==0){
        points[0]=CPoint(rect.left,rect.bottom);
    	points[1]=CPoint(rect.left,rect.top);
    	points[2]=CPoint(rect.right,rect.top);
    	points[3]=CPoint(rect.right,rect.bottom); 
     }
    else{ 	
        points[0]=CPoint(rect.left,rect.bottom);
    	points[1]=CPoint(rect.right,rect.bottom); 
    	points[2]=CPoint(rect.right,rect.top);
    	points[3]=CPoint(rect.left,rect.top);
     }
//    pOldPen=pdc->SelectObject(pPen); 
    pdc->MoveTo(points[0]);
 	pdc->LineTo(points[1]);
 	pdc->LineTo(points[2]);
    pPen->DeleteObject();
       
    pPen->CreatePen(PS_SOLID,1,RGB(255,255,255) );
    pOldPen=pdc->SelectObject(pPen);
 	pdc->LineTo(points[3]);
 	pdc->LineTo(points[0]);
    pdc->SelectObject(pOldPen);
    pPen->DeleteObject();
	delete pPen;
}    
        

BOOL CInfoDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	char tmp[16];
	CString title;

	SetDlgItemText(IDC_STATIC6,m_szFileName);
	if(m_bJed==1)
	{
		SetWindowText("Hardware Information");
		SetDlgItemText(IDC_STATIC0,
			"Hardware Download OK ! Please Reset the EasyPack !");
		SetDlgItemText(IDC_STATIC11, "Target:");
		if(m_uchMinor==0)
			title="ETB 1016";
		else if(m_uchMinor==1)
			title="CB-196 1032E";
		else
			title="EP-196 1032E";
		SetDlgItemText(IDC_STATIC12, title);
		SetDlgItemText(IDC_STATIC2, "Status:");
		SetDlgItemText(IDC_STATIC4, "download size:");
		SetDlgItemText(IDC_STATIC7, m_uRecordNum?"Work":"Diagnotics");
		wsprintf(tmp,"%X",m_uchMajor);
	}	
	//show HW info before download
	else if(m_bJed==2)
	{
		SetWindowText("Hardware Information");
		SetDlgItemText(IDC_STATIC0,
			"Please Check Hardware version !");
		SetDlgItemText(IDC_STATIC11, "Target:");
		if(m_uchMinor==0)
			title="ETB 1016";
		else if(m_uchMinor==1)
			title="CB-196 1032E";
		else
			title="EP-196 1032E";
		SetDlgItemText(IDC_STATIC12, title);
		SetDlgItemText(IDC_STATIC2, "Status:");
		SetDlgItemText(IDC_STATIC4, "download size:");
		SetDlgItemText(IDC_STATIC7, m_uRecordNum?"Work":"Diagnotics");
		wsprintf(tmp,"%X",m_uchMajor);
	}
	else
	{
		SetDlgItemInt(IDC_STATIC7,m_uRecordNum); 
		if(m_uchMinor<0xf)
			wsprintf(tmp,"%X.0%X",m_uchMajor,m_uchMinor);
    	else 
        	wsprintf(tmp,"%X.%X",m_uchMajor,m_uchMinor);
    }
	SetDlgItemText(IDC_STATIC8,tmp);
    
    wsprintf(tmp,"%ld",m_lFileSize);
	SetDlgItemText(IDC_STATIC9,tmp); 
	
    int nDay = m_uData & 0x1f;
    int nMonth = (m_uData >> 5) & 0x0f;
    int nYear = m_uYear; 
	wsprintf(tmp,"%d/%d/%d",nMonth,nDay,nYear);    
	SetDlgItemText(IDC_STATIC10,tmp);  

//Center the window
	CRect rect;
	GetWindowRect(&rect);
	int x,y;
	x=(::GetSystemMetrics(SM_CXSCREEN)-rect.Width() )/2;
	y=(::GetSystemMetrics(SM_CYSCREEN)-rect.Height() )/2;
	SetWindowPos( &wndTop,x,y,0,0,SWP_NOSIZE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
