// CASE2.cpp :
//
#define  __cplusplus
#include "stdafx.h"
#include "tutorial.h"
#include "mainfrm.h"
#include "srcwnd.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
extern void Delay(int nDelay,BOOL bShow=0);
extern BOOL g_bAuto;
extern BOOL g_mbCanDoNext;
/*-------------------------------------------------------*/
/*       how to down load file append to "net" msg       */
/*-------------------------------------------------------*/
void CMainFrame::HowToUseDownLoadFile(UINT *nCase)
{              
 CPoint         pointDest;
 CPoint         pointSrc;
 CRect          rect;
 if(m_pDlg)
   {
    
    if(*nCase>4)
      if(GetAMsgDlg())
        {    
         CloseDlg(GetAMsgDlg());
        /* 
         (*nCase)--;
         ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetAMsgDlg()->SetFocus();//DestroyWindow();
         MessageBeep(-1);
         return;
        */ 
        }   
        
    m_pDlg->SetFocus();    
   }
   

 SetMouse(0);    

 switch(* nCase)
   {
    case 1:    
              
         SetByUser(FALSE);
		 WriteMsg(IDS_LOAD_FILE_MSG1,DOOROPEN,"Load file");

		 if(g_bAuto)    
		   {       
		    KillTimer(IDAUTO);
		    SetTimer(IDAUTO, 5000,NULL);
		    SetSysMouse(1);
		    SetSysKey(1);
		   } 
		 break;

	case 2:	 
         rect.SetRect(WinCxy.x+6    ,WinCxy.y+375+2-50,
                      WinCxy.x+4+330,WinCxy.y+375+80-2-20);
         OverMsg.SetPaintRect(rect);                        
         SetKey(0);//setKeyFilter
		 //Choose Map Menu Item
         StepMsg.SetFont(12,5,400);
         OverMsg.SetFont(16,6,200);
		 pointDest.x=20;
		 pointDest.y=30;
		 GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(0,'F',1);
		 m_uMenuAct = ID_FILE_LOAD;
		 return;
    
    case 3:
         ((CNMLoadDlg *)m_pDlg)->SetEditText1();
         break;

    case 4:
          ((CNMLoadDlg *)m_pDlg)->SetOptionBtn(0);
          ((CButton *)(((CNMLoadDlg *)m_pDlg)->GetDlgItem(IDC_LOAD_OPTION)))->SetState(0);
          ((CNMLoadDlg *)m_pDlg)->PostMessage(WM_COMMAND,IDC_LOAD_OPTION,0);
          break;

    case 5:                                
         Delay(100);                  
         ((CNMLoadDlg *)m_pDlg)->SetRCodeMsg(); 
         ((CNMLoadDlg *)m_pDlg)->GetSrcDlg()->SetFocus();
         break;                  
    case 6: 
         Delay(100);
         ((CNMLoadDlg *)m_pDlg)->SetRSymbol(); 
         ((CNMLoadDlg *)m_pDlg)->GetSrcDlg()->SetFocus();
         break;
    case 7:         
         Delay(100);
         ((CNMLoadDlg *)m_pDlg)->SetRDemand(); 
         ((CNMLoadDlg *)m_pDlg)->GetSrcDlg()->SetFocus();
         break;                  
    case 8:         
         Delay(100);
         ((CNMLoadDlg *)m_pDlg)->SetRStatus();
         ((CNMLoadDlg *)m_pDlg)->GetSrcDlg()->SetFocus();
         break;                  
    case 9:         
         Delay(100);
         ((CNMLoadDlg *)m_pDlg)->SetRWarn();
         ((CNMLoadDlg *)m_pDlg)->GetSrcDlg()->SetFocus();
         break;                  

    case 10:   
         ((CNMLoadDlg *)m_pDlg)->GetSrcDlg()->SetFocus();
         ((CLODialog *)((CNMLoadDlg *)m_pDlg)->GetSrcDlg())->SetOkBtn();
         (((CNMLoadDlg *)m_pDlg)->GetSrcDlg())->PostMessage(WM_COMMAND,IDOK,0L);
         break;

    case 11:     
         (((CNMLoadDlg *)m_pDlg))->SetOkBtn();
	     SetKey(1);
	     CloseDlg(m_pDlg);    
	     Delay(500);
         m_pDlg = new CLoadStatusDlg(this);
         m_pDlg->ShowWindow(SW_SHOW);

//	     PostMessage(WM_COMMAND, ID_LOAD_STATUS);
         break;
   
    case 12: 
         if(m_pDlg)
           {
            (*nCase)--;
            break;
           }
         CloseWnd(m_pWnd);  
      /*   
         rect.SetRect(WinCxy.x+480,WinCxy.y+72,
	                  WinCxy.x+480+150,WinCxy.y+72+190);
	     StepMsg.SetPaintRect(rect);             
	     SetStepMsg(IDS_LOAD_FILE_STEP,1);
	     SetByUser(TRUE);
	     WriteMsg(IDS_SET_MAP_MSG2);   
        */
         break; 

    case 130: 
         if(EndCase(&bByUser,IDS_SET_MAP_TUT1,nCase))
	       {          
	        m_uNextCaseID=ID_CASE_SET_BP; 
	        RestoreBk(MS_STEP);
	        PostMessage(WM_COMMAND,ID_NEXT,0L);
           }
         break;
    default: 
	     SetNextAction(0);
	     RestoreBk(MS_STEP);
	     m_uNextCaseID=ID_CASE_SET_BP; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
   }    

 SetMouse(1);    
} 
/*-------------------------------------------------------------*/
/*                respond ID_FILE_LOAD msg                     */
/*-------------------------------------------------------------*/ 
void CMainFrame::OnFileLoad()
{
	// TODO: Add your command handler code here
	 if(m_uMenuAct!=ID_FILE_LOAD)
	   {
	    MessageBeep(-1);
	    return;
	   }      
	                      
	 m_pDlg=0;                           
	 if(bByUser)
	   {                                         
	    BOOL bOk;
	    CLoadFileDlg *p = new  CLoadFileDlg(this,1,&bOk);
	    p->DoModal();
	    if(bOk)
  	      PostMessage(WM_COMMAND,ID_LOAD_STATUS,0L);
	   } 
	 else
	   {                                               

	    CNMLoadDlg *p = new  CNMLoadDlg(this);
	    p->ShowWindow(SW_SHOW);
        
	   }

}

/////////////////////////////////////////////////////////////////////////////
// CLoadFileDlg dialog
static char BASED_CODE szFilter[] = 
    "OMF File(*.omf)|*.omf|UBROF File(*.a03)|*.a03|"
    "Hex File(*.hex)|*.hex|2500AD File(*.sym)|*.sym|Load File(*.*)|*.*||";


CLoadFileDlg::CLoadFileDlg(CWnd* pParent /*=NULL*/,BOOL bModal/*=1*/,BOOL *pbOk/*=0*/)
	: CFileDialog(TRUE, NULL, "*.omf",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
	              szFilter, pParent),m_bModal(bModal),m_pbOK(pbOk)
{       
//	  CFileDialog::Create(IDD,pParent);
       
 
	//{{AFX_DATA_INIT(CLoadFileDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

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

BEGIN_MESSAGE_MAP(CLoadFileDlg, CFileDialog)
	//{{AFX_MSG_MAP(CLoadFileDlg)
	ON_WM_NCLBUTTONDBLCLK()
	ON_WM_NCLBUTTONDOWN()
	ON_WM_NCLBUTTONUP()
	ON_WM_NCMOUSEMOVE()
	ON_COMMAND(IDC_LOAD_OK, OnLoadOk)
	ON_COMMAND(IDC_LOAD_OPTION, OnOption)
	ON_LBN_DBLCLK(IDC_LIST2, OnListDLK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CLoadFileDlg message handlers

void CLoadFileDlg::OnNcLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	
	//CFileDialog::OnNcLButtonDblClk(nFlags, point);
}

void CLoadFileDlg::OnNcLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	
//	CFileDialog::OnNcLButtonDown(nFlags, point);
}

void CLoadFileDlg::OnNcLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
//	CFileDialog::OnNcLButtonUp(nFlags, point);
}

void CLoadFileDlg::OnNcMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
//	CFileDialog::OnMouseMove(nFlags, point);
}

BOOL CLoadFileDlg::OnInitDialog()
{
	CFileDialog::OnInitDialog();
	

   	CRect  rectDlg;
	CPoint point(0,0);
	GetWindowRect(&rectDlg);
	GetParent()->ClientToScreen(&point);
	MoveWindow(point.x,point.y,rectDlg.Width(),rectDlg.Height());

	// TODO: Add extra initialization here                              
    CRect rectBtn;
    m_uFocus = SHOWFOCUSMSG;//only focus msg//CLOSEFOCUS;

    lstrcpy(m_szPath,((CMainFrame *)GetParent())->GetLoadFilePath());

    CButton *pOk=(CButton *) GetDlgItem(IDOK);//new CTButton();
    pOk->GetWindowRect(&rectBtn);
    pOk->DestroyWindow();
    
    rectBtn.left-=9;
    rectBtn.right-=9;
    rectBtn.top   -=65;//int(rectDlg.top-point.y);
    rectBtn.bottom-=65;//int(rectDlg.top-point.y);
    
    pEdit1      = new CTEdit(&m_uFocus,m_bModal,m_szPath,IDS_SET_MAP_EDIT1);
    pCancelBtn  = new CButton();
    pHelpBtn    = new CButton();
    pOptionBtn  = new CButton();
    pNetworkBtn = new CButton();
    pOkBtn      = new CButton();
    
    pEdit1->SubclassDlgItem(IDC_EDIT1,this); 
    pCancelBtn->SubclassDlgItem(IDCANCEL,this); 
    pOkBtn->Create("&Ok",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP|BS_PUSHBUTTON, rectBtn, 
                        this, IDC_LOAD_OK);

    rectBtn.top   +=65;//int(rectDlg.top-point.y);
    rectBtn.bottom+=65;//int(rectDlg.top-point.y);
    pHelpBtn->Create("&Help",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP|BS_PUSHBUTTON, rectBtn, 
                        this, IDC_HELP);

    rectBtn.top    +=30;
    rectBtn.bottom +=30;
    pOptionBtn->Create("&Options...",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP
                       |BS_PUSHBUTTON, rectBtn, this, IDC_LOAD_OPTION);

    rectBtn.top    +=30;
    rectBtn.bottom +=30;
    pNetworkBtn->Create("Network...",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP
                       |BS_PUSHBUTTON, rectBtn, this, IDC_LOAD_NETWORK);


     
	return TRUE;  // return TRUE  unless you set the focus to a control
}      
 
/*-------------------------------------------------------*/
/*         delete "new" control                          */
/*-------------------------------------------------------*/
void CLoadFileDlg::OnDelete()
{
	  FilterLMClk(0,0);
	
	 ((CMainFrame *)GetParent())->SetDlgWnd(0);
	 ((CMainFrame *)GetParent())->SetByUser(0);

	 ((CMainFrame *)(GetParent()))->RestoreBk(1);
	 ((CMainFrame *)(GetParent()))->RestoreBk(0);

	 delete pEdit1;
	 delete pOkBtn;
	 delete pOptionBtn;
	 delete pNetworkBtn;
	 delete pCancelBtn;
	 delete pHelpBtn;
	 
}     
/*--------------------------------------------------------*/
/*          check item                                    */
/*--------------------------------------------------------*/
BOOL CLoadFileDlg::Check()
{
 char szText[10];
 CString string;
 pEdit1->GetWindowText(string);
 string.MakeLower();
 string.MakeReverse();
 lstrcpyn(szText,string.GetBuffer(string.GetLength()),lstrlen("prime.omf")+1);
 
 if(((CMainFrame *)(AfxGetApp()->m_pMainWnd))->CheckOperation(szText,"fmo.emirp",IDS_SET_MAP_TUT2,1))
   return 1;
 else
   return 0;
}

void CLoadFileDlg::OnListDLK()
{
	// TODO: Add your command handler code here
	PostMessage(WM_COMMAND,IDC_LOAD_OK,0L);
}

/*--------------------------------------------------------*/
/*          exit diaog                                    */
/*--------------------------------------------------------*/
void CLoadFileDlg::OnCancel()
{  
   if(m_pbOK)
     *m_pbOK=0;

   m_uFocus=CLOSEFOCUS;
   OnDelete();
 
   /////////////////////////////////////////////////////////////////
   ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->SetByUser(FALSE);///
   CFileDialog::OnCancel();            
}


void CLoadFileDlg::OnLoadOk()
{
	// TODO: Add your command handler code here
   if(!Check())
     {
	  ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->SetNoteMsg(IDS_LOAD_FILE_EDIT1,1);
       return ;
     }

   if(m_pbOK)
     *m_pbOK=1;

   m_uFocus=CLOSEFOCUS;
   ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->RestoreBk(NOTEMSG);
   /////////////////////////////////////////////////////////////////
   ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->SetByUser(TRUE);///
   OnDelete();             
   CFileDialog::OnOK();
}

void CLoadFileDlg::OnOption()
{
	// TODO: Add your command handler code here
	//nTab,CDialog *pDlg,BOOL bChild,CWnd* pParent /*=NULL*/,BOOL bModal
	CLODialog *pDlg = new CLODialog(this);
	pDlg->ShowWindow(SW_SHOW);
}

/////////////////////////////////////////////////////////////////////////////
// CNMLoadDlg dialog
CNMLoadDlg::CNMLoadDlg(CWnd* pParent /*=NULL*/)
	: CTDialog(CNMLoadDlg::IDD, pParent,0)
{     

    m_pSrcDlg=0;
	//{{AFX_DATA_INIT(CNMLoadDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	if(!m_bModal)
	  Create(IDD,pParent);
}

void CNMLoadDlg::DoDataExchange(CDataExchange* pDX)
{
	CTDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNMLoadDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}
void CNMLoadDlg::SetOkBtn()
{
 pOkBtn->SetButtonDown(0);
 pOkBtn->SetState(0);
}                      

BEGIN_MESSAGE_MAP(CNMLoadDlg, CTDialog)
	//{{AFX_MSG_MAP(CNMLoadDlg)
	ON_COMMAND(IDC_LOAD_OPTION, OnLoadOption)
	ON_COMMAND(ID_CANCEL, OnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CNMLoadDlg message handlers

BOOL CNMLoadDlg::OnInitDialog()
{
	CTDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
        
        
    CRect rectBtn;

    lstrcpy(m_szPath,((CMainFrame *)GetParent())->GetLoadFilePath());

    CButton *pOk=(CButton *) GetDlgItem(IDOK);//new CTButton();
    pOk->GetWindowRect(&rectBtn);
    pOk->DestroyWindow();
    
    rectBtn.left-=9;
    rectBtn.right-=9;
    rectBtn.top   -=65;//int(rectDlg.top-point.y);
    rectBtn.bottom-=65;//int(rectDlg.top-point.y);
    
    pEdit1      = new CTEdit(&m_uFocus,m_bModal,m_szPath,IDS_SET_MAP_EDIT1);
    pCancelBtn  = new CTButton();
    pHelpBtn    = new CTButton();
    pOptionBtn  = new CTButton(0,1);
    pNetworkBtn = new CTButton();
    pOkBtn      = new CTButton();
    pStatic1    = new CTStatic(IDB_DIRECT,ST_BITMAP);
    pStatic2    = new CTStatic(IDB_DRIVE,ST_BITMAP);
    pStatic3    = new CTStatic(IDB_FILETYPE,ST_BITMAP);
    pStatic4    = new CTStatic(IDS_LOAD_FILE_TEXT1,ST_TEXT);
    
    pEdit1->SubclassDlgItem(IDC_EDIT1,this); 
    pCancelBtn->SubclassDlgItem(IDCANCEL,this);
    pStatic1->SubclassDlgItem(IDC_STATIC1,this);
    pStatic2->SubclassDlgItem(IDC_STATIC2,this);
    pStatic3->SubclassDlgItem(IDC_STATIC3,this);
    pStatic4->SubclassDlgItem(IDC_TEXT1,this);
    
    pOkBtn->Create("&Ok",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP|BS_PUSHBUTTON, rectBtn, 
                        this, IDC_LOAD_OK);

    rectBtn.top   +=65;//int(rectDlg.top-point.y);
    rectBtn.bottom+=65;//int(rectDlg.top-point.y);
    pHelpBtn->Create("&Help",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP|BS_PUSHBUTTON, rectBtn, 
                        this, IDC_HELP);

    rectBtn.top    +=30;
    rectBtn.bottom +=30;
    pOptionBtn->Create("&Options...",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP
                       |BS_PUSHBUTTON, rectBtn, this, IDC_LOAD_OPTION);

    rectBtn.top    +=30;
    rectBtn.bottom +=30;
    pNetworkBtn->Create("Network...",WS_VISIBLE|WS_TABSTOP|WS_CHILD|WS_GROUP
                       |BS_PUSHBUTTON, rectBtn, this, IDC_LOAD_NETWORK);

	return TRUE;  // return TRUE  unless you set the focus to a control
	
}
/*-------------------------------------------------------*/
/*              SetEditText                              */
/*-------------------------------------------------------*/
void CNMLoadDlg::SetEditText1()
{
 pEdit1->SetEditText("c:\\epsld52f\\prime.omf",IDS_LOAD_FILE_EDIT1,1);

}
void CNMLoadDlg::SetOptionBtn(BOOL bDown)
{
 pOptionBtn->SetButtonDown(bDown);
}

void CNMLoadDlg::OnDelete()
{

	 delete pEdit1;
	 delete pOkBtn;
	 delete pOptionBtn;
	 delete pNetworkBtn;
	 delete pCancelBtn;
	 delete pHelpBtn;
	 delete pStatic1;
	 delete pStatic2;
	 delete pStatic3;
	 delete pStatic4;
}     

void CNMLoadDlg::OnCancel()
{
	// TODO: Add your command handler code here 
	OnDelete();
	if(m_pSrcDlg)
	   m_pSrcDlg->PostMessage(WM_COMMAND,IDCANCEL,0L);
	CTDialog::OnCancel();
}

void CNMLoadDlg::OnLoadOption()
{
	// TODO: Add your command handler code here 
	m_pSrcDlg = new CLODialog(this);
    m_pSrcDlg->ShowWindow(SW_SHOW);
}

void CNMLoadDlg::SetRCodeMsg()
{
  m_pSrcDlg->SetRCodeMsg();
}        

void CNMLoadDlg::SetRSymbol()
{
 m_pSrcDlg->SetRSymbol();
}

void CNMLoadDlg::SetRDemand()
{
 m_pSrcDlg->SetRDemand();
}

void CNMLoadDlg::SetRStatus()
{
 m_pSrcDlg->SetRStatus();
}

void CNMLoadDlg::SetRWarn()
{
 m_pSrcDlg->SetRWarn();
}
                           
/////////////////////////////////////////////////////////////////////////////
// CLoadStatusDlg dialog


CLoadStatusDlg::CLoadStatusDlg(CWnd* pParent /*=NULL*/,BOOL bModal)
	: CTDialog(CLoadStatusDlg::IDD, pParent,bModal)
{

	//{{AFX_DATA_INIT(CLoadStatusDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
    if(!m_bModal)
	    Create(IDD,pParent);

	m_pBitmap = new CBitmap;
	m_pBitmap->LoadBitmap(IDB_STATUS);

}

void CLoadStatusDlg::DoDataExchange(CDataExchange* pDX)
{
	CTDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoadStatusDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}
                      
void CLoadStatusDlg::InitItem()
{
  pStatus = new CTStatic(0,ST_BITMAP,ST_TIME);
  pStatus->SubclassDlgItem(IDC_LOADPROG_STATUS,this);
  GetDlgItem(IDC_LOADPROG_FILE)->SetWindowText("d:\\ep-sld\\samples\\prime.omf");  
  GetDlgItem(IDC_LOADPROG_PC)->SetWindowText("0x0");  
  GetDlgItem(IDC_LOADPROG_LINE)->SetWindowText("25");  
  GetDlgItem(IDC_LOADPROG_FUNC)->SetWindowText("3");  
}

void CLoadStatusDlg::DeleteItem()
{
 delete  pStatus;
}
    
void CLoadStatusDlg::TimeCurMDL(int nTimes)
{ 
 if(nTimes != nTimes/2 *2)
   return;
 CString string;
 string.LoadString(IDS_LOADGRP_S1+(nTimes/2)-1);
 char szText[50];
 lstrcpy(szText,string.GetBuffer(string.GetLength()));
 GetDlgItem(IDC_LOADPROG_CURMDL)->SetWindowText(szText);  
}

void CLoadStatusDlg::TimeByte(int nTimes)
{       
 int nByte=62*nTimes;
 char szByte[50];
 itoa(nByte,szByte,10);
 GetDlgItem(IDC_LOADPROG_BYTE)->SetWindowText(szByte);  
}

void CLoadStatusDlg::TimeMDL(int nTimes)
{
 char szByte[50];
 itoa(nTimes,szByte,10);
 GetDlgItem(IDC_LOADPROG_MDL)->SetWindowText(szByte);  
}

void CLoadStatusDlg::TimeSYM(int nTimes)
{   
 int nByte=2*nTimes;
 char szByte[50];
 itoa(nByte,szByte,10);
 GetDlgItem(IDC_LOADPROG_SYM)->SetWindowText(szByte);  
} 

void CLoadStatusDlg::TimeType(int nTimes)
{  
 int nByte=14*nTimes;
 char szByte[50];
 itoa(nByte,szByte,10);
 GetDlgItem(IDC_LOADPROG_TYPE)->SetWindowText(szByte);  
}
     
void CLoadStatusDlg::LoadStatus(int nTimes)
{            
 int        nMapLength;
 BITMAP     bm;
 CRect      rectWin;
 CBitmap    *pMemBitmap = pStatus->GetBitmap();//new CBitmap;
 CDC        *pDesMemDC  = new CDC;
 CDC        *pSrcMemDC  = new CDC;
 CClientDC  dc(pStatus);
 
 if(pStatus->GetMovieStatus())
   pMemBitmap->DeleteObject();
   
 pStatus->SetMovieStatus(TRUE);
   
 m_pBitmap->GetObject(sizeof(BITMAP),&bm);
 pStatus->GetClientRect(&rectWin);
 nMapLength=int(long((long(rectWin.Width())*nTimes))/m_uCount);
 if(nMapLength<=10)
   return;
 
 pMemBitmap->CreateCompatibleBitmap(&dc,nMapLength,bm.bmHeight);
 pDesMemDC->CreateCompatibleDC(&dc);
 pSrcMemDC->CreateCompatibleDC(&dc);
 pDesMemDC->SaveDC();               
 pSrcMemDC->SaveDC();
 pDesMemDC->SelectObject(pMemBitmap);
 pSrcMemDC->SelectObject(m_pBitmap);
 pDesMemDC->BitBlt(0,0, 5,bm.bmHeight,pSrcMemDC,0,0,SRCCOPY);
 pDesMemDC->StretchBlt(5,0, nMapLength-10,bm.bmHeight,
                       pSrcMemDC,5,0,bm.bmWidth-10,bm.bmHeight,SRCCOPY); 
 pDesMemDC->BitBlt(nMapLength-5,0, 5,bm.bmHeight,pSrcMemDC,bm.bmWidth-5,0,SRCCOPY);
 pDesMemDC->RestoreDC(-1);
 pSrcMemDC->RestoreDC(-1);
 pStatus->InvalidateRect(rectWin);//Paint(pMemBitmap);
 pStatus->UpdateWindow();

 pMemBitmap->DeleteObject();
// delete pMemBitmap;
 pDesMemDC->DeleteDC();               
 pSrcMemDC->DeleteDC();

 delete pDesMemDC;
 delete pSrcMemDC;
}              

BEGIN_MESSAGE_MAP(CLoadStatusDlg, CTDialog)
	//{{AFX_MSG_MAP(CLoadStatusDlg)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CLoadStatusDlg message handlers

BOOL CLoadStatusDlg::OnInitDialog()
{    
    POINT WinCxy;
	CRect rectWin,rect;
	CTDialog::OnInitDialog();
	if(g_bAuto)
	{
	 g_mbCanDoNext=0;
	 AfxGetApp()->m_pMainWnd->KillTimer(IDAUTO);
	}
	GetWindowRect(&rectWin);
	WinCxy=((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetWinCxy();
	rect.left=WinCxy.x+(640-rectWin.Width())/2;
	rect.top=rectWin.top+40;
	rect.right=rect.left+rectWin.Width();
	rect.bottom=rect.top+rectWin.Height();
	MoveWindow(&rect);           
	///////////////////////////
	if(!m_bModal)//////////////
	   SetMouse(0);////////////
	           
	InitItem();                
	m_uCount=20;
	// TODO: Add extra initialization here
    SetTimer(TIMER2,100,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CLoadStatusDlg::OnTimer(UINT nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	static int times=0;
	times++;
    TimeCurMDL(times);
    TimeByte(times);
    TimeMDL(times);
    TimeSYM(times);
    TimeType(times);
	LoadStatus(times);

	if(times>int(m_uCount))
	  {        
	   KillTimer(TIMER2);
	   times=0;                
	   OnCancel();
	   //PostMessage(WM_COMMAND,IDOK,0L);
	  }
	CTDialog::OnTimer(nIDEvent);  
}

void CLoadStatusDlg::PostNcDestroy()
{            
  CTDialog::PostNcDestroy();
//  delete this;
  ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->ClearDlg();
	if(g_bAuto)
	{
	 g_mbCanDoNext=1;
	 AfxGetApp()->m_pMainWnd->SetTimer(IDAUTO,5000,NULL);
	}

}
void CLoadStatusDlg::OnCancel()
{
	// TODO: Add extra validation here

    m_pBitmap->DeleteObject();
    KillTimer(TIMER2);
    delete m_pBitmap;
	DeleteItem();
	SetMouse(1);////////////
	(AfxGetApp()->m_pMainWnd)->PostMessage(WM_COMMAND,ID_SHOW_SRC,0L);
	CTDialog::OnCancel();
	////////////////////////
} 

void CLoadStatusDlg::OnOK()
{
	// TODO: Add extra validation here

    m_pBitmap->DeleteObject();
    KillTimer(TIMER2);
    delete m_pBitmap;
	DeleteItem();
	CTDialog::OnOK();
	////////////////////////
	SetMouse(1);////////////                                        
    ///////////////////////////////////////////////////////////////
    //if(m_bModal)
    //((CMainFrame *)(AfxGetApp()->m_pMainWnd))->SetByUser(TRUE);///

	
}





