What is wrong with my character set (Win32 API)

I am currently studying Win32 using this tutorial , and it is difficult for me to display the characters.

Take, for example, this piece of code that adds a menu to my window when creating:

    case WM_CREATE: {
            HMENU hMenu, hSubMenu;
            HICON hIcon, hIconSm;

            hMenu = CreateMenu();
            hSubMenu = CreatePopupMenu();

            AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "Exit");
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "File");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&GO");
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff");

            SetMenu(hwnd, hMenu);

            hIcon = LoadImage(NULL, "Stuff.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);

            if (hIcon)
                SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
            else
                MessageBox(hwnd, "Could not load large icon!", "Load Error", MB_OK | MB_ICONERROR);

            hIconSm = LoadImage(NULL, "Stuff.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);

            if(hIconSm)
                SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
            else
                MessageBox(hwnd, "Could not load small icon!", "Load Error", MB_OK | MB_ICONERROR);
        }
        break;

This is inside a block switchin my function WndProcthat processes Windows messages received from a message loop.

Each line to be displayed:

"Exit"
"File"
"&GO"
"&Stuff"

Unreadable at runtime, as they appear as small squares, just like the codepage was not correct or something like that. When I run the tutorial, all lines are displayed correctly. As a rule, I adhere to what the textbook says to help me figure it out correctly, and his pedagogy is good. Anyway!...

:

  • Microsoft Visual Studio 2008;
  • Microsoft Windows Server 2003 RDP;
  • - Windows Vista Ultimate.

- ?

+1
2

Unicode Windows ANSI. Windows ASCII, ANSI. , 8- , . Win32 , Unicode . (, UTF-16LE , .) , , Win16 Win32 .

( , ). Win32 API, , . ANSI UTF-16LE . ( ) UTF-16LE . Visual C wchar_t 16- , L"" ASCII UTF-16LE.

Win16, MessageBox API Win32, , MessageBoxA, MessageBoxW , UNICODE.

, , UNICODE, typedef, .

, Win16 #include <tchar.h>, TCHAR char wchar_t, _T() API Win32 , MessageBox.

. , , , , , TCHAR. , TCHAR s, , , , UNICODE.

Win32 , UNICODE , , , L"" W .

, , ( - , , ). , ASCII Win32, UTF-16LE, "Exit" Unicode, U+7845 U+7469, . Han, , .

, ASCII. :

AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "Exit");

:

AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, _T("Exit"));
AppendMenuA(hSubMenu, MF_STRING, ID_FILE_EXIT, "Exit");
AppendMenuW(hSubMenu, MF_STRING, ID_FILE_EXIT, L"Exit");

.

+6

. Unicode. L ( L ") Unicode ( Windows UTF-16). Windows, , .

API- UTF-16 API. http://utf8everywhere.org.

+4

Source: https://habr.com/ru/post/1524259/


All Articles