Unicode文本在编辑框中显示为问号,即使我使用SetWindowTextW() [英] Unicode text appears as question marks in edit box, even though I use SetWindowTextW()

查看:1163
本文介绍了Unicode文本在编辑框中显示为问号,即使我使用SetWindowTextW()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编辑框中显示为问号的unicode档案名称有问题。



当我在编辑框中贴上Unicode字元时,例如阿拉伯文或泰文,它们显示正确,但是我运行此代码后,它们成为问号。如何来?

  WCHAR buf [100]; 
GetWindowTextW(hWndEditBox,buf,100);
SetWindowTextW(hWndEditBox,buf);另一件事 - 这个项目是ANSI(我们有代码不能被移植,所以整个项目都是这样的)保持ANSI),即_UNICODE宏未定义,但我明确使用了Unicode版本的文件名。

解决方案

$ c> GetWindowText 函数实际上发送一个 WM_GETTEXT 消息到窗口( hWndEditBox )。因为你使用 * A 函数而不是 * W 函数(具体地 CreateWindowExA 在这种情况下,我想)您的消息循环将使用一些区域设置从宽字符转换为多字节字符。



这里似乎是改变整个窗口的设置 - 如果你的代码需要ANSI不是相关的UI这应该是可能的。或者,您可以用丰富的编辑框替换编辑框,提供额外的消息(例如 streaming )。



您可能要检查是否为 GetWindowTextW call或 SetWindowTextW 调用执行错误转换 - 如果 GetWindowTextW 正常工作,您可以转换



最后,您可以在阅读文本之前尝试调整线程的代码页,尽管这可能会导致各种其他问题。通常的建议是使用Unicode。



资料来源: GetWindowText 此评论来自Raymond Chen在他的博客上。


I have a problem with unicode filenames appearing as question marks in my edit boxes.

When I paste unicode characters in an edit box, for example Arabic or Thai, they show correctly, but after I run this code, they become question marks. How come?

WCHAR buf[100];
GetWindowTextW(hWndEditBox, buf, 100);
SetWindowTextW(hWndEditBox, buf);

Another thing - the project is ANSI (we have code that can't be ported so the entire project stays ANSI), i.e. _UNICODE macro is undefined, but I explicitly use the Unicode versions of the filenames.

解决方案

The GetWindowText function actually sends a WM_GETTEXT message to the window (hWndEditBox). Since you're using the *A functions rather than the *W function (specifically CreateWindowExA in this case, I think) your message loop will be converting from wide characters to multi-byte characters using some locale.

Your only solution here seems to be changing the entire window setup - if your code that requires ANSI is not related to UI this should be possible. Alternatively, you may be able to replace the edit box with rich edit boxes, that provide extra messages (such as streaming, for example).

You may want to check whether it is the GetWindowTextW call or the SetWindowTextW call that is doing the bad conversion - if GetWindowTextW works correctly you may be able to convert to multibyte using the correct locale before you set it.

Finally, you can try adjusting the thread's code page before reading the text, though this may cause all sorts of other issues. The usual advice is to use Unicode.

Sources: GetWindowText and this comment from Raymond Chen on his blog.

这篇关于Unicode文本在编辑框中显示为问号,即使我使用SetWindowTextW()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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