Display Arabic/ Unicode in MFC View

2019-08-29 12:51发布

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

标签: unicode mfc
1条回答
太酷不给撩
2楼-- · 2019-08-29 13:06

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);
查看更多
登录 后发表回答