#!/perl/bin -w ################################################################### # # Purpose: Declaration of Modules to use in this script ################################################################### use Tk; use strict; use TK::FileSelect; use Tk::LabEntry; use Cwd; use FileHandle; use DirHandle; use Win32::Process; my $W; # GUI window $W = MainWindow->new; $W->title("Select Job"); $W->iconname('select job'); my $file_selected; # Read the directory contents - Put in a path were you have files placed my @dirContents = readDir ("c:/public"); my $job_path = 'c:\\public\\'.$file_selected; print "$job_path\n"; my $TOP = $W->Toplevel; $TOP->title("data contents"); $TOP->geometry("+70+120"); $TOP->configure(-background => lc("aquamarine2")); my $tFrame = $TOP->Frame; my $bFrame = $TOP->Frame; $tFrame->configure(-background => lc("PaleTurquoise")); $bFrame->configure(-background => lc("PaleTurquoise")); # Create the label for editing the file my $lab = $tFrame->Label(-text => "Double click to edit file: ", -background => "PaleTurquoise", -anchor => 'e'); # Create a listbox with the contents of the directory. my $ent = $tFrame->Scrolled(qw/Listbox -setgrid 1 -height 16 -width 40 -scrollbars e -selectmode single/); for(@{dirContents}) { $ent->insert(0, "$_"); } $ent->bind('', sub { $file_selected = $ent->get('active'); # In case of Excel files ############### if ($file_selected =~ m/\.xls/) { my $excel; print "$job_path\n"; use Win32API::Registry qw( :ALL ); my ( $key, $type, $excel_path ); #Microsoft Office 95 RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office\\9.0\\excel\\InstallRoot", 0, KEY_READ, $key ); #"$software has registry key\n" : "$software seems to be missing ".regLastError()."\n"; if ($key == 0) #Microsoft Office 97 { RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Office\\8.0\\excel\\InstallRoot", 0, KEY_READ, $key ); } RegQueryValueEx($key, "Path", [], $type, $excel_path, [] ); Win32::Process::Create($excel, $excel_path.'\excel.exe',"excel $job_path",0,CREATE_NEW_CONSOLE,".")|| die ErrorReport(); } elsif ($file_selected =~ m/\.pdf/) { my $pdf; print "$job_path\n"; use Win32API::Registry qw( :ALL ); my ( $key, $type, $pdf_path ); RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Adobe\\Acrobat Reader\\5.0\\InstallPath", 0, KEY_READ, $key ); regLastError(); RegQueryValueEx( $key, "(Default)", [], $type, $pdf_path, [] ); print "$pdf_path\n\n\n\n"; Win32::Process::Create($pdf, $pdf_path.'\acrord32.exe',"acrord32 $job_path",0,CREATE_NEW_CONSOLE,".")|| die ErrorReport(); } else { my $Notepad; Win32::Process::Create($Notepad,'c:\\program files\\windows NT\\accessories\\wordpad.exe',"wordpad $job_path",0,CREATE_NEW_CONSOLE,".")|| die ErrorReport(); } }); # Quit the edit directory contents popup my $quitButton = $bFrame->Button(-text => "Quit", -width => 12, -background => "PaleTurquoise", -activebackground => "PaleTurquoise", -command => sub { $TOP->destroy; # strictly not necessary }); # Instead of pack, using grid to place more precisely. Tk::grid($tFrame, -row => 0, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($bFrame, -row => 1, -column => 0, -sticky => 's', -padx => 10, -pady => 10, ); Tk::grid($quitButton, -row => 0, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($lab, -row => 1, -column => 0, -sticky => 'w', -padx => 10, -pady => 10, ); Tk::grid($ent, -row => 1, -column => 1, -sticky => 'w', -padx => 10, -pady => 10, ); MainLoop; sub readDir { my ($DirName) = @_; opendir (INDIR,$DirName) or die "\nCannot open $DirName: $!\n"; my @DirContents = grep (!/^\.\.?$/ && -f "$DirName/$_" , readdir(INDIR)); close (INDIR); return @DirContents; }