Hello all, When I was trying to learn how to use threads with Win32::Gui, I got help from a lot of people on this list. I wrote this code as a way to test it.
Basically without the thread when the sleep command runs the window become unresponsive, with threads you can keep doing things to the window. use Win32::GUI; use threads; use vars qw( $MainWin ); $howlong = 180; $MainWin = new Win32::GUI::Window( -name => "MainWin", -text => "Fork Test", -width => 500, -height => 700, -left => 100, -top => 100, -menu => $Menu, -font => $Font, ); $MainWin->AddButton( -name => "Button1", -text => "TEST", -align => center, -valign => center, -left => 350, -top => 10, ); $RTF = $MainWin->AddRichEdit( -name => "RTF", -left => 10, -top => 50, -width => $MainWin->ScaleWidth-20, -height => $MainWin->ScaleHeight-70, -multiline => 1, -addstyle => ES_READONLY, ); $MainWin->Show(); Win32::GUI::Dialog(); sub MainWin_Terminate { return -1; } sub Button1_Click { $MainWin->Button1->Disable(); $info = "I can send stuff"; threads->create(\&do_stuff, $info)->detach; } sub do_stuff { $RTF->ReplaceSel("Hello I am the child process and like any child I'm going to sleep while my parent keeps working.\r\n"); $RTF->ReplaceSel("So go ahead an minimize the window, move it, go to other windows and then back to this one.\r\n"); $RTF->ReplaceSel("My parent will do all the work.\r\n"); $RTF->ReplaceSel("$_[0].\r\n"); $MainWin->Update(); $MainWin->DoEvents(); sleep($howlong); $RTF->ReplaceSel("Finished sleeping\r\n"); $MainWin->Button1->Enable(); } |---------+------------------------------------------------> | | "Jez White" | | | <[EMAIL PROTECTED]> | | | Sent by: | | | [EMAIL PROTECTED]| | | ceforge.net | | | | | | | | | 11/28/2004 07:09 AM | | | | |---------+------------------------------------------------> >----------------------------------------------------------------------------------------------------------| | | | To: "Harlan Carvey" <[EMAIL PROTECTED]>, "Alex Lee" <[EMAIL PROTECTED]>, "Win32-GUI List" | | <perl-win32-gui-users@lists.sourceforge.net> | | cc: (bcc: Joseph Vieira/DMR/CA) | | Subject: Re: FW: [perl-win32-gui-users] Website - Code snippets gallery | >----------------------------------------------------------------------------------------------------------| Hi, > I can put together GUIs...been doing it in Java, Tk, > and using Win32::GUI. One thing I'd be interested in > would be how to write a Windows app that has a GUI > that responds when you click buttons, but the > underlying activities/background processes continue to > run. This is doable by using threads - you will probably better of using the latest version of Perl (5.8.4?) as you can, since threading is generally weak in early versions. Win32::gui seems fine with threads since I've been able to create C threads (via an xs module) which were able to fire events in the GUI via windows SendMessages. Cheers, jez. ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/ _______________________________________________ Perl-Win32-GUI-Users mailing list Perl-Win32-GUI-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users