Page 1 of 1

Unicode not working in wxWidgets Windows Console?

Posted: Sun Aug 23, 2009 2:45 am
by AnotherCoder
Hi, I am new to wxWidgets and am using it in Microsoft Visual C++ 2008. I can get this program from the Hello World Tutorial running just fine.

How come this program outputs question marks when I try to compile in release mode:

Code: Select all

#include <wx/string.h>

int main(int argc, char **argv)
{
	wxPuts(wxT("言語"));
}
This is the output:

Code: Select all

??
Press any key to continue . . .
I already built wxWidgets libraries for Debug, Release, and Unicode - Release.[/code]

Posted: Sun Aug 23, 2009 5:01 am
by catalin
More likely "Unicode not working in Windows console". ;)

Unicode is not "very" supported in win console.
See if this article helps.

Posted: Sun Aug 23, 2009 5:07 am
by AnotherCoder
Thanks.
I will look at that link tomorrow.
Sorry, but I need to go now.

Will try to respond in less than 10 hours :oops:

EDIT: I updated the title in the first post.

Posted: Sun Aug 23, 2009 2:38 pm
by Auria
I somewhat doubt you can use wx functions like this from "main" without wxWidgets being initialized first... not sure it's linked with your issue though

Posted: Sun Aug 23, 2009 5:29 pm
by AnotherCoder
Okay, now I am even more confused. After reading the article, I got this far:

Code: Select all

#include <wx/string.h>
#include <wx/utils.h>
#include <windows.h>

int _tmain()
{
	//Store the old console format in 'oldcp'
	UINT oldcp = GetConsoleOutputCP();
	SetConsoleOutputCP(CP_UTF8);
	wchar_t s[] = L"aΣb";
	int bufferSize = WideCharToMultiByte(CP_UTF8, 0, s, -1, NULL, 0, NULL, NULL);
	char* m = new char[bufferSize];
	WideCharToMultiByte(CP_UTF8, 0, s, -1, m, bufferSize, NULL, NULL);
	wxPrintf("%S", m);
	delete[] m;


	//Restore the console format
	SetConsoleOutputCP(oldcp);
}
However, all I get is:

Code: Select all

Press any key to continue . . .
????????

Posted: Sun Aug 23, 2009 5:54 pm
by catalin
AnotherCoder wrote:

Code: Select all

	wxPrintf("%S", m);
Does printf (any kind of it..) work with capital 'S' ? I don't remember ever trying..

Also, are you sure that the font used to display the characters in the console has the glyphs for the ones you want to print?

Posted: Sun Aug 23, 2009 5:58 pm
by AnotherCoder
Well, the guide I read said that I needed to change the font Lucida Console, but I don't know how to do this :oops:

Also, the article said to use "%S" because "it tells the wprint function to expect narrow string"

Thanks for all your responses.

Posted: Sun Aug 23, 2009 6:15 pm
by catalin
AnotherCoder wrote:Well, the guide I read said that I needed to change the font Lucida Console, but I don't know how to do this
Open a console, right click its title bar, choose Properties -> Font -> choose "Lucida Console" from the list there -> hit OK

Unicode in GUI?

Posted: Sun Aug 23, 2009 6:25 pm
by AnotherCoder
Okay, I've changed the font, but I am still only getting:

Code: Select all

Press any key to continue . . .
Well, I guess it is not so important to print Unicode in console. But, will Unicode work in normal GUI programs?

EDIT:
I'll just post a new topic with the Unicode in GUI applications:
http://forums.wxwidgets.org/viewtopic.php?p=108225
Thanks.

Posted: Mon Aug 24, 2009 12:52 am
by samsam598