Why can't My Applicaion correctly display the Unicode character?

I decided to turn my win32 C ++ application into a Unicode version, but when I use this, I received unreadable letters for Arabic, Chinese and Japanese ...

Firstly:

If I do not use Unicode, I got Arabic in the edit windows. Window titles:

HWND hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "ا ب ت ث ج ح خ د ذ", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE, 10, 10, 300, 200, hWnd, (HMENU)100, GetModuleHandle(NULL), NULL);

SetWindowText(hWnd, "صباح الخير");

The output seems fine and works fine! (without unicode).

  • With Unicode:

I added before the inclusion headers:

#define UNICODE
#include <windows.h

Now in the Procedure window:

case WM_CREATE:{
    HWND hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", L"ا ب ت ث ج ح خ د ذ", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE, 10, 10, 300, 200, hWnd, (HMENU)100, GetModuleHandle(NULL), NULL);

    // Even I send message to change text but I get unreadable characters!
}
break;
case WM_LBUTTONDBLCLK:{
    SendDlgItemMessageW(hWnd, 100, WM_SETTEXT, 0, (LPARAM)L"السلام عليكم"); // Get unreadable characters also
}
break;

As you can see in Unicode, controls cannot correctly display Arabic characters.

  • The fact is: after creating the control, I delete the contents manually using backspaceNow, if I enter the Arabic text manually. Successfully display it correctly? !!! But why does Wen use features? How SetWindowTextW()??

, . .

+4
2

UTF-16 UTF-8 . Windows ANSI ( Windows). , UTF-8 . , MS Visual Studio 2015 /utf-8, .

, UTF-8, UTF-8 w/BOM Microsoft Visual Studio. , UNICODE, W API API L "" :

#include <windows.h>

int main()
{
    MessageBoxW(NULL,L"ا ب ت ث ج ح خ د ذ",L"中文",MB_OK);
}

(UTF-8). ANSI (Windows-1252) .

Corrupted image

(UTF-8 w/BOM). UTF-8 , .

Correct image

Python, :

>>> s='中文,ا ب ت ث ج ح خ د ذ'
>>> print(s.encode('utf8').decode('Windows-1252'))
中文,ا ب ت ث ج ح خ د ذ
+10

, , !

1- : () .

2- v++ 6.0 UNICODE, _UNICODE Multi-Byte-Character-String _MBCS.

@Remy Lebeau, Simplified Arabic (Unicode fnot) .

, entrypoint wWinMainCRTStartup.

, , . , ! , !

  • , V++ 14 , unicode.
0

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


All Articles