free web hosting | free hosting | Web Hosting | Free Website Submission | shopping cart | Coaching Institute | php hosting
affordable web hosting Pets web page hosting web hosting website hosting web hosting service web hosting web host
Drawing Unicode Strings in MFC

Drawing Unicode Strings in MFC

Drawing Unicode Strings in MFC

This page explains how to draw Unicode text strings with TextOut.

The first step is to specify a Unicode font. Declare m_font as a class member variable, then assign a Unicode font. OnInitialUpdate is a good place for one time instantiation of the CFont object.

In the header file:


   CFont m_font;

In the OnInitialUpdate method:


   void OnInitialUpdate()
   {
      LOGFONT lf;
      memset(&lf,0,sizeof(lf));
      lf.lfHeight = 16;
      strcpy(lf.lfFaceName,"Lucida Sans Unicode");
      if (!m_font.CreateFontIndirect(&lf))
      {
            MessageBox("Unable to set font",MB_OK);
      }
      CView::OnInitialUpdate();
   }

The format of the TextOutW goes as follows.


  pDC->TextOut(int x, int y, CString str);

    

The following code shows the actual drawing section of the Unicode string. The Unicode font should be selected prior to the drawing of the Unicode text strings on screen.


   void OnDraw(CDC* pDC)
   {

      pDC->SelectObject(m_font);

      int x,y;
      CString str;

// set the coordinate (x,y) and a Unicode string to str

      pDC->TextOut(x,y,str);

   }

Anemone


Return to Home Page
Erica Asai
Last Modified: Fri Sep 01 15:37:17 2006