Thursday, November 5, 2009

Code for Simple Text Editor Which We have done in Class

FileName : TextandFontView.h
class CTextandFontView : public CView
{
...
public:
  CString str[10];
....
};

FileName : TextandFontView.cpp

Global variable:
      int x=0,y=0,i=0;

void CTextandFontView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    // TODO: Add your message handler code here and/or call default
    CClientDC *pDC = new CClientDC (this);
    pDC->SetBkColor (RGB(100,100,0));
    pDC->SetBkMode (TRANSPARENT);
        CFont ft;
    ft.CreatePointFont (100,"Arial");
    pDC->SelectObject(&ft);
   
    if(nChar==VK_BACK)
    {
     RedrawWindow ();
     if(str[i].IsEmpty ())
     {
         i--;
         y-=20;
     }
     for(int j=0;j
     {
        pDC->TextOut (x,j*20,str[j]);
     }
      
     str[i]=str[i].Mid (0,str[i].GetLength()-1);
     pDC->TextOut (x,y,LPCTSTR(str[i]),str[i].GetLength());
    }
    else if(nChar==VK_RETURN)
    {
        y+=20;
        i++;
        pDC->TextOut(x,y,str[i]);
       
    }
    else
    {
    RedrawWindow ();
   
    for(int j=0;j
    {
        pDC->TextOut (x,j*20,str[j]);
    }
         str[i]+=nChar;
   
        pDC->TextOut (x,y,str[i]);
    }

    CView::OnChar(nChar, nRepCnt, nFlags);
}



 

No comments:

Post a Comment