Cyrillic alphabet in Multibyte

2019-08-06 12:19发布

问题:

I am pretty new to working with C++. I have an MFC project which needs be translated in to Russian.

If I change the MFC settings to Unicode it shows correctly. My question is:

Is it possible to print cyrillic alphabet with Multibyte? If so, how?

Thanks guys!

回答1:

I encourage you to build your MFC application using Unicode (to be more precise: UTF-16 in MFC/Visual Studio settings), as you wrote "If I change MFC to Unicode it shows correctly.".

At the same time, you can still use another encoding like e.g. UTF-8 for your Cyrillic text, and store this in CStringA or std::string objects. Then, you can convert between UTF-8 and UTF-16 at the "MFC boundaries", e.g. when showing your text on your dialog boxes or other application windows.

You can use some ATL/MFC conversion helpers, or write your own conversion code invoking Windows APIs like MultiByteToWideChar and WideCharToMultiByte, specifying the proper "code page" for the conversion (e.g. CP_UTF8 for UTF-8-encoded text).

You may find this MSDN article on Unicode encoding conversions helpful as well.

On the other hand, if you want to use a specific code page (e.g. 1251 Windows Cyrillic) instead of UTF-8, then you can still use MultiByteToWideChar to convert text from your code page to Unicode UTF-16, specifying the proper code page identifier.