一般怎么解决控件上中文显示乱码的问题

mutou0422 2009-07-11 09:23:17
从网上下的控件,在setLabel或者addTitle这样的方法里输入英文都可以正常显示,但是中文都是乱码。

c->addTitle("Some Chinese Text", "mingliu.ttc", 15);

我想这样去指定字体也没有用。

帮助文档里有说到这个控件是采用UTF-8编码的。

现在我要想显示中文,怎么解决?
...全文
680 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangdong 2011-05-06
  • 打赏
  • 举报
回复
在例程里有个TCHARtoUTF8,象下面这样用可以解决问题:

c->addTitle(TCHARtoUTF8("中文字符"), _T("SIMKAI.TTF"), 12);

----------------------------------------------------------

不过我不知道横坐标上面的汉字如何显示:
const char *labels[] = {"1996年", "1997Y", "1998", "1999", "2000", "2001", "2002",
"2003", "2004", "2005"};

这个显示出来老是乱码。
mutou0422 2009-07-15
  • 打赏
  • 举报
回复
我把当前的cpp 通过vs存为 unicode(UTF-8 无签名)的格式 再运行 就可以显示汉字。。。

但现在怕整个cpp都存为utf的会对其他代码产生影响

所以有没有什么改进的方法?
cadhy 2009-07-11
  • 打赏
  • 举报
回复

mark
supconsupcon 2009-07-11
  • 打赏
  • 举报
回复
c->addTitle("Some Chinese Text", "mingliu.ttc", 15);
改为c->addTitle(_T("中文字符"), _T("mingliu.ttc"), 15);
mutou0422 2009-07-11
  • 打赏
  • 举报
回复
囧 我另存为UTF8格式的后编译过不了 现在还改不回去了。。。。
oyljerry 2009-07-11
  • 打赏
  • 举报
回复
直接把你这段代码所在的cpp文件另存为UTF8格式的文件,然后再编译..
mutou0422 2009-07-11
  • 打赏
  • 举报
回复
ChartDirector assumes all text strings are in UTF8 encodings. If you are entering text string literals in source code, you may simply save your source code in UTF8 encoding. Most text editors designed for programming use can support saving source code in UTF8.

If your text strings are from somewhere else (such as from a database), and it is not in UTF8, you would need to convert it to UTF8 before passing them to ChartDirector. Many languages have built-in libraries for these conversion, and many coversion libraries are available on the Internet. For example:


C++ on Windows:Use the Win32 function MultiByteToWideChar to convert to wchar_t (unicode), then use WideCharToMultiByte to convert to UTF8.


网上也这么说了,可是我这为什么不行?我什么地方弄错了么?求救啊~~~~
mutou0422 2009-07-11
  • 打赏
  • 举报
回复
char* cword = "温度";
DWORD num= MultiByteToWideChar(CP_ACP,0,cword,-1,NULL,0);

wchar_t* wword; //定义一个UNICODE的指针

wword= new wchar_t[num];

if(!wword) //判断申请到空间没有
{
delete[] wword;
}

MultiByteToWideChar(CP_ACP,0, cword, -1, wword, num);

DWORD dwNum = WideCharToMultiByte(CP_OEMCP, NULL, wword, -1, NULL, 0, NULL, FALSE);

char *psText;
psText = new char[dwNum];
if(!psText)
{
delete[] psText;
}
WideCharToMultiByte (CP_OEMCP,NULL,wword,-1,psText,dwNum,NULL,FALSE);


这样转换过后把psText传给addTitle也还是乱码。
mutou0422 2009-07-11
  • 打赏
  • 举报
回复
应该和字体指定没有关系的 我试了windows/fonts/下面的很多字体了 都不行

现在想想 应该和字体编码方式有关

vs设置的字符集是unicode的,而这个空间用的UTF-8编码

这些编码问题我不懂 是不是还要把ASCII扩展到GB2312呢?
oyljerry 2009-07-11
  • 打赏
  • 举报
回复
要看控件是否支持,对于中文,用宽字符等先试试,或者MulitByteToWideChar转化成UTF-8看看
tkminigame 2009-07-11
  • 打赏
  • 举报
回复
const char*以00作为结尾判断。
const wchar*中的单字节字符都是ascii加上00。
如果设置的文字是“中文01英文”控件只会显示到“中文0”,能用吗
mutou0422 2009-07-11
  • 打赏
  • 举报
回复
如果参数是const char*型的不支持中文字符。


这个不支持是什么意思?
tkminigame 2009-07-11
  • 打赏
  • 举报
回复
如果参数是const char*型的不支持中文字符。
mutou0422 2009-07-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 supconsupcon 的回复:]
c->addTitle("Some Chinese Text", "mingliu.ttc", 15);
改为c->addTitle(_T("中文字符"), _T("mingliu.ttc"), 15);
[/Quote]

这个函数的参数要求的就是const char*型的

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧