in reply to Win32 GUI - Problem with text input field
Initial diagnosis and why Win32::GUI is bad :)
Hello, I am currently trying to design a simple perl program with Win32::GUI.
Win32::GUI is a dead end, hasn't been updated in forever, doesn't support unicode.... other problems with Win32::GUI and why I laught at those choosing Win32::GUI
If the sub window is called again in the same season, no new input is being accepted... Does anyone know how to solve that problem?
I assume its because of the way you write code , the way Win32::GUI docs encourage, the nested subs memory leaking closure way; see write Tk callbacks all lexically scoped and not-memory leaking with no nested subs ever :) avoid nested subs and closures because nested named subs because they're closures
update: yup, my assumption was correct; if you add use warnings; you will be warned about this Variable "$main" will not stay shared ... Variable "$add" will not stay shared a ...
update: your code fixed up
#!/usr/bin/perl -- ## ## ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Win32::GUI(); Main( @ARGV ); exit( 0 ); sub Main { my $mainWindow = MainWindow(); warn "Dialog ", $mainWindow->Dialog; return; } sub MainWindow { my $main = Win32::GUI::Window->new( -width => 840, -height => 480, -text => 'Main', ); $main->AddButton( -width => 130, -height => 60, -pos => [ 100, 100 ], -text => 'Sub', -onClick => sub { warn "onClick @_ "; IncrementButtonText( @_ ); AddWindow( @_ ); ## launch another dialog? icky }, ); $main->AddButton( -width => 66, -height => 24, -pos => [ 750, 410 ], -text => 'Exit', -onClick => sub { warn "onClick @_ "; return -1; ## end this mainloop }, ); $main->Show(); return $main; } ## end sub MainWindow sub IncrementButtonText { my( $button ) = @_; my $text = $button->Text; $text =~ s{(\d*)$}{ 1 + ($1?$1:0) }e; $button->Text( $text ); return $button; } sub AddWindow { my $add = Win32::GUI::Window->new( -width => 840, -height => 480, -text => 'Add', -onTerminate => sub { warn "onTerminate @_ "; return 1; ## end this dialog }, ); $add->AddTextfield( -width => 360, -height => 130, -pos => [ 100, 100 ], -text => join( ' ', 'Input', scalar gmtime, scalar localtim +e ), -name => 'input', ); my $endthisdialog = sub { AddEnd( $add, @_ ); undef $add; 0; }; $add->AddButton( -width => 130, -height => 60, -pos => [ 100, 300 ], -text => 'Submit', -onClick => $endthisdialog, ); $add->AddButton( -width => 66, -height => 24, -pos => [ 750, 410 ], -text => "Back", -onClick => $endthisdialog, ); $add->Show(); return $add->Dialog(); } ## end sub AddWindow sub AddEnd { warn "AddEnd @_ "; my( $add, $button ) = @_; print $add->input->Text(), "\n"; return; }
more generic win32 tips
If you want to automate anything on win32 you have to absorb the following knowledge . It mostly consists of learing the ole/excel/powerpoint... object model, and using Win32::OLE to call it or sending messages using guitest. OLE is essentially a fancy/standardised way of sending messages. Its very much like web-scraping, you have to know HTTP/HTML DOM .... the rest is just legwork
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Win32 GUI - Problem with text input field
by dasgar (Priest) on Oct 15, 2014 at 06:44 UTC | |
by Anonymous Monk on Oct 16, 2014 at 21:40 UTC | |
|
Re^2: Win32 GUI - Problem with text input field
by Andreas44 (Initiate) on Jun 17, 2014 at 18:00 UTC |