RE: [perl-win32-gui-users] Thread Safe Message Passing
Since I was looking for something slightly different than Rob had provided, I managed to make use of his example (TY Rob) and turn it around into something more 'famliliar'. Thanks for posting the code - the more feedback and comments, the better the final solution will be:) The attached 2 files: ThreadSafe.pm Threadsafe_1.pl The module is built around the idea that there *had* to be a way to get messages from the windows thread (main aka tid == 0 ) to the child threads. Would this be the correct usage of your module: #Add this after the window has been created $win->AddButton( -name => 'test', -text => 'test', -pos => [114, 10], -height => 20, -onClick => \&butclick, ); sub butclick { for (1..5) { $win->SendMessage(WM_PIPE1,M_DATA,['some data',$_]); $win->SendMessage(WM_PIPE2,M_DATA,['some data',$_]); } } When the button is clicked, 5 messages are sent to both spawned threads. Is that correct? Would be correct to say that the essence of your package is that it allows the main thread to communicate with child threads via the windows message queue? Cheers, jez.
RE: [perl-win32-gui-users] Thread Safe Message Passing
Yes, it is correct that it allows the main thread to communicate with the child threads via the Window Message Queue (though I am workin on a way to make it last beyond the Window's lifespan). And techinically... no, sending data that way wont work quite yet... but that is the general idea in the end. I plan on moving things to a ThreadsSafe::SendMessage() form in order to allow lifespan of the children beyond that of the window message queue, as well as provide and *easy* way of transfering the data to that queue. the format for sending message then would be more along ths lines of: ThreadsSafe::SendMessage(MESSAGE, WPARAM, LPARAM[, DATA]); the reference is a scalar/list/hash/storable object, that will be frozen by storable and then put on the destination threads's queue, where it will be sent over to the callback for that threads, in its original form via thaw. But I think you get the general idea. :) Jason P. -Original Message- From: Jeremy White [mailto:[EMAIL PROTECTED] Sent: Sat 2/11/2006 5:19 AM To: Plum, Jason; perl-win32-gui-users@lists.sourceforge.net Subject: RE: [perl-win32-gui-users] Thread Safe Message Passing >Since I was looking for something slightly different than Rob had >provided, I managed to make use of his example (TY Rob) and turn it >around into something more 'famliliar'. Thanks for posting the code - the more feedback and comments, the better the final solution will be:) >The attached 2 files: >ThreadSafe.pm >Threadsafe_1.pl > >The module is built around the idea that there *had* to be a way to get >messages from the windows thread (main aka tid == 0 ) to the child >threads. Would this be the correct usage of your module: #Add this after the window has been created $win->AddButton( -name => 'test', -text => 'test', -pos => [114, 10], -height => 20, -onClick => \&butclick, ); sub butclick { for (1..5) { $win->SendMessage(WM_PIPE1,M_DATA,['some data',$_]); $win->SendMessage(WM_PIPE2,M_DATA,['some data',$_]); } } When the button is clicked, 5 messages are sent to both spawned threads. Is that correct? Would be correct to say that the essence of your package is that it allows the main thread to communicate with child threads via the windows message queue? Cheers, jez.
RE: [perl-win32-gui-users] Thread Safe Message Passing
Hello again all, I've sorted out how to pass the parameters from thread to thread via a wrapper around SendMessage. I've worked in an allowance for SendMessage (via SendMessageTimeout) to silently fail if the Window has finished. This is NOT a good way to do it. Do NOT rely on this. Of course this is far from Production code... so don't use it for production. Have a look, a pry, and some poking, and tell me what you think :) Jason P. threadsafe_2.pl Description: threadsafe_2.pl ThreadSafe.pm Description: ThreadSafe.pm
[perl-win32-gui-users] Problem with (Shift)Tab key
Hello to everybody! I'v got the following problem. I want the Up,Down,Tab and ShiftTab keys work in tables as usual. It means Tab changes only columns to right on so on. The working example is enclosed. ONE THING bother me; when I press Tab key a sound from computer is sending as it was error. This sound is not emited when I press Up and Down keys. How to manage? Could anyone help me? Waldemar Biernacki #!/usr/bin/perl -w use strict; use Win32::GUI; my $mw = new Win32::GUI::Window( -name => "Main", -width => 900, -height => 400, # -tabstop=>1, ); #$mw->DialogUI( 1 ); my @edit = (); my $dimX = 4; my $dimY = 4; for ( my $i = 0; $i < $dimY; $i++ ) { for ( my $j = 0; $j < $dimX; $j++ ) { $edit[$i][$j] = $mw->AddTextfield ( -text => $i.'x'.$j, -name => 'edit'.$i.$j, -left => 50 + 100*$j, -top=> 50 + 20*$i, -width => 99, -height => 20, # -tabstop=> 1, # -dialogui => 1, ); eval ('sub edit'.$i.$j.'_KeyDown { what_to_do( '.$i.','.$j.' ) }'); } } sub what_to_do { my ( $i, $j ) = ( shift, shift ); my $hash_EVENT = Win32::GUI::GetKeyboardState; my $_EVENT = what_event( $hash_EVENT ); my $nextX = $j + 1; $nextX = 0 if $nextX >= $dimX; my $prevX = $j - 1; $prevX = $dimX-1 if $prevX < 0; my $nextY = $i + 1; $nextY = $dimY-1 if $nextY >= $dimY; my $prevY = $i - 1; $prevY = 0 if $prevY < 0; if ( $_EVENT eq 'Tab' ) { $edit[$i][$nextX]->SetFocus() } if ( $_EVENT eq 'ShiftTab' ) { $edit[$i][$prevX]->SetFocus() } if ( $_EVENT eq 'Up' ) { $edit[$prevY][$j]->SetFocus() } if ( $_EVENT eq 'Down' ) { $edit[$nextY][$j]->SetFocus() } } $edit[0][0]->SetFocus(); $mw->Show(); Win32::GUI::Dialog(); sub Main_Terminate { -1; } sub what_event { my $_EVENT = shift; my $result = ''; my $SHIFT = ''; if (( $_EVENT->[160] )||( $_EVENT->[161] )) { $SHIFT = 'Shift' } for ( my $i = 0; $i < 256; $i++ ) { if ( $_EVENT->[$i] ) { if( $i == 9 ) { $result = $SHIFT.'Tab' } elsif ( $i == 38 ) { $result = $SHIFT.'Up' } elsif ( $i == 40 ) { $result = $SHIFT.'Down'} } } return $result; } __END__ exam.pl Description: Binary data