From: Robert M. <rm...@po...> - 2005-07-15 19:08:25
|
Dan, $re->Text() behind the scenes calls the win32api GetWindowText API,=20 which in turn sends a WM_GETTEXT message to the richedit control. As far=20 as I can see there is no Unicode version of GetWindowText.. You=20 actually need to send a EM_GETTEXTEX message (see msdn for more=20 information). This message can be set to get the text in unicode=20 (UCS-2) and that then needs to be converted to perl characters. As Win32::GUI does not support the EM_GETTEXTEX message, calling it is=20 somewhat tricky, but the following seems to work here. If you'd like=20 native support for EM_GETTEXTEX, then please raise a RFC. Regards, Rob. #! perl -w use strict; use warnings; use Win32::GUI; # constants: sub WM_USER() {1024}; sub EM_GETTEXTEX() {+WM_USER+94}; sub GT_DEFAULT() {0}; my $w =3D Win32::GUI::Window->new( -name =3D> 'Main', -size =3D> [800, 600], ); my $re =3D $w->AddRichEdit( -size =3D> [600, 400], ); $w->AddButton( -name =3D> 'btnChange', -pos =3D> [600, 500], -text =3D> '$re->Text($re->Text)', ); my $rtf_prolog =3D '{\rtf1\ansi\deff0 {\fonttbl{\f0 \fcharset1\fnil Times New Roman;}} {\stylesheet {\*\cs0 \additive Default Paragraph Font;}}'; $re->Text($rtf_prolog . 'This, \u305?, is not exactly the letter i' . '}'= ); $w->Show(); Win32::GUI::Dialog(); exit(0); sub btnChange_Click { my $text1 =3D $re->Text(); my $maxlen =3D 1024; my $buffer =3D " " x $maxlen; my $flags =3D GT_DEFAULT; my $codepage =3D 1200; my $struct =3D pack("LLIpp", $maxlen, $flags, $codepage, undef, undef= ); my $address =3D pack("P20", $struct); my $wparam =3D unpack("L", $address); my $numTchar =3D $re->SendMessage(EM_GETTEXTEX, $wparam, $buffer); my $octets =3D substr($buffer, 0, ($numTchar*2)); use Encode qw/decode/; my $text2 =3D decode("UCS-2LE", $octets); print "--$text1--\n"; print "--$text2--\n"; return 1; } __END__ Dan Dascalescu wrote: >I'm trying to get a useful Perl representation of the Unicode string >edited by the user in a RichEdit. It turned out that if I use >$RichEdit->Text, some Unicode characters are corrupted (transformed to >Latin equivalents). The same happens for GetSelText. > >In other words, $RichEdit->Text($RichEdit->Text) corrupts the text! > >I looked in RichEdit.xs, then at >http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/shell= cc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/r= icheditmessages/em_setoptions.asp >, but I couldn't figure out a fix. > >So is there a way to retrieve the intact Unicode content of a RichEdit? >The code below demonstrates the problem (should I submit it as a bug?). > >Or, is there a way to retrieve the RTF behind the RichEdit, other than >by doing a Save and reading the file? > >Thanks, >Dan > >#! perl -w >use strict; >use Win32::GUI; > >my $w =3D Win32::GUI::Window->new( > -name =3D> 'Main', > -size =3D> [800, 600], >); > >my $re =3D $w->AddRichEdit( > -size =3D> [600, 400], >); > >$w->AddButton( > -name =3D> 'btnChange', > -pos =3D> [600, 500], > -text =3D> '$re->Text($re->Text)', >); > >my $rtf_prolog =3D '{\rtf1\ansi\deff0 >{\fonttbl{\f0 \fcharset1\fnil Times New Roman;}} >{\stylesheet {\*\cs0 \additive Default Paragraph Font;}}'; > >$re->Text($rtf_prolog . 'This, \u305?, is not exactly the letter i' . '}= '); > >sub btnChange_Click { > $re->Text($re->Text); >} > > >$w->Show; > >Win32::GUI::Dialog(); > >sub Main_Terminate { > -1; >} > > >------------------------------------------------------- >SF.Net email is sponsored by: Discover Easy Linux Migration Strategies >from IBM. Find simple to follow Roadmaps, straightforward articles, >informative Webcasts and more! Get everything you need to get up to >speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&op=CCk >_______________________________________________ >Perl-Win32-GUI-Users mailing list >Per...@li... >https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users > > =20 > |