Unicode not working in wxWidgets Windows Console? 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
AnotherCoder
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Aug 23, 2009 2:34 am
Location: USA

Unicode not working in wxWidgets Windows Console?

Post 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]
Last edited by AnotherCoder on Sun Aug 23, 2009 5:08 am, edited 1 time in total.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post by catalin »

More likely "Unicode not working in Windows console". ;)

Unicode is not "very" supported in win console.
See if this article helps.
AnotherCoder
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Aug 23, 2009 2:34 am
Location: USA

Post 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.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post 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
"Keyboard not detected. Press F1 to continue"
-- Windows
AnotherCoder
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Aug 23, 2009 2:34 am
Location: USA

Post 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 . . .
????????
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post 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?
AnotherCoder
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Aug 23, 2009 2:34 am
Location: USA

Post 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.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Post 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
AnotherCoder
Earned a small fee
Earned a small fee
Posts: 14
Joined: Sun Aug 23, 2009 2:34 am
Location: USA

Unicode in GUI?

Post 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.
samsam598
Super wx Problem Solver
Super wx Problem Solver
Posts: 340
Joined: Mon Oct 06, 2008 12:55 pm

Post by samsam598 »

Regards,
Sam
-------------------------------------------------------------------
Windows 10 64bit
VS Community 2019
msys2-mingw13.2.0 C::B character set: UTF-8/GBK(Chinese)
wxWidgets 3.3/3.2.4 Unicode Mono Static gcc static build
Post Reply