找到自己所想要的认识中文的字体文件,可以在windows系统下找微软的,我找到的是simhei.ttf这个字体文件,然后修改MyGUI源码中字体文件MyGUI_Fonts.xml,将刚才找到的字体文件 添加进去,如下,然后在用到的字体的空间中写上这个字体的名字就好。如果嫌麻烦可以修改默认字体文件MyGUI_Settings.xml,修改其中的字体,默认字体名字改为你修改后的就可以了。如果以上方式还是做不到显示中文问题 那么就再写一个钩子程序,捕获输入进行解析,我这里做了一个修改窗口属性的回调,也是参考前辈的例子做的
<Resource type="ResourceTrueTypeFont" name="font_Simhei"><Property key="Source" value="simhei.ttf"/>
<Property key="Size" value="19"/>
<Property key="Resolution" value="50"/>
<Property key="Antialias" value="false"/>
<Property key="SpaceWidth" value="4"/>
<Property key="TabWidth" value="8"/>
<Property key="CursorWidth" value="2"/>
<Property key="Distance" value="6"/>
<Property key="OffsetHeight" value="0"/>
<Codes>
<Code range="33 126"/>
<Code range="8216 8217"/>
<Code range="8220 8221"/>
<Code range="8211 8212"/>
<Code range="8230"/>
<Code range="12289 12290"/>
<Code range="12296 12303"/>
<Code range="12308 12309"/>
<Code range="12304 12305"/>
<Code range="65281 65374"/>
<Code range="19968 40869"/>
<Code hide="128"/>
<Code hide="1026 1039"/>
<Code hide="1104"/>
</Codes>
</Resource>
代码:
SetWindowLong(hWnd, GWL_WNDPROC, (long)windowProc);//回调函数入口
LONG_PTR style = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
SetWindowLongPtr(hWnd, GWL_EXSTYLE, style | WS_EX_ACCEPTFILES);
LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#define __WM_REALMOUSELAST WM_MOUSEWHEEL
#else
#define __WM_REALMOUSELAST WM_MOUSELAST
#endif // WM_MOUSEWHEEL
// для взятия знаковых значений
#define GET_HIWORD(param) ((short)HIWORD(param))
#define GET_LOWORD(param) ((short)LOWORD(param))
static int old_x = 0;
static int old_y = 0;
static int old_z = 0;
static bool left_button = false;
static bool right_button = false;
if (WM_CLOSE==uMsg)
{
//gameFrameListen->windowClosed(gameFrameListen->mWindow);
if ( gameFrameListen->isSendCloseWdMessage())
{
SetWindowLong((HWND)hWnd, GWL_WNDPROC, (long)msOldWindowProc);
msOldWindowProc = 0;
SendMessage((HWND)hWnd,uMsg,wParam,lParam);
}
return 0;
}
else if (WM_SIZE == uMsg)
{
return 0;
}
else if ((WM_CHAR==uMsg )&&(WM_IME_CHAR !=uMsg))
{
if (GetKeyState(VK_BACK) & 0xF000)
{ //退格键
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(OIS::KC_BACK));
}
else
{
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::None, wParam);
}
}
else if (WM_KEYUP==uMsg)
{
int scan_code = MyGUI::VirtualKeyToScanCode(wParam);
MyGUI::KeyCode code = MyGUI::KeyCode::Enum(scan_code);
MyGUI::InputManager::getInstancePtr()->injectKeyRelease(code);
}
return CallWindowProc((WNDPROC)msOldWindowProc, hWnd, uMsg, wParam, lParam);
}