MFC 应用程序到 Unicode/MBCS 的分段转换
我有一个大型 MFC 应用程序,我正在扩展它以允许多语言输入。目前,我需要允许用户在单个对话框的编辑框中输入 Unicode 数据。
有没有办法在不为整个应用程序打开 UNICODE 或 MBCS 的情况下执行此操作?我目前只需要转换应用程序的一小部分。是否可以分段执行此操作?如果可以,如何执行?
澄清:我可以使用 ::GetWindowTextW() 从窗口中获取 Unicode 信息。我试图弄清楚如何允许用户在窗口中输入 Unicode 文本。目前,用户键入的字符在 windows-1252 代码页之外显示为“?”。有办法解决这个问题吗?
I have a large MFC application that I am extending to allow for multi-lingual input. At the moment I need to allow the user to enter Unicode data in edit boxes on a single dialog.
Is there a way to do this without turning UNICODE or MBCS on for the entire application? I only need a small part of the application converted at the moment. Is it possible to do this piecewise, and if so, how?
Clarification: I could use ::GetWindowTextW() to get Unicode information out of the window. I am trying to figure out how to allow the user to enter Unicode text in the window. Currently, characters the user types outside of the windows-1252 codepage show up as '?'. Is there a way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要允许
CEdit
显示 Unicode 字符,您应该使用CreateWindowW
函数创建它。我刚刚在 ANSI MFC 程序中测试了它。您可以在对话框的
OnInitDialog
函数中手动创建所有编辑框。然后将它们子类化为具有 Unicode 支持的自定义 CMyEdit 类。To allow
CEdit
to show Unicode characters you should create it withCreateWindowW
function. I've just tested it in ANSI MFC program.You could create all edit boxes manually in
OnInitDialog
function of dialog box. And later subclass them to custom CMyEdit class with Unicode support.您可以用丰富的编辑控件替换这些编辑框吗?然后,即使在非 Unicode 版本中,您也可以输入国际字符;在内部,它们将被 rtf 编码,但是当您从控件中流式传输文本时,您可以使用 SF_UNICODE 格式来获取 Unicode 表示形式。
Can you replace these edit boxes with rich edit controls? Then you could enter international characters even in a non-Unicode build; internally, they would be rtf-encoded, but then when you stream the text out from the control, you can use the SF_UNICODE format to get the Unicode representation.
只是一个想法 - 您可以尝试为您的构建打开 UNICODE 并在需要时使用 ANSI 调用(例如 CStringA)。
(我知道这可能不适合您,但认为值得指出的是,您可以通过其他方式解决这个问题)
Just a thought - you could try turning on UNICODE for your build and use ANSI calls where you need to (eg. CStringA).
(I understand that this may not be an option for you, but thought it worth pointing out that you could tackle this problem the other way round)