问题描述
有关UTF-8支持和各种Win32 API的快速问题。
Quick question regarding UTF-8 support and various Win32 API's.
在一个典型的C ++ MFC项目中,MessageBox()可以显示UTF-编码字符串?
In a typical C++ MFC project, is it possible for MessageBox() to display a UTF-8 encoded string?
感谢,
Andrew
Thanks,Andrew
推荐答案
快速回答:不。
更长的答案:如果字符串只包含常规的ANSI字符,例如美国英语,它会工作,因为这些字符代码在UTF- 8和ANSI。
Longer answer: It'll work if the string only contains regular ANSI characters, e.g US English, since these character codes are the same in UTF-8 and ANSI.
如果包含非ANSI字符或任何双字节编码字符,则需要使用带有CP_UTF8的MultiByteToWideChar转换为Unicode-16。您的程序还需要使用UNICODE定义进行编译,或者您可以使用'W'API调用 - 例如。 MessageBoxW。
If non-ANSI characters are included, or any double-byte encoded characters, you'll need to transform to Unicode-16 using MultiByteToWideChar with CP_UTF8. Your program will also need to be compiled with UNICODE defined, or you can use the 'W' API calls - e.g. MessageBoxW.
(注意,函数接受一个文本参数,如MessageBox,CreateWindow映射到'A'或'W'版本,取决于是否定义UNICODE)。
(Note that functions taking a text argument such as MessageBox, CreateWindow map to either 'A' or 'W' versions depending on whether UNICODE is defined).
这也可能有用;
这篇关于WinAPI和UTF-8支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!