in reply to Sharing Win32::GUI::RichEdit...
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sharing Win32::GUI::RichEdit...
by Ace128 (Hermit) on Jul 06, 2005 at 15:50 UTC | |
by jplindstrom (Monsignor) on Jul 06, 2005 at 18:54 UTC | |
by Ace128 (Hermit) on Jul 07, 2005 at 23:58 UTC |