π 2010-Jan-13 ⬩ βοΈ Ashwin Nanjappa ⬩ π·οΈ unicode, wxwidgets ⬩ π Archive
wxWidgets can be compiled to pure Unicode mode by setting wxUSE_UNICODE
to 1
in the header file $(WX_WIDGETS_ROOT)\include\wx\msw\setup.h
But what if the rest of your code that interfaces with Unicode wxWidgets is still not Unicode, but uses char
and STL std::string
? The changes needed at the interface are:
Wrap all characters and string literals passed to wxWidgets in wxT()
. It converts them to Unicode. Ex: wxT("Hell World!")
wxWidget functions do not deal with STL std::string
but with wxString
. Do the conversion using wxConvUTF8
, which is an instance of the wxMBConv
class. MBConv
stands for Multi-Byte Conversion, it helps to convert between Multi-Byte formats and Unicode. wxConvUTF8
as you can guess converts multi-byte to the UTF-8 Unicode encoding. Ex:
std::string stdStr(βHell World!β); wxString wxStr(stdStr.c_str(), wxConvUTF8);
When wxWidgets functions throw out a wxString
, convert them back to char
string using wxString::mb_str()
. This returns the multi-byte representation of the internal Unicode text in wxString
.
If you are curious about this fishy Multi-Byte business, check out Windows: Multi-Byte.