Display Arabic/ Unicode in MFC View

2019-08-29 12:42发布

问题:

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?

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:

回答1:

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);


标签: unicode mfc