Hello All,

I've been recently asked how to display Unicode characters in controls
other than RichEdit. The first answer that came to mind was to set the
-charset parameter of the Win32::GUI::Font object to 65001, the code
page for UTF-8. I tried that, but either the charset had no effect
(maybe Win32::GUI should have used CreateFontW instead of CreateFont
?), or AddLabel treated the string as binary.

In any case, I spent about 20 minutes searching the MSDN for the
corresponding documentation for
http://perl-win32-gui.sourceforge.net/cgi-bin/docs.cgi?doc=font, so I
urge Rob or someone to add this link to Win32::GUI::Font's
documentation:
http://msdn2.microsoft.com/en-us/library/ms534214.aspx

Here's the code:

#! perl -w
use strict;
use Win32::GUI;
use utf8;  # enable Perl to parse UTF-8 from this file

my $string = 'Râşniţă';
print $string;  # this should warn about "Wide character in print",
confirming that $string was correctly parsed from UTF-8 into Perl's
internal representation

# Create a font with the UTF8 charset
my $win_font = Win32::GUI::Font->new(
   -name => 'Arial Unicode MS',
   -charset => 65001,
);

my $main = Win32::GUI::Window->new(
   -name => 'Main',
   -size => [400, 300],
   -font => $win_font,
);

# The Label will inherit $win_main's font
my $label = $main->AddLabel(
   -text => $string,
);

$main->Show;
Win32::GUI::Dialog();


Thanks,
Dan

Reply via email to