Try this. Pass the (unshared) richtext window object to the thread as a parameter and then use it. It works fine.

This minimally modified version of the sample program starts a thread that sits in the background, periodically quering the text from the RichEdit Window and prints it to terminal. As you type into the window you will see what you type printed to the shell window from where you started the program.

#! perl -slw use strict; use threads; use threads::shared; use Win32::GUI; sub thread { my( $Textbox ) = @_; while( 1 ) { sleep 3; print $Textbox->Text; } } my $Font = new Win32::GUI::Font( -name => "Courier New", -height => 16, ); my $Menu = Win32::GUI::MakeMenu( "&File" => "File", "> &Load" => "FileLoad", "> &Save" => "FileSave", ); my $Window = new Win32::GUI::Window( -name => "Window", -text => "Win32::GUI TEST - RichEdit", -width => 500, -height => 400, -left => 100, -top => 100, -font => $Font, -menu => $Menu, ); my( $text ); my $Textbox = $Window->AddRichEdit( -name => "Text", -text => $text, -left => 5, -top => 5, -width => $Window->ScaleWidth-10, -height => $Window->ScaleHeight-10, -style => WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, -exstyle => WS_EX_CLIENTEDGE, ); threads->new( \&thread, $Textbox )->detach; $Window->Show(); Win32::GUI::Dialog(); sub Window_Resize { my ($width, $height) = ($Window->GetClientRect)[2..3]; $Textbox->Resize($width-10, $height-10); } sub FileSave_Click { $Textbox->Save("richedit.rtf"); } sub FileLoad_Click { $Textbox->Load("richedit.rtf"); } sub Window_Terminate { return -1; }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re: Sharing Win32::GUI::RichEdit... by BrowserUk
in thread Sharing Win32::GUI::RichEdit... by Ace128

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.