Why does message box in C++ show chinese message(为什么C++中的消息框显示中文消息)
问题描述
可能的重复:
为什么我的简单 C++ GUI应用程序显示中文消息框?
我已经在 Visual C++ 中实现了如下代码块:
I have implemented this block of code as below in Visual C++:
int nResult=MessageBox(NULL,
(LPCWSTR)"An example of Cancel,Retry,Continue",
(LPCWSTR)"Message Box!",
MB_ICONWARNING|MB_ABORTRETRYIGNORE);
然而,无论我尝试什么,它总是显示一个中文消息框!因此,我只想为我的问题寻求任何解决方案以及为什么这里有中文信息.谢谢!
however, no matter what i tried, it always show a message box in chinese! Therefore, i just want to ask for any solution for my problem and why there is chinese message here. Thanks you!
推荐答案
您忘记在字符串字面量之前放置 'L'.修改如下:
You forgot to place 'L' before the string literal. Modify as follows:
int nResult=MessageBox(NULL,
L"An example of Cancel,Retry,Continue",
L"Message Box!",
MB_ICONWARNING|MB_ABORTRETRYIGNORE);
在 C++ 中,Unicode 字符串文字以 L
为前缀.如果您不添加前缀,则转换为unicode string constant"将无济于事,并会导致对内存位置的错误解释.
In C++ unicode string literals are prefixed with L
. If you don't put the prefix, casting to 'unicode string constant' won't help and causes incorrect interpreting of the memory location.
这篇关于为什么C++中的消息框显示中文消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么C++中的消息框显示中文消息


基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 常量变量在标题中不起作用 2021-01-01