Search code examples
c++visual-c++visual-studio-2013mfc

How to print symbol "↑" using AfxMessageBox?


How can I print this symbol "↑" using AfxMessageBox()?

I try to code it like this:

AfxMessageBox("↑");

After compiling, I got a strange symbol:

image

Does AfxMessageBox() not support this symbol?


Solution

  • Your source file is likely saved as UTF-8. To work with MBCS string literals, your source file needs to be saved in the same charset that your OS user locale is set to. Unfortunately, not many charsets support this particular character, I think. Otherwise, you have to switch to Unicode.

    If you can’t switch the whole app to Unicode, then you can at least use MessageBoxW() instead, eg:

    ::MessageBoxW(NULL, L"↑", L"title", MB_OK);
    

    Or

    ::MessageBoxW(NULL, L"\x2191", L"title", MB_OK);