Newbie Unicode question - Is this ok? Topic is solved

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.
Post Reply
Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Newbie Unicode question - Is this ok?

Post by Ugly! » Wed Feb 28, 2007 9:35 am

Hi folks, I'm a little confused here. I've started using the Unicode build not long ago and I have a question/problem.
I'm using Visual C++ 2005 Express Edition.

When I do:

Code: Select all

wxLogMessage(wxT("
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

Jorg
Moderator
Moderator
Posts: 3971
Joined: Fri Aug 27, 2004 9:38 pm
Location: Delft, Netherlands
Contact:

Post by Jorg » Wed Feb 28, 2007 10:46 am

Please be aware that your source code is NOT unicode. So any character you use in there does not have to match to a unicode character per-ce as it might be displayed differently in another code page.

The best way is simply looking up the characters you want to display, and convert them by code to wxString, and display that in your dialog.

Regards,
-Jorgen
Forensic Software Engineer
Netherlands Forensic Insitute
http://english.forensischinstituut.nl/
-------------------------------------
Jorg's WasteBucket
http://www.xs4all.nl/~jorgb/wb

Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Post by Ugly! » Wed Feb 28, 2007 6:05 pm

Jorg wrote:Please be aware that your source code is NOT unicode. So any character you use in there does not have to match to a unicode character per-ce as it might be displayed differently in another code page.
I'm using windows XP. Isn't it supossed to be in Unicode? If it doesn't, where "is" the Unicode part in Windows XP???
Jorg wrote: The best way is simply looking up the characters you want to display, and convert them by code to wxString, and display that in your dialog.
Could you elaborate a little more here. Maybe with an example...

Btw, I'm using DialogBlocks for generating my GUI and I don't want to change the generated code everytime when bad characters appear.

Regards, Mat
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

geralds
I live to help wx-kind
I live to help wx-kind
Posts: 186
Joined: Tue Nov 01, 2005 9:22 am
Contact:

Post by geralds » Wed Feb 28, 2007 10:42 pm

You could experiment with source file encodings a little. On MinGW and Dev-C++, for example, Unicode characters need to be entered as UTF-8 even though the IDE displays them as multibyte garbage. I would have expected Visual C++ to handle Unicode characters entered in the IDE out of the box, but it's possible that changing the encoding will help.

In short, you shouldn't have to enter Unicode characters as code points (though as Jorg says, that's always an option).

-Gerald

Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Post by Ugly! » Wed Feb 28, 2007 11:22 pm

geralds wrote:I would have expected Visual C++ to handle Unicode characters entered in the IDE out of the box, but it's possible that changing the encoding will help.

-Gerald
Visual C++ 2005 Express Ed. does not seem to handle different encodings.
Actually, you cannot set the source file encoding anywhere at all.

For now I'm going with the internationalization option.
Use ascii characters in the source, create a catalog with poEdit and load the locale.

Works like a charm, but it's still a hack.
I blame M$ for this one (no Unicode support in source files?). :) (unless someone set me right)

Regards, Mat
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

alamgir99
Experienced Solver
Experienced Solver
Posts: 72
Joined: Tue Feb 20, 2007 2:16 am
Location: Melbourne, Australia

Post by alamgir99 » Thu Mar 01, 2007 5:53 am

Ugly! wrote: I blame M$ for this one (no Unicode support in source files?). :) (unless someone set me right)
Just confirming that studio 2005 handles unicode char in source files seamlessly. But I failed to display them, when run. Says, cant display in current codepage. It was my test program's fault i believe not MS's.

al

geralds
I live to help wx-kind
I live to help wx-kind
Posts: 186
Joined: Tue Nov 01, 2005 9:22 am
Contact:

Post by geralds » Thu Mar 01, 2007 7:48 am

As you say, the gettext route is failsafe (and I wouldn't call this solution a hack), but there simply has to be a way of doing this in the source file (though not necessarily in the IDE). It could be something as simple as a missing byte order mark at the start of the file. Perhaps the IDE defaults to local single-byte encoding unless a BOM is found?

Unfortunately I haven't got access to VC++, so I can't try this out.

Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Post by Ugly! » Thu Mar 01, 2007 8:11 am

alamgir99 wrote: Just confirming that studio 2005 handles unicode char in source files seamlessly. But I failed to display them, when run. Says, cant display in current codepage. It was my test program's fault i believe not MS's.
al
Sorry, I didn't understand. Would you care to elaborate please?
How are you using the characters?

What about wxLogMessage(wxT("
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot » Thu Mar 01, 2007 5:49 pm

Code::Blocks is an excellent IDE, and allows you to change the encodings that the files are opened in.

JS

Ugly!
Earned some good credits
Earned some good credits
Posts: 113
Joined: Mon May 09, 2005 5:11 am
Location: Argentina - BS AS

Post by Ugly! » Thu Mar 01, 2007 8:08 pm

JSThePatriot wrote:Code::Blocks is an excellent IDE, and allows you to change the encodings that the files are opened in.

JS
But I don't know where the problem is. Is it the IDE or the compiler? I'm guessing the compiler is the one that should support different source files encoding.
I'll give it a try any way...

Thnx, Mat
Just a newbie - Too many interests, not too many time.

Windows XP SP2
Kubuntu GNU/Linux - Feisty
wxActiveRecordGenerator (aka wxARG) maintainer
Find it at wxCode

Post Reply