c++winapi

WM_SETTEXT writes unicode character


I wrote a small piece of code like this

// Handle = notepad
// set text to send
std::wstring message_to_send = L"xin chào bạn";
// send message
DWORD_PTR result;
SendMessageTimeoutW(Handle, WM_SETTEXT, (WPARAM)0, (LPARAM)message_to_send.c_str(), SMTO_ABORTIFHUNG, 1000, &result);

but the text pasted in notepad is not correct: xin chào bạn

Where did I go wrong, what do I need to do to fix this?

I try set the project setting Use Unicode Character Set and file save as encoding UTF8 but it still error


Solution

  • As @Remy Lebeau said, The result you show looks like UTF-8 that has been misinterpreted in an ISO/Latin charset instead. You can tell the compiler that the file is UTF-8.

    You can set it like Visual studio in here:

    enter image description here

    Please refer to the /source-charset and /utf-8 compiler options.