From: zak <cho...@gm...> - 2008-06-02 08:48:56
|
hi here is an example for using perl and win32 gui to run an excellent Dos Prompt Factorizing program in a windows GUI : it is for demonstrating the benefits of GUI interface over DOS like steel, the program are compiled using cava packager http://www.cava.co.uk/ the Factor.exe is a freeware for factoring big numbers from http://www.shamus.ie/uploads/File/factor.exe the new gui for the program in: http://www.4shared.com/file/49815871/9090655a/factorize.html the source code in case the file is deleted below, my source code are not the optimum one especially in the perl side coding, but it is working, any suggestions are welcome. use Win32::GUI; use warnings; use strict; my $Win = new Win32::GUI::Window( -left => 3, -top => 5, -width => 640, -height => 480, -name => "Win", -text => "factorizing numbers" ); $Win->Show(); my $font = Win32::GUI::Font->new( -name => "Courier New", -size => 14, ); my $font2 = Win32::GUI::Font->new( -name => "Courier New", -size => 16, ); $Win->AddButton( -text => "Run", -name => "Button1", -left => 7, -top => 5, -width => 56, -height => 36, -foreground => 0, ); $Win->AddButton( -text => "CLS", -name => "Button2", -left => 581, -top => 399, -width => 47, -height => 25, -foreground => 0, ); $Win->AddLabel( -text => "Write the Number", -name => "Label_2", -left => 400, -top => 30, -width => 200, -height => 18, -foreground => 0, ); my $numberinput = $Win->AddTextfield( -text => "", -name => "Textfield_2", -left => 4, -top => 54, -width => 595, -height => 33, -align => "left", -font => $font, -background =>"#FFF8CD", ); my $output = $Win->AddTextfield( -text => "", -name => "Textfield_Output", # OutPut textfield -left => 1, -top => 91, -width => 634, -height => 297, -multiline => 1, -vscroll => 1, -align => "left", ); my $waitLable = $Win->AddLabel( -text => "", -name => "Label_3", -left => 95, -top => 8, -width => 213, -height => 39, -foreground => 0, -font => $font2, -foreground => 8388863, ); $Win->AddButton( -text => "CLS", -name => "Button3", -left => 603, -top => 56, -width => 26, -height => 29, -foreground => 0, ); Win32::GUI::Dialog(); exit(0); sub Win_Terminate { return -1; } sub Button1_Click { my $number = $numberinput->GetLine(1); $waitLable -> Text("Please Wait"); my $i = 0; my $r; my $ss; my @a;my @ss; my @info = `factor.exe $number`; foreach (@info) { $r = $_; if ($r =~ /this number is prime/){ $output->Append("this number is PRIME\n");last} {if (@a = $r =~ m/PRIME.*?\d+/g) { @ss = $a[0] =~ /\d+/g; $output->Append("$ss[0]\n"); } } } $output->Append("===============================\n"); $waitLable -> Text(""); } sub Button2_Click { $output->Text(""); } sub Button3_Click { $numberinput->Text(""); } |