简体   繁体   English

无法获取Visual C ++ 6.0对话框编辑控件以接受Unicode /无法获取EDITTEXT资源以接受Unicode

[英]Can't Get Visual C++ 6.0 Dialog Edit Control to Accept Unicode / Can't Get EDITTEXT Resource to Accept Unicode

I'm using Visual C++ 6.0 in Windows 7. I go to File->New. 我在Windows 7中使用Visual C ++ 6.0。我转到“文件”->“新建”。 I choose Win32 application and name it HelloWorld. 我选择Win32应用程序并将其命名为HelloWorld。 "Win32 Appliction Step 1 of 1" comes up. 出现“ Win32 Appliction步骤1之1”。 I choose "A Typical Hello World Application". 我选择“典型的Hello World应用程序”。 VC creates a simple Hello World App. VC创建了一个简单的Hello World应用程序。

I select the file HelloWorld.cpp. 我选择文件HelloWorld.cpp。 I paste in the following defines at the top of the HelloWorld.cpp file: 我将以下定义粘贴在HelloWorld.cpp文件的顶部:

#define UNICODE
#define _UNICODE

I then double click on HelloWorld.rc. 然后,我双击HelloWorld.rc。 I open up the "Dialog" item. 我打开“对话框”项。 Under it is IDD_ABOUTBOX. 它的下面是IDD_ABOUTBOX。 I double click that. 我双击。 I then add an EDITTEXT control to the dialog window. 然后,我将EDITTEXT控件添加到对话框窗口。 I hit ctrl-F5 to run the program. 我按ctrl-F5运行该程序。

I choose about and the about dialog is displayed along with EDITTEXT control. 我选择关于,关于对话框将与EDITTEXT控件一起显示。 I then goto to the charmap.exe application and select a japanese hiragana character from the Meiryo font. 然后,我转到charmap.exe应用程序,并从Meiryo字体中选择一个日语平假名字符。 I copy it to the clipboard. 我将其复制到剪贴板。

I then paste it into the EDITTEXT control. 然后,将其粘贴到EDITTEXT控件中。 It shows up as a "?" 它显示为“?” question mark. 问号。

I don't understand what to do. 我不知道该怎么办。 How can I get dialog edit boxes to accept Unicode? 如何获得对话框编辑框以接受Unicode?

Thanks in advance, Ryan 在此先感谢,瑞安

Do not define UNICODE and _UNICODE in the source file. 不要在源文件中定义UNICODE和_UNICODE。 you have to define it on the project level. 您必须在项目级别上对其进行定义。 Form menu in VS select project and Setting (Alt-7). VS中的“表单”菜单选择项目和设置(Alt-7)。

In the dialog, select C++ tab and from Category drop box select Preprocessor. 在对话框中,选择“ C ++”选项卡,然后从“类别”下拉框中选择“预处理器”。 In the edit box below enter UNICODE and _UNICODE delimited by coma. 在下面的编辑框中,输入用逗号分隔的UNICODE和_UNICODE。

Now, edit control, as is uses system font that does not have extended character set. 现在,按原样使用没有扩展字符集的系统字体编辑控件。 You have to change font for edit control. 您必须更改字体以进行编辑控制。

In the dialog WM_INITDIALOG handler do the following: 在对话框WM_INITDIALOG处理程序中,执行以下操作:

case WM_INITDIALOG:
    {
        LOGFONT lf;
        ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
        HWND hEdit = GetDlgItem(hDlg, IDC_EDIT1);
        HDC hDC = GetDC(hEdit);

        _tcscpy(lf.lfFaceName, _T("Arial"));
        lf.lfHeight = -MulDiv(10, GetDeviceCaps(hDC, LOGPIXELSY), 72);

        //This creates the new font for the edit control
        HFONT hFont = CreateFontIndirect(&lf);

        //This sets the new font for the edit control
        SendMessage(hEdit, WM_SETFONT, (WPARAM)hFont, FALSE);
    }
    return TRUE;

Remember that not all font type have extended character set. 请记住,并非所有字体类型都有扩展的字符集。 I think setting it to Arial as in the code snippet should work. 我认为像代码片段中那样将其设置为Arial应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM