转载自http://blog.csdn.net/u013052732/article/details/18003159
为实现游戏界面中的汉字效果,我们可以做一个函数,然后在写汉字的时候调用函数进行识别,请看函数代码
首先,头文件加入指针函数声明
- char* G2U(const char* gb2312);
然后,代码要放到你要显示汉字的cpp里面
- char* HelloWorld::G2U(const char* gb2312){
- int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
- wchar_t* wstr = new wchar_t[len+1];
- memset(wstr, 0, len+1);
- MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
- len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
- char* str = new char[len+1];
- memset(str, 0, len+1);
- WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
- if(wstr) delete[] wstr;
- return str;
- }
最后,在显示文字的地方进行添加例如
- CCLabelTTF* pLabel = CCLabelTTF::create(G2U("节操掉了一地"),"Verdana",35);