Hi,

I have used Win32::API and Encode to accomplish this directly via
SetWindowTextW function which takes a UTF-16LE string argument:

    use Win32::API;
    use Encode;

    our $SetWindowTextW_fn = undef;
    sub text {
    my ($control, $text) = @_;
    if (not $SetWindowTextW_fn) {
    $SetWindowTextW_fn = Win32::API->new("user32", "SetWindowTextW",
    "NP", "N");
    die unless $SetWindowTextW_fn;
    }
    $SetWindowTextW_fn->Call($control->{-handle}, t2w($text));
    }

    # t2w - convert arbitrary string (may be unicode or not) to UTF-16LE
    # encoding. Windows uses UTF-16LE as its native Unicode encoding (the
    # "W" version of functions).
    sub t2w {
    my ($text) = @_;
    return encode("UTF-16LE", $text . "\x00");
    }

Since the "encode" function follows the normal Perl unicode'ness rules
it will work correctly if you give it an unicode string (as long as it
has been decoded to perl's internal format, of course). For example,
text($label, "\x{0032}\x{2208}\x{007b}\x{0032}\x{007d}") should work.
Ought. Might. :-)

*Note*: I have not extensively tested whether this works for all unicode
codepoints - it was a hack I needed to get some characters shown
correctly and after that was accomplished I have never looked at the
code since. Also, this worked with 1.03. I have not tried it with more
recent Win32::GUI versions.

Hope this helps,

Santeri Paavolainen

Glenn Linderman wrote:
> On approximately 11/27/2006 10:34 PM, came the following characters from 
> the keyboard of Octavian Rasnita:
>   
>>> I can't actually help you here, off the top of my head, but it is an
>>> area that I am interested in.  Have you noted Dan Dascalescu's post on
>>>
>>> Date: Sat, 18 Nov 2006 18:44:57 -0800
>>>       
>> Hi,
>>
>> Yes, I have also "talked" on private with Dan. He told me that he tried to
>> initialize some fonts, and to specify the charset for them. He tried very
>> many charsets, but the result was always the same: the program was using the
>> default ISO-8859-1.
>>
>> It is too bad if Win32::GUI can use only a single charset because it is the
>> most accessible GUI library for screen readers, and I will need to try using
>> another one like WX...
>>
>> Thanks.
>>
>> Teddy
>>     
>
> OK.  I was under the impression that Dan had had some success with the 
> code he posted.  I guess I misunderstood... by suggesting adding 
> documentation links to the Win32::GUI documentation, I thought he'd 
> found some clever way to bypass the limitations of Win32::GUI... which 
> has been known not to support Unicode for some time (other than in 
> RichEdit controls)... Unicode is on Robert's list, I think.
>
> Win32::GUI does use the "A" version of the Win32 APIs... so given that, 
> I would expect (but have never tested) that any single-byte code page 
> could be used.  I think I recall seeing posts from people that have 
> gotten various code pages to work, but I'm not sure I could find them again.
>
>
>   

Reply via email to