Click here to Skip to main content
11,790,021 members (41,317 online)
Click here to Skip to main content


, 14 Feb 2001 95K 2.8K 24
Rate this:
Please Sign up or sign in to vote.
Display Chinese & Japanese characters on unicode & non-unicode systems
<!-- Link to source file download -->
  • Download source files - 51 Kb
  • <!-- Link to demo file download -->
  • Download demo project - 39 Kb
  • <!-- Article image -->

    Sample Image - KanjiFont_Demo.jpg

    <!-- Add the rest of your HTML here -->


    As you may know, Windows 2000 and Windows NT contain natural support Unicode, and can make use of the Windows API functions for displaying and using wide characters. However, the behavior of those API functions is not always completely the same between NT and 2000. Furthermore, under Windows 95 & 98 Unicode character functions are not supported at all.

    This makes it very frustrating for a developer to create an application that needs to display such characters. Recently, I needed to write a small Japanese dictionary for myself. This article contains the small set of classes that encapsulate some simple character translations and the methods for displaying Unicode characters reliably on Windows95/98/NT/2000 to solve this problem. I based my code on some older code done by Glen Rosenthal who wrote JWPce (a very nice Japanese text editor) and on an MSDN article that had some dated examples of a similar solution (Q241020).

    Basically, all TrueType fonts contain encoding tables based on the Unicode mappings for the characters those fonts contain. Microsoft distributes a few large fonts with MS Office and with newer version of Internet Explorer that contain characters or 'glyphs' for many different globale regions. Normally, a device context will do the translation from character code to glyph index for the systems locale when you call the TextOut or the ExtTextOut functions. This does not work on non-Unicode versions of Windows, and it does not work on some configurations for systems that are Unicode compatible. So in order to display the character you want on all version of windows you have to calculate the index of the 'glyph' within the true type font for the charcter code you want to display. Then a call to the ExtTextOut API function will allow you to display the 'glyph' you have selected; so long as it is present in the selected font.

    These classes provide a simple set of objects to easily use a true type font that contains glyphs foreign to your system locale, as well as some character code translation objects. To assist in debugging and just generally getting used to seeing Unicode character codes; most programmers are used to ASCII. I've included some iostream manipulators that allow you to easily translate character codes from one encoding format to another.

    If you have any enhancements or improvements, please let me know and the source can be updated here.


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Eric Crahen
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    QuestionDoes it work for arabic? Pin
    venomelektro28-Mar-05 8:07
    membervenomelektro28-Mar-05 8:07 
    GeneralThe correct character position. Pin
    James Cao28-Sep-04 12:12
    memberJames Cao28-Sep-04 12:12 

    This is a very good project. If you can calculate the current position for next new character, the project will be nicer. To display several characters vertically will be even better.

    This is the statement with hard code 20 units as the width of any character as follows:
    m_kanjiFont.DrawGlyph(m_KanjiLabel.GetDC()->GetSafeHdc(), 0x2434, 20, 0);
    As a result, several characters are displayed too close each other.
    I will send you updated version to provide the correct values, when I finish more code in future.



    James Cao
    QuestionHow can I know which kind of font is suitable to a string? Pin
    charcoalc29-Feb-04 19:33
    membercharcoalc29-Feb-04 19:33 
    Questionhow about GetCharacterPlacementA? Pin
    diamant22-Dec-03 2:45
    memberdiamant22-Dec-03 2:45 
    GeneralRegarding Kanji fonts Pin
    Leela Prasanna Kumar21-Nov-02 23:14
    sussLeela Prasanna Kumar21-Nov-02 23:14 
    QuestionAlso in the title caption bar? Pin
    Pep27-May-02 2:19
    memberPep27-May-02 2:19 
    Generalnewbie question Pin
    Arthur Chen12-May-01 11:05
    memberArthur Chen12-May-01 11:05 
    QuestionWhy not simply use ExtTextOutW? Pin
    Peter Kenyon27-Aug-00 12:25
    sussPeter Kenyon27-Aug-00 12:25 
    AnswerRe: Why not simply use ExtTextOutW? Pin
    Eric Crahen29-Aug-00 3:25
    sussEric Crahen29-Aug-00 3:25 
    GeneralRe: Why not simply use ExtTextOutW? Pin
    Peter29-Aug-00 13:27
    sussPeter29-Aug-00 13:27 
    GeneralRe: Why not simply use ExtTextOutW? Pin
    Brian Peterson29-Aug-00 13:48
    sussBrian Peterson29-Aug-00 13:48 
    GeneralRe: Why not simply use ExtTextOutW? Pin
    Md. Nura Azom Lipon4-Jan-03 3:16
    memberMd. Nura Azom Lipon4-Jan-03 3:16 
    GeneralGood work, but we need more! Pin
    Paul Selormey26-Aug-00 9:40
    sussPaul Selormey26-Aug-00 9:40 
    GeneralRe: Good work, but we need more! Pin
    Eric Crahen29-Aug-00 3:23
    sussEric Crahen29-Aug-00 3:23 
    GeneralLibrary Rocks! Pin
    tyson25-Aug-00 16:25
    susstyson25-Aug-00 16:25 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.1509028.1 | Last Updated 15 Feb 2001
    Article Copyright 2000 by Eric Crahen
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid