WinAPI 和 UTF-8 支持 [英] WinAPI and UTF-8 support

查看:24
本文介绍了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 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆