2

I'm using Visual C++ 6.0 in Windows 7. I go to File->New. I choose Win32 application and name it HelloWorld. "Win32 Appliction Step 1 of 1" comes up. I choose "A Typical Hello World Application". VC creates a simple Hello World App.

I select the file HelloWorld.cpp. I paste in the following defines at the top of the HelloWorld.cpp file:

#define UNICODE
#define _UNICODE

I then double click on HelloWorld.rc. I open up the "Dialog" item. Under it is IDD_ABOUTBOX. I double click that. I then add an EDITTEXT control to the dialog window. I hit ctrl-F5 to run the program.

I choose about and the about dialog is displayed along with EDITTEXT control. I then goto to the charmap.exe application and select a japanese hiragana character from the Meiryo font. I copy it to the clipboard.

I then paste it into the EDITTEXT control. It shows up as a "?" question mark.

I don't understand what to do. How can I get dialog edit boxes to accept Unicode?

Thanks in advance, Ryan

4

1 回答 1

0

不要在源文件中定义 UNICODE 和 _UNICODE。您必须在项目级别定义它。VS 中的表单菜单选择项目和设置(Alt-7)。

在对话框中,选择 C++ 选项卡,然后从 Category 下拉框中选择 Preprocessor。在下面的编辑框中输入以逗号分隔的 UNICODE 和 _UNICODE。

现在,编辑控件原样使用没有扩展字符集的系统字体。您必须更改字体以进行编辑控制。

在对话框 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;

请记住,并非所有字体类型都有扩展字符集。我认为在代码片段中将其设置为 Arial 应该可以。

于 2012-06-14T22:54:31.243 回答