jpavel has asked for the wisdom of the Perl Monks concerning the following question:

G'day, good monks: My code for this portion of a project I'm working on is a mess - I can provide snippets if it'll help, but I think my problem lies in overall orchestration and comprehension.

I'm trying to write to a Win32::GUI RichEdit field with a highlighted word. The script scrapes output from another function and prints it out. I was originally using a Textfield, but that does not allow for variations in text. I know I need to write a prolog at initialization, then have my script print the lines with the word highlighted. There is no user interaction for this portion.

The problem I'm running into is that either my \'s get printed literally (so \fs20 is \\fs20 in the raw document) or they get completely misinterpreted and get turned into funky characters that I have no explanation for.

So - anybody ever print out rtf strings to a Win32::GUI Richedit window before? I don't mind including other modules; I've been fiddling with RTF::Writer's new_to_string with no success. Thanks again!

Replies are listed 'Best First'.
Re: Writing to a Win32::GUI RichEdit
by jpavel (Sexton) on Jun 02, 2009 at 13:49 UTC
    For anyone coming back here in the future, here's my solution:
    if ($ltext =~ m/^(.*)($searchvalue)(.*)$/igm) { $matches->Select(1e9, 1e9); $matches->ReplaceSel("$server: $1"); $matches->Select(1e9, 1e9); $matches->SetCharFormat( -bold =>1, -height =>260, -color =>0xFF0000 ); $matches->ReplaceSel($2); $matches->Select(1e9, 1e9); $matches->SetCharFormat( -bold =>0, -height =>170, -color =>0x000000 ); $matches->ReplaceSel("$3\r\n\r\n"); }