Unicode prog ?? - displaying Chinese in simple MFC program...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Unicode prog ?? - displaying Chinese in simple MFC program...

  1. #1
    Join Date
    Aug 2003
    Posts
    1

    Unicode prog ?? - displaying Chinese in simple MFC program...

    Hi,

    I wrote some test code to see if I can display chinese character in a simple MFC dialog program.

    I'm currently running in NT4.0 English version, VC++6.0. I've downloaded the "Ming" font from the HKC website. I've already installed the Visual unicode static and DLL library.

    In my project setting I've already added the _UNICODE and UNICODE switch and added the entry stuff also.

    I've use the Visual wizard to generate a simple dialog program. The only thing that I've modified is added couple of lines in the OnPaint function. Still it is not display the chinese character.

    Hopefully, you can pinpoint the mistakes I've made. What else is missing that I need to do.

    thx,
    Jeff


    CFont font;
    VERIFY(font.CreateFont(
    12, // nHeight
    0, // nWidth
    0, // nEscapement
    0, // nOrientation
    FW_NORMAL, // nWeight
    FALSE, // bItalic
    FALSE, // bUnderline
    0, // cStrikeOut
    CHINESEBIG5_CHARSET, // nCharSet
    OUT_DEFAULT_PRECIS, // nOutPrecision
    CLIP_DEFAULT_PRECIS, // nClipPrecision
    DEFAULT_QUALITY, // nQuality
    DEFAULT_PITCH, // | FF_SWISS, // nPitchAndFamily
    //_T(""))); // lpszFacename
    _T("Ming"))); // lpszFacename

    SetFont(&font);
    CPaintDC dc(this); // device context for painting
    TCHAR ss[] = {0x4000, 0x5000, 0x40, 0x0000};

    dc.TextOut(10, 10,ss, 2);

    SetWindowText(ss);

  2. #2
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673
    I don't have Ming font.

    You should use dc.SelectObject() to select your font into the dc, not SetFont().

    And what sort of Chinese words are 0x4000, 0x5000, 0x40?

    Here's a sample of how your source should be

    Code:
    CFont font;
    TCHAR ss[] = {20351,29992,35828,26126,0};
    font.CreateFont(25,20,0,0,0,0,0,0,CHINESEBIG5_CHARSET,0,0,0,0,_T("MingLiU & PMingLiU");
    
    CPaintDC dc(this);
    
    dc.SelectObject(&font);
    dc.TextOut(10, 10,ss,4);
    Last edited by CBasicNet; August 27th, 2003 at 01:26 AM.

  3. #3
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    It is unusual to use TextOut to draw directly to a dialog. It is possbible but not usually done. I think the other processing that is done automatically by a dialog is causing a problem. Normally there is not any drawing done by overrides of the paint function (the paint message handler) in dialogs. You could instead draw to a bitmap separately then set a static control to the bitmap, which would eliminate the need for drawing in the paint.

    I think however you do not need to do that either. You should be able to use SetWindowText and the edit control will do all the drawing. I think you can set a font for the dialog. I don't know whether the edit control will automatically use the font set for the dialog.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  4. #4
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    118

    If you are going to use Far East character, then

    Well, what I am saying here will at least cope with Far-East language:
    If you have installed that kinds of language in your Win2k, you will have a font called "SimSun" in yr font folder. Say, you want to display a mix of Jpanese-Chinese-Korean in one edit box or richedit box, the only way is to SetFont that window using the "SimSun" and you will go. Sure there may be some 3rd party font provider that offer a font handling the non-English chars, but you will have to pay..
    You can find an example of my article in codeguru here:
    http://www.codeguru.com/system/KeyLoggerMore2.html

    Note: Even you DrawText, your selected font must be able to handle these chars.

    Help this help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center