Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to display a simple Unicode string in an MFC view class. The problem can be simplified to the following code

CString arabic (_T("????? ??????"));
pDC->TextOutW (50, 50, arabic);

The problem is that the MFC window displays bars instead of the Arabic characters as shown in the screenshot below. Can someone tell what I am doing wrong?

First attempt to display Arabic

I am using VS 2003 if that matters.

EDIT: When I have selected a font object in the device context, the behaviour of the application changes but it's still not correct; it displays the following characters as if I am using the wrong codepage:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
349 views
Welcome To Ask or Share your Answers For Others

1 Answer

This means that the selected font does not have the chars available.

You have to select a font that has the glyphs you need into the device context.

something like this maybe:

CFont font;
font->CreateFont(16,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,
        OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
        ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_SWISS,
        "Tahoma");
pDC->SelectObject(font);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...