Creating a Win32 application window with an English title, but the title bar becomes Chinese from nowhere. How so?

HWND wndHandle; //global variable

// code snipped

WNDCLASSEX wcex;

// code snipped

wcex.lpszClassName = (LPCWSTR) "MyTitleName";

 // code snipped

wndHandle = CreateWindow(
            (LPCWSTR)"MyTitleName",     //the window class to use
            (LPCWSTR)"MyTitleName",     //the title bar text
...
...

I am following a tutorial for windows window. The above code is used to set the title bar of a window. The compiler yells at me: β€œit is impossible to convert fromβ€œ const char [12] ”toβ€œ LPCWSTR ”, so well, I came up with my lineβ€œ MyTitleName ”with (LPCWSTR), and everything compiled just fine. However, the window title bar is executed at runtime turns out to be Chinese. I tried changing the line around and Chinese characters always change according to my line. I use XP Visual C ++ 2008 Express Edition and I got English (US) as the setting for non-unicode programs. I don't I understand, why does the string become Chinese?

+3
2

( ). , , Windows API, , : L"MyTitleName". LPCWSTR, , -, .

:

wcex.lpszClassName = L"MyTitleName";

 // code snipped

wndHandle = CreateWindow(
            L"MyTitleName",     //the window class to use
            L"MyTitleName",     //the title bar text
            ...

, : "" Character Set Use Multi-Byte Character Set. - , - .

+9

- (LPCWSTR). , , - . - Unicode . Fix:

wcex.lpszClassName = L"MyTitleName";
wndHandle = CreateWindow(
              L"MyTitleName",     //the window class to use
              L"MyTitleName",     //the title bar text
+7

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


All Articles