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/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01