Cocos 在win32 平臺上顯示中文(僅實現win32)

測試顯示 中文或者 其它平臺已經判斷顯示的 可以借用這偷懶的方法

在cocos-x 3.2 ,vs2012 環境中運行的


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

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

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

		char* resultstring = new char[asciisize];

		int convresult = ::WideCharToMultiByte(CP_UTF8, 0, text.c_str(), text.size(), resultstring, asciisize, NULL, 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);



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章