Adding special characters to buttons

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
vignes_12
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 01, 2022 8:47 pm

Adding special characters to buttons

Post by vignes_12 »

I am trying to create a button with a label of the backspace key ⌫; however, when I try to do so I am getting this error "warning C4566: character represented by universal-character-name '\u232B' cannot be represented in the current code page (1252)" and the backspace key is being represented as a question mark instead. Is there a way to fix this problem?
User avatar
doublemax
Moderator
Moderator
Posts: 19163
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Adding special characters to buttons

Post by doublemax »

Wrap the string literal with the unicode char with the wxT() macro. This will enforce a string with wide (more than 8 bit) characters.

Code: Select all

wxT("\u232B")
If that doesn't work, please show the code where you set the button label and tell us which platform you're using.
Use the source, Luke!
vignes_12
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 01, 2022 8:47 pm

Re: Adding special characters to buttons

Post by vignes_12 »

Thanks that worked!
randalphwa
In need of some credit
In need of some credit
Posts: 8
Joined: Sat Dec 11, 2021 9:52 pm

Re: Adding special characters to buttons

Post by randalphwa »

It sounds like you are using a Windows compiler (hence the 1252 code page) (cl or clang-cl?). If so, then for a different approach, you could tell the compiler that you are using utf8 by adding the compiler switch:

Code: Select all

/utf-8
This will allow you to enter your special characters exactly as they appear so that anyone else reading the code will know what '\u232B' actually looks like. Note that UTF8 is the default for Unix compilers, so no switch needed there. On Windows, you do still need to let wxWidgets know that this string must be converted to UTF16 before passing it off to a UI control such as wxButton by calling:

Code: Select all

wxString::FromUTF8("your string here")
Obviously that's a lot more work, but it does make your code more readable, and works with any kind of international characters, not just the one you are currently working with.