Why is my Applicaion not displaying Unicode characters correctly?


WonFeiHong

I decided to convert my win32 c++ application to Unicode version, but when I use it I get unreadable letters in Arabic, Chinese and Japanese...

First:

If I don't use Unicode, I can find the name window title in Arabic in the edit box:

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 looks ok and works fine! (no unicode).

  • Unicode: used

I added before including the header:

#define UNICODE
#include <windows.h

Now in a "window procedure":

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 seen with Unicode, the control does not display Arabic characters correctly.

  • Important: After creating the control, use " backspaceNow" to manually delete the content. If I manually enter the Arabic text, will it be displayed correctly and correctly? ! ! But why does Wen use a function? like SetWindowTextW()??

please help. thanks.

Mark Tolonen

Make sure to save the source file as UTF-16 or UTF-8 using the BOM. Otherwise, many Windows applications are encoded in ANSI (the default native Windows code page). You can also check compiler switches to force UTF-8 for source files. For example, MS Visual Studio 2015's compiler has a /utf-8switch so there is no need to save with a BOM.

Here's a simple example, saved in UTF-8, then in UTF-8 w/ BOM, and compiled using the Microsoft Visual Studio compiler. Note that if you hardcode the W version of the API and use L"" for wide strings, you don't need to define UNICODE:

#include <windows.h>

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

result (UTF-8). The compiler took ANSI encoding (Windows-1252) and decoded wide strings incorrectly.

Image corrupted

Result (UTF-8 with BOM). The compiler detects the BOM and decodes the source code using UTF-8, producing the correct data for wide strings.

correct image

Some Python code demonstrating the decoding error:

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

Related


Why is my Applicaion not displaying Unicode characters correctly?

WonFeiHong I decided to convert my win32 c++ application to Unicode version, but when I use it I get unreadable letters in Arabic, Chinese and Japanese... First: If I don't use Unicode, I can find the name window title in Arabic in the edit box: HWND hWnd = Cr

Why is my Applicaion not displaying Unicode characters correctly?

WonFeiHong I decided to convert my win32 c++ application to Unicode version, but when I use it I get unreadable letters in Arabic, Chinese and Japanese... First: If I don't use Unicode, I can find the name window title in Arabic in the edit box: HWND hWnd = Cr

Why is my Applicaion not displaying Unicode characters correctly?

WonFeiHong I decided to convert my win32 c++ application to Unicode version, but when I use it I get unreadable letters in Arabic, Chinese and Japanese... First: If I don't use Unicode, I can find the name window title in Arabic in the edit box: HWND hWnd = Cr

Why is my Applicaion not displaying Unicode characters correctly?

WonFeiHong I decided to convert my win32 c++ application to Unicode version, but when I use it I get unreadable letters in Arabic, Chinese and Japanese... First: If I don't use Unicode, I can find the name window title in Arabic in the edit box: HWND hWnd = Cr

Android: TextView, unicode characters not displaying correctly

forward I programmatically add ranks by TextViewsetting some unicode asterisks . It's the unicode asterisk \u22C6 , but TextViewstarting the application shows this character: \u22A0 . This is how I create it: private CharSequence calculatedSelectedRating(Integ

IText Unicode Indian characters not displaying correctly

mph luck I am using Itext to generate PDF. I have text in Marathi. But Itext is the generation of text without glyph replacement. E.g: The text should read: ल्ल But iText shows in PDF: लल. Same as "text" should be: But iText displays in PDF: I have used Window

Why are Unicode characters not rendering correctly

sw1nn background: I have some unicode characters in my prompt (essentially git status tags) I'm running urxvt under xfce on Arch Linux. I'm using DejaVu Sans Mono as the Powerline font specified via the .Xresources line: URxvt*font: xft:DejaVu Sans Mono for Po

Why is my Mapbox GL not displaying tiles correctly?

username I am working on an Angular project and I want to use Mapbox I followed this tutorial which shows how to do it. When I try to run the server, I end up with this result. I searched everywhere but didn't find a solution to my problem. this is my code Tri

Why is my HTML div not displaying correctly?

Matt I'm writing a small website for an old web browser, so I have to use old-fashioned tabs. body { background-color: black; } #left-pane, #right-pane { border: 1px solid white; display: inline-block; width: 20em; height: 40em; } <div id="left-pane

Why is my composite signal not displaying correctly? MATLAB

Sustainable Development Goals I wrote some code in MATLAB below to filter a noise signal ( noise_fyes the noise signal, it's the 1x 256vector): s_nf = size(noise_f); size_f = s_nf(2); lp_tresh = ceil((2/3)*size_f); lp_f = zeros(1,256); for n = 1:lp_tresh

Why is my composite signal not displaying correctly? MATLAB

Sustainable Development Goals I wrote some code in MATLAB below to filter a noise signal ( noise_fyes the noise signal, it's the 1x 256vector): s_nf = size(noise_f); size_f = s_nf(2); lp_tresh = ceil((2/3)*size_f); lp_f = zeros(1,256); for n = 1:lp_tresh

Why is my custom UITableViewCell not displaying correctly?

chip I have a UITableViewController with a single prototype cell. The cell has labels and text fields in it, and its class is set to InputCell. When the table view is loaded, the cell appears to be dequeued, but appears as the default empty cell. I checked the

Why is my code not displaying comments and replies correctly?

rape This is the test code, I know about sql injections and how to fix them. This is a long question to explain, so I'll try my best. These are the columns in my database contentid (auto increments with every post, comment, and reply) hostid (gets the value of

Why is my JButton icon not displaying correctly?

Jakub Rogacz I'm currently developing some swing applications. When I try to JButtonshow only its Icon, it starts overlapping the two JButton Icons. Does anyone know what might be causing it (I have one icon that says 'yes', the second says 'no', If I move the

Why is my Mapbox GL not displaying tiles correctly?

username I am working on an Angular project and I want to use Mapbox I followed this tutorial which shows how to do it. When I try to run the server, I end up with this result. I searched everywhere but didn't find a solution to my problem. this is my code Tri

Why is my Mapbox GL not displaying tiles correctly?

username I am working on an Angular project and I want to use Mapbox I followed this tutorial which shows how to do it. When I try to run the server, I end up with this result. I searched everywhere but didn't find a solution to my problem. this is my code Tri

Why is my Mapbox GL not displaying tiles correctly?

username I am working on an Angular project and I want to use Mapbox I followed this tutorial which shows how to do it. When I try to run the server, I end up with this result. I searched everywhere but didn't find a solution to my problem. this is my code Tri

Why is my composite signal not displaying correctly? MATLAB

Sustainable Development Goals I wrote some code in MATLAB below to filter a noise signal ( noise_fyes the noise signal, it's the 1x 256vector): s_nf = size(noise_f); size_f = s_nf(2); lp_tresh = ceil((2/3)*size_f); lp_f = zeros(1,256); for n = 1:lp_tresh

Why is my composite signal not displaying correctly? MATLAB

Sustainable Development Goals I wrote some code in MATLAB below to filter a noise signal ( noise_fyes the noise signal, it's the 1x 256vector): s_nf = size(noise_f); size_f = s_nf(2); lp_tresh = ceil((2/3)*size_f); lp_f = zeros(1,256); for n = 1:lp_tresh

Why is my custom UITableViewCell not displaying correctly?

chip I have a UITableViewController with a single prototype cell. The cell has labels and text fields in it, and its class is set to InputCell. When the table view is loaded, the cell appears to be dequeued, but appears as the default empty cell. I checked the

Why is my JButton icon not displaying correctly?

Jakub Rogacz I'm currently developing some swing applications. When I try to JButtonshow only its Icon, it starts overlapping the two JButton Icons. Does anyone know what might be causing it (I have one icon that says 'yes', the second says 'no', If I move the

Why is my notification applet not displaying correctly?

questioner I am using Linux Mint 16 Petra in the MATE desktop environment. Maybe I shouldn't, but when I add a new app to the startup apps list, I see what looks like a duplicate, so I removed the duplicate. After restarting, the notification area in my panel

Why is my code not displaying comments and replies correctly?

rape This is the test code, I know about sql injections and how to fix them. This is a long question to explain, so I'll try my best. These are the columns in my database contentid (auto increments with every post, comment, and reply) hostid (gets the value of

Why is my discord bot not adding characters correctly?

Hellman 69 I'm trying to make a bot that when a person types in! When you join choiceOutOfVariousRoles, it will add a role in the server. I'm currently using discord version 12. My error message is: fn = fn.bind(thisArg); Despite trying various techniques, I

Why is my discord bot not adding characters correctly?

Hellman 69 I'm trying to make a bot that when a person types in! When you join choiceOutOfVariousRoles, it will add a role in the server. I'm currently using discord version 12. My error message is: fn = fn.bind(thisArg); Despite trying various techniques, I

Why is my discord bot not adding characters correctly?

Hellman 69 I'm trying to make a bot that when a person types in! When you join choiceOutOfVariousRoles, it will add a role in the server. I'm currently using discord version 12. My error message is: fn = fn.bind(thisArg); Despite trying various techniques, I