Hello,

I have one question more.
Later on a code is given (I have Win32::GUI ver 1.05).
Sorry! - it is not as simple as it should be!
The point is that in WindowsXP it works fine but in Widows 98 SP2 it does not.
Windows' error screen points to USER32.DLL error.
Maybe someone could help me and show how to change the code to be working in 98?

Waldemar

####################################################
#! perl -w

use strict;
use Win32::GUI qw();
use Win32::GUI::Grid;

my $file = $ARGV[0];

unless ( -e $file ) {
   print "no file [$file] !\n";
   exit(1);
}


my $last  = -1;

my @Window;
my @start = (0);
my @rows  = (5);
my $which = 0;
my $help;

makewindow();

Win32::GUI::Dialog();
exit(1);

sub Window_Terminate { return -1 }

###############################################################

sub makewindow {
   return 1 if $last > 3;
   $last++;

   $start[$last] = 0;
   $rows[$last]       = 5+$last;

   $Window[$last]->{SCREEN} = new Win32::GUI::Window (
       -title    => "Item: $last",
       -pos     => [10+$last*202, 20],
       -size    => [200, 400],
       -name     => "Window_$last",
       -onKeyDown   => \&keydown,
   );

   $Window[$last]->{GRID} = new Win32::GUI::Grid (
       -parent  => $Window[$last]->{SCREEN},
       -name    => "Grid_$last",
       -pos     => [0, 0],
       -size    => [190,400],
       -onKeyDown   => \&keydown,
   );

   if ( $last == 0 ) {
       $Window[$last]->{HELP} = $Window[$last]->{SCREEN}->AddLabel(
           -parent  => $Window[$last]->{SCREEN},
           -pos=>[4,200],
           -size=>[150,150],
           -text=>"HELP:\nF4=add\nF7=switch\nEnter=close (the last only)",
           -multiline=>1,
       )
   }

   $Window[$last]->{SCREEN}->Show(1);

   $Window[$last]->{GRID}->SetEditable(0);
   $Window[$last]->{GRID}->SetRows($rows[$last]);
   $Window[$last]->{GRID}->SetColumns(1);
   $Window[$last]->{GRID}->SetFixedRows(0);
   $Window[$last]->{GRID}->SetFixedColumns(0);
   $Window[$last]->{GRID}->SetColumnWidth ( 0, 200 );
   $Window[$last]->{GRID}->Refresh();

   read_file($last);

print "item $last created\n";

   $which = $last;
}

sub read_file {
   my $which = shift;
   if ( open ( FH, "<$file" )) {
       for ( my $i = 0; $i < $start[$which]+$rows[$which] ; $i++ ) {
           my $file_row = <FH>;
           $file_row =~ s/\t/____/g;
           $file_row =~ s/\s//g;
$Window[$which]->{GRID}->SetCellText( $i-$start[$which], 0, $file_row ) if $i>=$start[$which];
       }
       close FH;
   }
}

sub keydown {
   my ( $self, undef, $key ) = @_;

   my $hash_EVENT    = Win32::GUI::GetKeyboardState;
   my $_EVENT        = what_event( $hash_EVENT );

   if ( $_EVENT eq 'F4' ) {

               makewindow();

   } elsif ( $_EVENT eq 'F7' ) {

               if ( $which == $last ) { $which = 0 } else { $which++ }
               $Window[$which]->{SCREEN}->SetFocus();

   } elsif ( $_EVENT eq 'Enter' ) {

       if (( $which == $last )&&( $last>0)) {

               print "item $last deleted\n";
$Window[$which]->{SCREEN}->DESTROY if $Window[$which]->{SCREEN};
               $last--;
               $which--;

       } elsif ( $last == 0 ) {

               print "item $last deleted\n";
               return -1;
       }

   } elsif ( $_EVENT eq 'Down' ) {

               $start[$which] += 1;

   } elsif ( $_EVENT eq 'Up' ) {

               $start[$which] -= 1;
               $start[$which] = 0 if $start[$which] < 0;

   } elsif ( $_EVENT eq 'PgDn' ) {

               $start[$which] += $rows[$which];

   } elsif ( $_EVENT eq 'PgUp' ) {

               $start[$which] -= $rows[$which];
               $start[$which] = 0 if $start[$which] < 0;
   }

   read_file($which);
   $Window[$which]->{GRID}->Refresh();

   return 1;
}

#------------------------------------

sub what_event {
   my $_EVENT = shift;
   my $result = '';
   my $SHIFT  = '';
   my $CTRL   = '';
   my $ALT    = '';

   if (( $_EVENT->[160] )||( $_EVENT->[161] )) { $SHIFT = 'Shift' }
   if (( $_EVENT->[162] )||( $_EVENT->[163] )) { $CTRL  = 'Ctrl'  }
   if (( $_EVENT->[164] )||( $_EVENT->[165] )) { $ALT   = 'Alt'   }

   if (( $_EVENT->[16] )) { $SHIFT = 'Shift' }
   if (( $_EVENT->[17] )) { $CTRL  = 'Ctrl'  }
   if (( $_EVENT->[18] )) { $ALT   = 'Alt'   }

#########################################
# Windows 98 tricks:
#---------------------------------------
   my $counter = 0;
   for (my $ii=0; $ii<256; $ii++) {
       $counter++ if $_EVENT->[$ii]
   }
   if ( $counter > 1 ) { $_EVENT->[115] = 0 }
#########################################

   for ( my $i = 0; $i < 256; $i++ ) {
       if ( $_EVENT->[$i] ) {
           if ( $i == 0 ) { $result .= 'Null' }
           elsif ( $i ==  8 ) { $result = 'Backspace' }
           elsif ( $i ==  9 ) { $result = $CTRL.$SHIFT.'Tab'    }
           elsif ( $i == 13 ) { $result = $CTRL.$SHIFT.'Enter'  }
           elsif ( $i == 27 ) { $result = $CTRL.$SHIFT.'Escape' }
           elsif ( $i == 33 ) { $result = $CTRL.$SHIFT.'PgUp'   }
           elsif ( $i == 34 ) { $result = $CTRL.$SHIFT.'PgDn'   }
           elsif ( $i == 36 ) { $result = $CTRL.$SHIFT.'Home'   }
           elsif ( $i == 35 ) { $result = $CTRL.$SHIFT.'End'    }
           elsif ( $i == 38 ) { $result = $CTRL.$SHIFT.'Up'     }
           elsif ( $i == 37 ) { $result = $CTRL.$SHIFT.'Left'   }
           elsif ( $i == 39 ) { $result = $CTRL.$SHIFT.'Right'  }
           elsif ( $i == 40 ) { $result = $CTRL.$SHIFT.'Down'   }
           elsif ( $i == 45 ) { $result = $CTRL.$SHIFT.'Insert' }
           elsif ( $i == 46 ) { $result = $CTRL.$SHIFT.'Delete' }
elsif (( 47 < $i )&&( $i < 58 )) { $result = $CTRL.$SHIFT.chr( $i ) }
           elsif (( 64 < $i )&&( $i < 91 )) {
my $shift = 0; $shift = 32 if (( $SHIFT eq 'Shift' )||( $CTRL eq 'Ctrl' ));
               $result = $CTRL.$ALT.chr( $i + 32 - $shift ) }
           elsif (( 111 < $i )&&( $i < 124 )) {
               $result = $ALT.$CTRL.$SHIFT.'F'.($i-111); }
           else {
               if (( $i != 160 )&&( $i != 161 )&&( $i != 16 )&&
                   ( $i != 162 )&&( $i != 163 )&&( $i != 17 )&&
                   ( $i != 164 )&&( $i != 165 )&&( $i != 18 )) {}
           }
       }
   }

   return $result;
}


Reply via email to