WinAPI and UTF-8 support(WinAPI 和 UTF-8 支持)
问题描述
关于 UTF-8 支持和各种 Win32 API 的快速问题.
Quick question regarding UTF-8 support and various Win32 API's.
在典型的 C++ MFC 项目中,MessageBox() 是否可以显示 UTF-8 编码的字符串?
In a typical C++ MFC project, is it possible for MessageBox() to display a UTF-8 encoded string?
谢谢,安德鲁
推荐答案
快速回答:没有.
更长的答案:如果字符串只包含常规的 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 字符或任何双字节编码字符,则需要使用 MultiByteToWideChar 和 CP_UTF8 转换为 Unicode-16.您的程序还需要使用定义的 UNICODE 进行编译,或者您可以使用W"API 调用 - 例如消息框W.
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).
这也可能有用;
http://www.joelonsoftware.com/articles/Unicode.html
这篇关于WinAPI 和 UTF-8 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WinAPI 和 UTF-8 支持
基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
