Liny_@NotePad

沉迷ACG中

CEGUI setText无法显示中文。。

YOYO posted @ 2009年11月02日 23:18 in 【游戏开发】 with tags 字符编码转换 中文显示 CEGUI , 4775 阅读

项目设好了中文字体,加上中文输入,输入的字符显示出来是正常的,但是直接在程序里面setText中文却显示乱码……

查了一下是字符编码的关系……CEGUI是UTF-8格式的。。必须进行转换。。我的项目使用多字节,下面是转换函数:

  1. CEGUI::String CharArrayToString(const char* pszText)
  2. {
  3.         //      ASCII -> Unicode
  4.         int nLen = strlen(pszText);
  5.         std::wstring unicode(nLen, 0);
  6.         unicode.resize(
  7.                 MultiByteToWideChar(CP_ACP, 0, pszText, static_cast<int>(nLen),
  8.                 const_cast<wchar_t*>(unicode.data()), unicode.size())
  9.         );
  10.  
  11.         //      Unicode -> UTF-8
  12.         char buff[128] = "";
  13.         WideCharToMultiByte(CP_UTF8, 0, unicode.data(), static_cast<int>(unicode.size()),
  14.                 buff, sizeof(buff), NULL, NULL);
  15.  
  16.         return CEGUI::String((CEGUI::utf8*)(buff));
  17. }

附上几个链接:


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter