// varwnd.cpp : implementation file
//

#include "stdafx.h"    
#include "tutorial.h"
#include "srcwnd.h"
#include "varwnd.h"
#include "mainfrm.h"

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

static char *lpdVar[] ={"d = X:0036",
                        "d[0] = 1 (0x1)",
                        "d[1] = 2 (0x2)",
                        "d[2] = -15959 (0xc109)",
                        "d[3] = -7080 (0xe458)",
                        "d[4] = 17843 (0x45b3)",
                        "d[5] = -27619 (0x941d)",
                        "d[6] = -2913 (0xf49f)",
                        "d[7] = -2312 (0xa554)",
                        "d[8] = 23382 (0x5b56)",
                        "d[9] = -16193 (0xc0bf)",
                        "d[10] = 2322 (0x912)",
                        "d[11] = -24424 (0x9098)",
                        "d[12] = 21963 (0x55c6)",
                        "d[13] = 24729 (0x6099)",
                        "d[14] = -26311 (0x9939)",
                        "d[15] = -16378 (0xc006)",
                        "d[16] = 32389 (0x7e85)",
                        "d[17] = 24338 (0x5f12)",
                        "d[18] = 5446 (0x1546)",
                        "d[19] = 21686 (0x5466)"};

static char *lppVar[] ={"p = X:0004",
                        "p[0] = 1 (0x1)",
                        "p[1] = 2 (0x2)",
                        "p[2] = 16593 (0x40d1)",
                        "p[3] = 30064 (0x7570)",
                        "p[4] = 32597 (0x7f55)",
                        "p[5] = 2369 (0x941)",
                        "p[6] = -2850 (0xf4de)",
                        "p[7] = -24628 (0x9fcc)",
                        "p[8] = -4412 (0xeec4)",
                        "p[9] = -27584 (0x9440)",
                        "p[10] = 23070 (0x5a1e)",
                        "p[11] = -10929 (0xd54f)",
                        "p[12] = 4693 (0x1255)",
                        "p[13] = -19884 (0xb254)",
                        "p[14] = 1441 (0x3869)",
                        "p[15] = -2727 (0xf559)",
                        "p[16] = 13636 (0x3544)",
                        "p[17] = 29940 (0x74f4)",
                        "p[18] = 25009 (0x6161)",
                        "p[19] = 25656 (0x6438)"};               
/////////////////////////////////////////////////////////////////////////////
// CVARListBox

CVARListBox::CVARListBox()
{
   m_pointCaret.x=0;
   m_pointCaret.y=0;

}

CVARListBox::~CVARListBox()
{
}
void CVARListBox::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
	// TODO: Add your message handler code here and/or call default
	TEXTMETRIC tm;
	CClientDC dc(this);
	dc.GetTextMetrics(&tm);
	lpMeasureItemStruct->itemHeight=tm.tmHeight+2;
}


BEGIN_MESSAGE_MAP(CVARListBox, CListBox)
	//{{AFX_MSG_MAP(CVARListBox)
	ON_WM_KILLFOCUS()
	ON_WM_KEYDOWN()
	ON_WM_SETFOCUS()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CVARListBox message handlers
void CVARListBox::OnKillFocus(CWnd* pNewWnd)
{
	CListBox::OnKillFocus(pNewWnd);
	
	// TODO: Add your message handler code here
	HideCaret();
}

void CVARListBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	// TODO: Add your message handler code here and/or call default
	CRect rect;
	GetClientRect(&rect);
	switch(nChar)
	 {
	  case VK_UP:                               
	       m_pointCaret.y--;  
	       break;
	  case VK_DOWN:       
	       m_pointCaret.y++;
	       break;
	  case VK_LEFT:    
	       m_pointCaret.x--;
	       break;
	  case VK_RIGHT:      
	       m_pointCaret.x++;
	       break;
	  case VK_HOME:      
	       m_pointCaret.x=0;
	       break;
	  case VK_END:        
	       m_pointCaret.x=rect.Width();         
	       break;                          
	  default:
	       break;
	  
	 }       
	
	m_pointCaret.x=(max(0,min(m_pointCaret.x,rect.Width()/8)));
	m_pointCaret.y=max(0,min(m_pointCaret.y,rect.Height()/13)); 
	POINT point=m_pointCaret;
	point.x =m_pointCaret.x*8;
	point.y =m_pointCaret.y*13;
	SetCaretPos(point); 
	
	CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CVARListBox::OnSetFocus(CWnd* pOldWnd)
{
	CListBox::OnSetFocus(pOldWnd);
	
	// TODO: Add your message handler code here
	CreateSolidCaret(2,13);    
	ShowCaret();          

	POINT p;
	p.x=0;
	p.y=0;
	SetCaretPos(p);
	
}

///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void CMainFrame::OnWindowVariable()
{
	// TODO: Add your command handler code here
// if(!bByUser)
     
     CVarWnd *pVarWnd= new CVarWnd(IDR_VARIABLE,6,ST_TUTORIAL);
     m_pVarWnd=pVarWnd;
  
/*
 else
  {
     CVarWnd *pVarWnd= new CVarWnd(IDR_VARIABLE,6,ST_NOTTUTORIAL);
     pVarWnd->ShowWindow(SW_SHOW);
  } 
 
*/	
}

/////////////////////////////////////////////////////////////////////////////
// CVarWnd

CVarWnd::CVarWnd(UINT idMenu,UINT idSub,BOOL bTutorial,BOOL bSetByUser/*=TRUE*/)
        :CTWnd(idMenu,idSub,bTutorial,bSetByUser)
{   
  int nBuffer[]  ={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67};
  Create(  NULL,//m_sClassName.GetBuffer(m_sClassName.GetLength()),
	      "Variable",             //Window Name
	       WS_OVERLAPPEDWINDOW|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS);
  for(int i=0;i<20;i++)
  	  m_nVar[i]=nBuffer[i];     

  m_Var.bDVar=0;
  m_Var.bPVar=0;
  m_Var.lpItemT1[0]=0;
  m_Var.lpItem1=0;
  m_Var.lpItemT2[0]=0;
  m_Var.lpItem2=0;
   
  m_pBitOpen =new CBitmap;
  m_pBitSOpen=new CBitmap;
  m_pBitClose=new CBitmap;
  m_pBitOpen->LoadBitmap(IDB_OPEN);
  m_pBitSOpen->LoadBitmap(IDB_SOPEN);
  m_pBitClose->LoadBitmap(IDB_CLOSE);
}

CVarWnd::~CVarWnd()
{   
 m_pBitOpen->DeleteObject();
 delete  m_pBitOpen;
 m_pBitSOpen->DeleteObject();
 delete  m_pBitSOpen;
 m_pBitClose->DeleteObject();
 delete  m_pBitClose;
}

BOOL CVarWnd::FindItem(DRAWITEMSTRUCT dis,LPSTR lpText)
{
 if(m_Var.lpItemT1[0]==0)
   {*lpText=0;
    return 0;}
 else
 if(dis.itemID==0)
   {lstrcpy(lpText,m_Var.lpItemT1);
    return 1;}
 else
 if(m_Var.lpItem1)  
   {if(dis.itemID>=1 && dis.itemID<=20)
	 {lstrcpy(lpText,m_Var.lpItem1[dis.itemID]);
	  return 0;}
   else
   if(dis.itemID==21)
	 {lstrcpy(lpText,m_Var.lpItemT2);
	  return 1;}
   else
   if(dis.itemID<=41 && m_Var.lpItem2)
	 {lstrcpy(lpText,m_Var.lpItem2[dis.itemID-21]);
	  return 0;}
   else
     {*lpText=0;
      return 0;}}// if(m_Var.lpItem1)  	  
 else            
 if(m_Var.lpItemT2==0)	  
   {*lpText=0;
    return 0;}
 else
   if(dis.itemID==1)
     {lstrcpy(lpText,m_Var.lpItemT2); 
      return 1;}
   else
   if(m_Var.lpItem2 && dis.itemID<=21)
	 {lstrcpy(lpText,m_Var.lpItem2[dis.itemID-1]);
	  return 0;}

 *lpText=0;
 return 0;
}
 
BOOL CVarWnd::AddItem(int nSnd)//1 d, 2 p
 {
  if(nSnd==1)
   {if(m_Var.bDVar)
      {MessageBox(" d Same as previous!","EasyPack/SLD",
                  MB_OK|MB_ICONEXCLAMATION);
       return 0;}
    if(m_Var.lpItemT1[0]==0)
      {lstrcpy(m_Var.lpItemT1,lpdVar[0]);
       m_Var.bDVar=1;     
       UpdateItem(0);
       return 1;} 
    else                     
    if(m_Var.lpItemT2[0]==0)
      {lstrcpy(m_Var.lpItemT2,lpdVar[0]);
       m_Var.bDVar=1;
       UpdateItem(0);
       return 1;} 
   }    
  else   
  {if(m_Var.bPVar)
    {MessageBox(" p Same as previous!","EasyPack/SLD",
                  MB_OK|MB_ICONEXCLAMATION);
       return 0;}
   if(m_Var.lpItemT1[0]==0)     
    {lstrcpy(m_Var.lpItemT1,lppVar[0]);
     m_Var.bPVar=1;
     UpdateItem(0);
     return 1;}   
   else   
   if(m_Var.lpItemT2[0]==0)
      {lstrcpy(m_Var.lpItemT2,lppVar[0]);
       m_Var.bPVar=1;
       UpdateItem(0);
       return 1;} 
 }   

 return 0; 
} 

void CVarWnd::UpdateItem(int nCSel)
{
 int nCount=0;
 m_pListVar->ResetContent();
 if(lstrlen(m_Var.lpItemT1))
    nCount++;
 if(lstrlen(m_Var.lpItemT2))
    nCount++;
 if(m_Var.lpItem1)
    nCount += 20;
 if(m_Var.lpItem2)
    nCount += 20;
 for(int i=0; i<nCount;i++)
    m_pListVar->AddString("");

 m_pListVar->SetCurSel(nCSel);
    
}

BEGIN_MESSAGE_MAP(CVarWnd, CTWnd)
	//{{AFX_MSG_MAP(CVarWnd)
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_WM_SIZE()
	ON_WM_PAINT()
	ON_WM_DRAWITEM()
	ON_WM_MEASUREITEM()
	ON_COMMAND(ID_VARIABLE_ADD, OnVariableAdd)
	ON_WM_SETFOCUS()
	ON_LBN_DBLCLK(IDD,OnLBNDBLClk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVarWnd message handlers      
void CVarWnd::OnLBNDBLClk()
{
 int nCSel=m_pListVar->GetCurSel();
 if(m_Var.lpItemT1[0]==0)
    return;

 if(nCSel==0)
   if(m_Var.lpItem1==0)
      {if(lstrcmp(m_Var.lpItemT1,lpdVar[0])==0)
          m_Var.lpItem1=lpdVar;
       else
          m_Var.lpItem1=lppVar;
       UpdateItem(nCSel);}
   else       
   {m_Var.lpItem1=0;
    UpdateItem(nCSel);}
 else
 if(m_Var.lpItem1)
   if(nCSel==21 && m_Var.lpItem2==0)
      {if(lstrcmp(m_Var.lpItemT1,lpdVar[0])==0)
          m_Var.lpItem1=lpdVar;
       else
          m_Var.lpItem1=lppVar;
      UpdateItem(nCSel);}
   else      
   if(m_Var.lpItem2)
     {m_Var.lpItem2=0;                  
      UpdateItem(nCSel);}
   else
   MessageBeep(-1);
 else   
   if(nCSel==1 && m_Var.lpItem2==0)
     { if(lstrcmp(m_Var.lpItemT2,lpdVar[0])==0)
          m_Var.lpItem2=lpdVar;
       else
          m_Var.lpItem2=lppVar;
       UpdateItem(nCSel);}
   else
   if(m_Var.lpItem2)
     {m_Var.lpItem2=0;
      UpdateItem(nCSel);}
   else
   MessageBeep(-1);
      
}

void CVarWnd::OnVariableAdd()
{
	// TODO: Add your command handler code here
 UINT ID=((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetMenuAct();
 if(ID !=   UINT(ID_WINDOW_VARIABLE | ID_VARIABLE_ADD))
   {
    MessageBeep(-1);
    return;
   }            

 if(!((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetByUser())
   { ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->                          
     SetPaintDO(0);
     CVarAddDlg *pDlg = new CVarAddDlg(this,0,0,0);
     pDlg->ShowWindow(SW_SHOW);
   }  
 else
  {
     CVarAddDlg *pDlg = new CVarAddDlg(this,1,0,0);
     pDlg->DoModal();
  } 

}

int CVarWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CTWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here                   
	POINT point=((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetWinCxy();
	m_pListVar = new CVARListBox;
	m_pListVar->Create(WS_CHILD|WS_VISIBLE|WS_VSCROLL|
	                   LBS_NOTIFY|
	                   LBS_NOINTEGRALHEIGHT|
	                   LBS_OWNERDRAWFIXED,
	               rectDefault,this,IDD);
	if(!m_pListVar)               
	  {
	   TRACE("Can not create listBox!");
	   return -1;
	  }    
	m_pListVar->ShowWindow(SW_SHOW);  
	MoveWindow(point.x+332,point.y,301,193);
	((CMainFrame *)(AfxGetApp()->m_pMainWnd))->
	m_nVariableWnd=ID_WINDOW_VARIABLE;
	return 0;
}

void CVarWnd::OnDestroy()
{
	CTWnd::OnDestroy();                        
	// TODO: Add your message handler code here
	((CMainFrame *)(AfxGetApp()->m_pMainWnd))->
	m_nVariableWnd=0;
	if(m_pListVar)
	   delete m_pListVar;
	
}             

void CVarWnd::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
    DrawStatus(dc);//draw status bar                
}

void CVarWnd::DrawStatus(CPaintDC &dc)
{              
 dc.SaveDC();                    
     CPen   Pen(PS_SOLID,2,RGB(0,0,0));
     CBrush brush(RGB(192,192,192));
     dc.SelectObject(&brush);
     
	 CRect VarRect;
	 CRect rect;
	 GetClientRect(&VarRect);
	 rect.left   = 0;
	 rect.top    = VarRect.bottom-25;
	 rect.right  = rect.left+VarRect.Width();
	 rect.bottom = VarRect.bottom;
	 dc.Rectangle(&rect);
	 dc.SelectObject(&Pen); 
	 dc.MoveTo(rect.left,rect.top+1);
	 dc.LineTo(rect.right,rect.top+1); 
 dc.RestoreDC(-1);	      
 
 DrawRectangle(dc,rect);
}

void CVarWnd::DrawRectangle(CPaintDC &dc,CRect rect)
{
 // type bar          
 dc.SaveDC();
 char szAdr[]  ="Address:";
 char szType[] ="Type:";
 
 int nAddress=dc.GetTextExtent(szAdr,lstrlen(szAdr)).cx+20;
 int nType=dc.GetTextExtent(szType,lstrlen(szType)).cx+20;
 
 CPen GrayPen(PS_SOLID,1,RGB(128,128,128));
 CPen WhitePen(PS_SOLID,1,RGB(255,255,255));
 CPen *pOldPen;
 
  // adrress bar
 
 m_AddressRect.left   = rect.left+nAddress;
 m_AddressRect.top    = rect.top+3;
 m_AddressRect.bottom = rect.bottom-3;
 m_AddressRect.right  = rect.Width()*10/24;                  
                     	
 pOldPen=dc.SelectObject(&GrayPen);                   
 dc.MoveTo(m_AddressRect.left,m_AddressRect.bottom);                   
 dc.LineTo(m_AddressRect.left,m_AddressRect.top);
 dc.LineTo(m_AddressRect.right,m_AddressRect.top);
  
 dc.SelectObject(&WhitePen);                   
 dc.LineTo(m_AddressRect.right,m_AddressRect.bottom);
 dc.LineTo(m_AddressRect.left,m_AddressRect.bottom);
  
 //Type bar                      
 
  m_TypeRect.SetRect( m_AddressRect.right+nType, 
	                 rect.top+3,
	                 rect.right-5,
	                 rect.bottom-3);   
  
  dc.SelectObject(&GrayPen);                   
  dc.MoveTo(m_TypeRect.left,m_TypeRect.bottom);                   
  dc.LineTo(m_TypeRect.left,m_TypeRect.top);
  dc.LineTo(m_TypeRect.right,m_TypeRect.top);
   
  dc.SelectObject(&WhitePen);                   
  dc.LineTo(m_TypeRect.right,m_TypeRect.bottom);
  dc.LineTo(m_TypeRect.left,m_TypeRect.bottom);
  
 // restore  system default pen       
  dc.SelectObject(pOldPen);
  dc.RestoreDC(-1);  
  WriteBarTitle(dc,rect,m_AddressRect,m_TypeRect);      
}
        
void CVarWnd::WriteBarTitle(CPaintDC &dc,
                            CRect    rect,
                            CRect    AddressRect,
                            CRect    TypeRect)
{                
 dc.SaveDC();
 
 TEXTMETRIC tm;
 dc.GetTextMetrics(&tm); 
 char szAddress[]="Address:";
 char szType[]="Type:";    
 
 int yChar=tm.tmHeight;
 int xChar=tm.tmAveCharWidth;
 CRect m_Adr,m_Type;
 m_Adr.SetRect(rect.left+1,AddressRect.top,AddressRect.left-1,AddressRect.bottom);
 m_Type.SetRect(AddressRect.right+1,TypeRect.top,TypeRect.left-1,TypeRect.bottom);     
 dc.SetBkMode(TRANSPARENT);       
 dc.DrawText(szAddress,lstrlen(szAddress),m_Adr,DT_CENTER|DT_VCENTER);
 dc.DrawText(szType,lstrlen(szType),m_Type,DT_CENTER|DT_VCENTER);
 
 dc.RestoreDC(-1);
}
        

void CVarWnd::OnSize(UINT nType, int cx, int cy)
{
	CTWnd::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(m_pListVar)
	   m_pListVar->MoveWindow(0,0,cx,cy-25);
}



void CVarWnd::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// TODO: Add your message handler code here and/or call default
//	CTWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
    LPDRAWITEMSTRUCT dis=lpDrawItemStruct;
      
 if(dis->itemAction &(ODA_DRAWENTIRE))// | ODA_SELECT)) 
   {
    CDC   dc;
    CRect rectText;
    CBitmap *pBitmap;
    const int nWBit = 20;
    int nCX;
    CDC  *pDC=dc.FromHandle(dis->hDC);
    char szText[100];                 
    BOOL bFather=FindItem(*lpDrawItemStruct,szText);
    if(szText[0]==0)
      return;
    if(bFather)
        rectText.SetRect(dis->rcItem.left+4+nWBit,
                         dis->rcItem.top,
                         dis->rcItem.right,
                         dis->rcItem.bottom);
    else                     
        rectText.SetRect(dis->rcItem.left+14+nWBit,
                         dis->rcItem.top,
                         dis->rcItem.right,
                         dis->rcItem.bottom);      
    if(bFather)
      { nCX = 3;
        if(m_Var.bDVar || m_Var.bPVar)
          pBitmap=m_pBitOpen;
        else
          pBitmap=m_pBitClose;}                     
    else
     { pBitmap=m_pBitSOpen;
       nCX=17;}               
///////////////////////////////////////////////////////////       
    BITMAP bm;                     
    CDC  SrcDC; 
    pBitmap->GetObject(sizeof(BITMAP),&bm);
    SrcDC.CreateCompatibleDC(pDC); 
    SrcDC.SelectObject(pBitmap);
    pDC->BitBlt(nCX,dis->rcItem.top,bm.bmWidth,bm.bmHeight,
                &SrcDC,0,0,SRCCOPY);  
    pDC->SetBkMode(TRANSPARENT);                     
    pDC->DrawText(szText,lstrlen(szText),&rectText,DT_LEFT);                      
    SrcDC.DeleteDC();
    SetStatus(1,1);  
  }  
}
void CVarWnd::SetStatus(BOOL bSet,BOOL bFirst)
{ 
 CClientDC dc(this);
 CRect rectAdr  =m_AddressRect;
 CRect rectType =m_TypeRect;
 rectAdr.left++;
 rectAdr.right--;
 rectAdr.top++;
 rectAdr.bottom--;
 rectType.left++;
 rectType.right--;
 rectType.top++;
 rectType.bottom--;
 if(!bSet)
   { CBrush brush(RGB(192,192,192));
     dc.FillRect(&rectAdr,&brush);
     dc.FillRect(&rectType,&brush);}
 else
   { char szText[20];
     dc.SetBkMode(TRANSPARENT);
     dc.DrawText("signed int",-1,&rectType,DT_LEFT);
     if(bFirst)
       lstrcpy(szText,"X:0036");
     else  
       lstrcpy(szText,"X:0004");
     dc.DrawText(szText,-1,&rectAdr,DT_LEFT);}  
}                                        

void CVarWnd::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
	// TODO: Add your message handler code here and/or call default
	m_pListVar->MeasureItem(lpMeasureItemStruct);
//	CTWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

void CVarWnd::OnSetFocus(CWnd* pOldWnd)
{
	CTWnd::OnSetFocus(pOldWnd);
	m_pListVar->SetFocus();
	// TODO: Add your message handler code here
	
}

/////////////////////////////////////////////////////////////////////////////
// CVarAddDlg dialog


CVarAddDlg::CVarAddDlg(	CWnd* pParent,
				        BOOL bModal,
				        BOOL bChild,
				        BOOL bSetByUse)	// standard constructor
	: CTDialog(CVarAddDlg::IDD, pParent,bModal,bChild,bSetByUse)
{
	//{{AFX_DATA_INIT(CVarAddDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT           
	if(!m_bModal)
	  Create(IDD,pParent);
}

void CVarAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CTDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVarAddDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}
void CVarAddDlg::SetCombo()
{
 m_pAddVar->SetCombo(0,IDS_VARIABLE_COMBO,0);
}
                           
void CVarAddDlg::SetOk()
{ 
 m_pOk->SetButtonDown(0);
 m_pOk->SetState(0);
 PostMessage(WM_COMMAND,IDOK);
}
                           
BEGIN_MESSAGE_MAP(CVarAddDlg, CTDialog)
	//{{AFX_MSG_MAP(CVarAddDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CVarAddDlg message handlers

BOOL CVarAddDlg::OnInitDialog()
{
	CTDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_uFocus=CLOSEFOCUS;
	CRect rect;
	GetWindowRect(&rect);
	MoveWindow(80,150,rect.Width(),rect.Height());
    m_pAddVar = new CTComboBox(&m_uFocus,m_bModal,0,0);
    m_pAddVar->SubclassDlgItem(IDC_COMBO_ADDVARIABLE_VARIABLE,this);

    m_pOk    = new CTButton(NULL,0,0);
    m_pOk->SubclassDlgItem(IDOK,this); 
/*	             
	m_pAddVar->ResetContent();
	m_pAddVar->AddString("");
	m_pAddVar->AddString("d");             
	m_pAddVar->AddString("p");
*/
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CVarAddDlg::OnCancel()
{
	// TODO: Add extra cleanup here
	delete m_pAddVar;
	delete m_pOk;
	CTDialog::OnCancel();
}

void CVarAddDlg::OnOK()
{
	// TODO: Add extra validation here
	int nIdx;
	char szText[10];
	m_pAddVar->GetWindowText(szText,8);
	if(*szText!='d' && *szText!='p')
	  {
	   MessageBox("IIIegal Variable.","EasyPack/SLD",MB_OK|MB_ICONEXCLAMATION);
	   m_pAddVar->SetFocus();
	   return;
	  }
    CVarWnd *pVarWnd =(CVarWnd *)(
                       ((CMainFrame *)
                        (AfxGetApp()->m_pMainWnd)))->GetWnd();
    if(*szText=='d')
       nIdx=1;
    else
       nIdx=2;
    if(!pVarWnd->AddItem(nIdx))    
	   MessageBeep(-1);
	delete m_pAddVar;
	delete m_pOk;
	CTDialog::OnOK();
}


