Hi there.

I've just started using the Win32::GUI library, so pardon me if this
turns out to be a newbie question.

I'm having problems with the UpDown control.
Here's what I'd like to end up with:

a dialog with a status bar, a text field, an UpDown control regulating the
text field, and a Close button. The script will do more stuff (and could even
run without a GUI). It should update the status bar indicating what it is doing,
and also add lines to the textfield as it goes. The Close button should be
disabled as the script does all it needs to do. When the script has done all it
needs to do, the Close button is enabled so that the user can close the dialog.

Here's what I have so far:
almost everything I need. In particular, I have the script creating, showing, and updating all the GUI as it needs, and passing control to the GUI when it is done. This is the
listing with all of this working *BUT no UpDown control*: I call this test.pl

#!/usr/bin/perl

use Win32;
use Win32::GUI;
use strict;
use warnings;

my $GUI = 1;
my $mainWindow;
my $mainStatusBar;
my $txtLog;

MAIN:
   LOG("test started");

   InitGUI()
      if $GUI;
   $mainStatusBar->Text("test initialized.")
      if $GUI;

   LOG("Will do 100 cycles.");
   DoSomething(100);

   $mainWindow->btnClose->Enable();
   my $exitCode = Win32::GUI::Dialog();
   LOG("Dialog cycle returned control to MAIN with exit code '$exitCode'.");

   exit(0);

sub InitGUI
   {
   LOG("InitGUI started.");
#Main Window, with status bar, Log textfield, and Close button:
   $mainWindow = new Win32::GUI::DialogBox(
                                       -text => "Test",
                                       -name => "MainWindow",
                                       -pos  => [ 200, 400 ],
                                       -size => [ 600, 500 ]
                                       )
   or ERROR("Could not initialize main window.");
   LOG("Main Window initialized.");
   $mainStatusBar = new Win32::GUI::StatusBar(
                                             $mainWindow,
                                             -name    => "mainStatusBar",
                                             )
   or ERROR("Could not initialize main window (status bar).");
   $mainStatusBar->Text("Initializing");
   LOG("Status Bar added.");
   $txtLog = new Win32::GUI::Textfield(
                                       $mainWindow,
                                       -name       => "txtLog",
                                       -pos        => [10, 10],
                                       -size       => [550, 350],
                                       -disabled   => 0,
                                       -visible    => 1,
                                       -multiline  => 1,
                                       -readonly   => 1,
                                       -text       => "Log Started"
                                       )
   or ERROR("Could not initialize main window (log textfield).");
   LOG("Log Textfield added.");
   $mainWindow->AddButton(
                         -name      => "btnClose",
                         -pos       => [10, 400],
                         -size      => [80, 20],
                         -text      => "Close",
                         -disabled  => 1,
                         -cancel    => 1,
                         -default   => 1
                           )
   or ERROR("Could not initialize main window (Close button).");
   LOG("Close button added.");

   LOG("All GUI elements initialized.");

   $mainWindow->Show();
   LOG("Showing main window.");
   my $exitCode = Win32::GUI::DoEvents();
LOG("DoEvents cycle returned control to InitGUI with exit code '$exitCode'.");
   }

sub TerminateGUI
   {
   print STDERR "Terminating GUI.\n";
   return -1;
   }

sub btnClose_Click()
   {
   print STDERR "Close button clicked.\n";
   return TerminateGUI();
   }
sub MainWindow_Terminate()
   {
   print STDERR "Main Window Terminated.\n";
   return TerminateGUI();
   }

sub DoSomething
   {
   my $numCycles = shift;
   LOG("DoSomething($numCycles).");
   for(my $i = 0; $i<$numCycles; $i++)
      {
      LOG("Doing something $i");
      }
   LOG("Done $numCycles cycles.");
   }

sub LOG
   {
   my ($package, $filename, $line) = caller;

   if($GUI and $txtLog)
      {
      my $msg = $_[0];
      $msg =~ s/[^\r]\n/\r\n/ms;
      $msg.="\r\n"
         unless $msg =~ /\r\n$/ms;

      $txtLog->Text($txtLog->Text().$msg);
      Win32::GUI::Update($mainWindow);
      }

   print "Test info:", scalar localtime(), ":", @_, "\n";
   }

sub WARN
   {
   my ($package, $filename, $line) = caller;
   if($GUI and $txtLog)
      {
      my $msg = $_[0];
      $msg =~ s/[^\r]\n/\r\n/ms;
      $msg.="\r\n"
         unless $msg =~ /\r\n$/ms;

      $txtLog->Text($txtLog->Text().$msg);
      Win32::GUI::Update($mainWindow);
      }
print STDERR "Test warning:", scalar localtime(), ":line $line in package $package:", @_, "\n";
   }

sub ERROR
   {
   my ($package, $filename, $line) = caller;
   if($GUI and $txtLog)
      {
      my $msg = $_[0];
      $msg =~ s/[^\r]\n/\r\n/ms;
      $msg.="\r\n"
         unless $msg =~ /\r\n$/ms;

      $txtLog->Text($txtLog->Text().$msg);
      Win32::GUI::Update($mainWindow);
      }
   $mainStatusBar->Text("ERROR !")
      if $GUI and $mainStatusBar;
print STDERR "Test error:", scalar localtime(), ":line $line in package $package:", @_, "\n";
   print STDERR "Test terminated with error.\n";
   exit(1);
   }
#===

I then created test2.pl, which is Identical, but I've added the following lines in InitGUI,
   $upDown = new Win32::GUI::UpDown(
                                    $mainWindow,
                                    -name    => "upDown"
                                    )
   or ERROR("Could not initialize main window (Up/Down control.");
   LOG("Up/Down control added.");
   $upDown->Buddy($txtLog);
Immediately preceeding the line
   LOG("All GUI elements initialized.");

What is happening with this one is that:
the close button text is changed to '0' (zero);
when the GUi gets control from the script, if I press the up or down arrows, the text in the textfield
is changed to a number (from 0 to 100, which seems to be roughly the range).

Any suggestions in regard?

Thanks in advance for the time,
F.O.R.


Reply via email to