MFC 应用程序到 Unicode/MBCS 的分段转换

2022-01-12 00:00:00 unicode c++ mfc mbcs

我有一个大型 MFC 应用程序,我正在扩展它以支持多语言输入.目前我需要允许用户在单个对话框的编辑框中输入 Unicode 数据.

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.

有没有办法在不为整个应用程序打开 UNICODE 或 MBCS 的情况下做到这一点?我现在只需要转换应用程序的一小部分.是否可以分段进行,如果可以,怎么做?

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?

澄清:我可以使用 ::GetWindowTextW() 从窗口中获取 Unicode 信息.我试图弄清楚如何允许用户在窗口中输入 Unicode 文本.目前,用户键入的字符在 windows-1252 代码页之外显示为?".有没有办法解决这个问题?

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?

推荐答案

要允许 CEdit 显示 Unicode 字符,您应该使用 CreateWindowW 函数创建它.我刚刚在 ANSI MFC 程序中测试过.

To allow CEdit to show Unicode characters you should create it with CreateWindowW function. I've just tested it in ANSI MFC program.

// allows Unicode characters
CreateWindowW( L"EDIT", L"", WS_CHILD|WS_VISIBLE, 10, 10, 50, 20, GetSafeHwnd(), 0, 0, 0 );

// shows Unicode characters as ?
CreateWindow( "EDIT", "", WS_CHILD|WS_VISIBLE, 10, 10, 50, 20, GetSafeHwnd(), 0, 0, 0 );

您可以在对话框的OnInitDialog 函数中手动创建所有编辑框.然后将它们子类化为支持 Unicode 的自定义 CMyEdit 类.

You could create all edit boxes manually in OnInitDialog function of dialog box. And later subclass them to custom CMyEdit class with Unicode support.

相关文章