简体   繁体   中英

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. 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

Do not define UNICODE and _UNICODE in the source file. you have to define it on the project level. Form menu in VS select project and Setting (Alt-7).

In the dialog, select C++ tab and from Category drop box select Preprocessor. In the edit box below enter UNICODE and _UNICODE delimited by coma.

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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