更改键盘布局后,编辑控件不会正确显示字符 [英] Edit control doesn't show characters properly after keyboard layout is changed

查看:117
本文介绍了更改键盘布局后,编辑控件不会正确显示字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了简单的编辑控制。将键盘布局从英语更改为其他键盘后,字符显示不正确。它们用管道表示( | )。



如果我复制编辑控件的内容并粘贴它进入记事本它们显示正确。



我试图注册类/创建父窗口/创建带后缀W的编辑控件( CreateWindowExW / RegisterClassExW )但没有运气......



我在源文件中键入了特定的UNICODE字符,因此可以弹出 Visual Studio 中的对话框,提示我将所有文件保存为UNICODE。一旦弹出,我确认将所有内容保存为UNICODE。我还去了项目属性并选择了UNICODE字符集。



没有进展......你可以通过简单地创建一个来重现问题编辑控件,然后更改键盘布局,因此不需要 SSCCE 。我使用 Visual Studio 2008在 Windows XP 上工作。



如果还有什么我必须提供/做的请问。

I have made simple edit control. After I change keyboard layout from English to other one, characters are not shown properly. They are represented with a pipe ( | ).

If I copy the content of the edit control and paste it into Notepad they are displayed properly.

I have tried to register class / create parent window / create edit control with suffix W ( CreateWindowExW / RegisterClassExW ) but no luck...

I have typed specific UNICODE characters in my source file so a dialog box in Visual Studio can pop prompting me to save all my files as UNICODE. Once it popped I confirmed to save everything as UNICODE. I have also went to Project properties and selected UNICODE character set.

No progress... You can reproduce the problem by simply creating the edit control, and then changing keyboard layout so there is no need for SSCCE. I work on Windows XP using Visual Studio 2008.

If anything else I must provide / do please ask.

推荐答案

将以下代码片段添加到我的 WM_CREATE 处理程序后,我发现编辑控件使用系统字体:



After adding the following code snippet into my WM_CREATE handler I found out that edit control uses System font :

HFONT hf = (HFONT)SendMessage( hEdit, WM_GETFONT, 0, 0 );

HDC eDC = GetDC( hEdit );
wchar_t txt[50];
GetTextFace( eDC, 50, txt );

SetWindowText( hEdit, txt );

ReleaseDC( hEdit, eDC );
DeleteObject( hf );





记事本中选择相同的字体后,问题是转载。



因此,在我上面提交的代码下方添加以下代码后,问题得到解决:





After choosing this same font in Notepad, the problem was reproduced.

Thus, after adding the following code just below the code I submitted above, the problem was fixed :

SendMessage( hEdit, WM_SETFONT, 
    (WPARAM)( (HFONT)GetStockObject(DEFAULT_GUI_FONT) ), 0 );





所以我的问题的答案是:



< b>问题是字体,因此必须更改为可以显示我需要显示的特殊字符的那个。



希望这可以节省一些人麻烦。



So the answer to my question is :

The problem is font, thus it must be changed to the one that can show special characters I need to display.

Hopefully this will save someone the trouble.


这篇关于更改键盘布局后,编辑控件不会正确显示字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆