加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos 在win32 平台上显示中文(仅实现win32)

发布时间:2020-12-14 20:41:32 所属栏目:百科 来源:网络整理
导读:测试显示 中文或者 其它平台已经判断显示的 可以借用这偷懒的方法 在cocos-x 3.2,vs2012 环境中运行的 在所使用的.h文件中私有添加 inline std::string WideByte2UTF8(const wstring text){int asciisize = ::WideCharToMultiByte(CP_UTF8,text.c_str(),text

测试显示 中文或者 其它平台已经判断显示的 可以借用这偷懒的方法

在cocos-x 3.2,vs2012 环境中运行的


在所使用的.h文件中私有添加

	inline std::string WideByte2UTF8(const wstring& text)
	{
		int asciisize = ::WideCharToMultiByte(CP_UTF8,text.c_str(),text.size(),NULL,NULL);

		if (asciisize == ERROR_NO_UNICODE_TRANSLATION || asciisize == 0)
		{
			return string();
		}

		char* resultstring = new char[asciisize];

		int convresult = ::WideCharToMultiByte(CP_UTF8,resultstring,asciisize,NULL);

		if (convresult != asciisize)
		{
			return string();
		}

		std::string buffer(resultstring,convresult);

		delete[] resultstring;

		return buffer;
	}


在cpp中调用

std::string str = "";
str = WideByte2UTF8(L"你好世界");
	Label* label = Label::createWithSystemFont(str.c_str(),"Arial",20);
	label->setColor(Color3B::RED);
	label->setPosition(200,200);
	this->addChild(label);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读