4

I'm making a Win32 GUI application and I want to display the ↺ character on a button.

Normally, I think one would insert a unicode character like this:

HWND button = CreateWindow("BUTTON", "\u27F3",
        WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, size - 105,
        size - 29, 100, 24, hwnd, (HMENU)IDI_BUTTON,
        GetModuleHandle(NULL), NULL);

where "\u27F3" is the unicode character described here under "C/C++/Java" http://www.fileformat.info/info/unicode/char/27f3/index.htm

However, when I do this I don't get the arrow character but a different one? What's going wrong?

Thanks!

beenjaminnn
  • 752
  • 1
  • 11
  • 23
  • 1
    You need to either select a font that supports the Unicode character you want to display or use a bitmap image. – Captain Obvlious May 28 '13 at 03:40
  • if you don't care, getting such an image and use Image button might save you much time. – David May 28 '13 at 03:40
  • 12
    Um, you're putting a Unicode character in an Ansi string. That never ends well. – Raymond Chen May 28 '13 at 03:43
  • 1
    I'm assuming that the motivation for doing this instead of using text like "Back" is limited space. If so, that's all fine and good, but strongly consider adding a tooltip to your button that displays a textual explanation of its function on mouse over. Something as simple as "Go Back" is fine—just don't assume the user knows exactly what ↺ means. – Cody Gray - on strike May 28 '13 at 08:04

2 Answers2

8

I'm going to shamelessly steal from Raymond Chen's comment and show the corrected code:

HWND button = CreateWindowW(L"BUTTON", L"\u27F3",
        WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, size - 105,
        size - 29, 100, 24, hwnd, (HMENU)IDI_BUTTON,
        GetModuleHandle(NULL), NULL);

Naturally the font you have selected into the window will need to support the character.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • Actually, recent versions of Windows are capable of selecting another font for missing glyphs, so it's possible it will "just work" anyway. – Igor Skochinsky May 28 '13 at 12:54
0

Well, you could also do this , also this isn't much different from @Mark Ransom answer :-

HWND button = CreateWindowW(TEXT("BUTTON"), TEXT("\u27F3"),
    WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, size - 105,
    size - 29, 100, 24, hwnd, (HMENU)IDI_BUTTON,
    GetModuleHandle(NULL), NULL);

and define a UNICODE in your program like this :-

 #define UNICODE 

Explanation :- TEXT is a macro which expands to unicode equivalent if UNICODE is defined other wise it evaluates to normal ASCII string.

Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97
  • The `TEXT` macro is only useful if you want to be able to switch from one character type to another. If you use the API functions that end in `A` or `W` you're already locked into the character type for the parameters, so I prefer to be explicit about it. I also see `_T` more than `TEXT` even though they mean the same thing. – Mark Ransom Sep 01 '16 at 18:26