Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MessageBox does not print UNICODE characters

Tags:

c++

winapi

I'm using the following to print a message in a Win32 API MessageBox:

MessageBox(hWnd, TEXT("Já existe um controlador em execução"), TEXT("Erro"), 0);

MessageBox is a macro and is expanding to MessageBoxW. The trouble is that it doesn't print Unicode, whereas the window that calls it prints Unicode without any issue, it seems that this is a problem with MessageBox itself.

Does anyone know how to solve this?

FYI, I also tried:

MessageBoxEx(hWnd, TEXT("Já existe um controlador em execução"), TEXT("Erro"), 0, MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE));

But it's the same, as expected.

Here is a picture of the call with the expansion:

enter image description here

And it prints:

enter image description here

Note that the main window menu has unicode characters that are printed correctly.

like image 970
anastaciu Avatar asked Oct 21 '25 00:10

anastaciu


1 Answers

To avoid source-code encoding based problems in the future, you can use \uxxxx style escape characters for non-ascii characters:

MessageBoxW(nullptr, L"J\u00E1 existe um controlador em execu\u00E7\u00E1o", L"Erro", MB_OK);
like image 147
Ayxan Haqverdili Avatar answered Oct 23 '25 14:10

Ayxan Haqverdili



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!