Adding special characters to buttons
-
- In need of some credit
- Posts: 7
- Joined: Mon Aug 01, 2022 8:47 pm
Adding special characters to buttons
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?
-
- Moderator
- Posts: 19163
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Re: Adding special characters to buttons
Wrap the string literal with the unicode char with the wxT() macro. This will enforce a string with wide (more than 8 bit) characters.
If that doesn't work, please show the code where you set the button label and tell us which platform you're using.
Code: Select all
wxT("\u232B")
Use the source, Luke!
-
- In need of some credit
- Posts: 7
- Joined: Mon Aug 01, 2022 8:47 pm
Re: Adding special characters to buttons
Thanks that worked!
-
- In need of some credit
- Posts: 8
- Joined: Sat Dec 11, 2021 9:52 pm
Re: Adding special characters to buttons
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: 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:
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.
Code: Select all
/utf-8
Code: Select all
wxString::FromUTF8("your string here")