Hi,

First of all, I apologize for the continuous nuisances with my questions About the MDI Windows, now I have new questions or doubts. 1 - I'm trying to add a Rebar and a StatusBar to the MDI Frame with a Backgound image. 2 - With the code added to this message, the Window don't show me the Rebar and the StatusBar. 3 - If I comment the following option "-popstyle => WS_CLIPCHILDREN," in "new Win32::GUI::MDIFrame" function, the window show me only the StatusBar but not the Rebar 4 - With the option "-popstyleis" disabled, some times when I move the child window over the StatusBar; the StatusBar is partially deleted. How I can add a ReBar and a StatusBar to MDI Window preserving the backgound image? and It's possible to protect the Rebar and the StatusBar in order to prevent to move the child Window over them? With this, the displacement would be limited to a rectangle defined by something like: my ( $l, $t, $r, $b ) = $window->GetClientRect() $t += $Rebar->Height; $b -=$StatusBar->Height;
Again, I'll appreciate your help.



Best regards, and sorry by the code size



#!perl -w
#
#  MDI sample
#

use strict;
use warnings;



#BEGIN { unshift(@INC, "./lib"); }

use Win32::GUI;
use Win32::GUI::DIBitmap;


# My child counter for unique name.
my $ChildCount = 0;
my $Window;



# Get fisical Screen Dim.
my ( $dw, $dh ) = GetDW();

# Load our bitmap
my $bm =
 newFromFile Win32::GUI::DIBitmap('backgound.bmp')
 or die "newFromFile";

# Store the width and height, as we'll use them a lot
my ( $bmw, $bmh ) = ( $bm->GetWidth(), $bm->GetHeight() );


#
#Create the imagelist that will be used for the toolbar
#
my $B1 = new Win32::GUI::Bitmap("one.bmp");
my $B2 = new Win32::GUI::Bitmap("two.bmp");
my $B3 = new Win32::GUI::Bitmap("three.bmp");
my $IL = new Win32::GUI::ImageList( 16, 16, 0, 3, 10 );
$IL->Add( $B1, 0 );
$IL->Add( $B2, 0 );
$IL->Add( $B3, 0 );




# create a class without a background brush: this prevents
# defFrameWindowProc erasing the window background, as we want to
# paint it ourselves to avoid flicker
my $class = Win32::GUI::Class->new(
                        -name   => 'noflicker',
                        -brush  => 1,
-widget => "MDIFrame", # use the MDIFrame windowproc
);

# Create Main menu.
my $Menu = Win32::GUI::MakeMenu(
   "&File"      => "File",
   "   > &New"  => { -name => "File_New", -onClick => \&NewChild },
   "   > -"     => 0,
   "   > E&xit" => {
                     -name    => "File_Exit",
                     -onClick => sub { -1; }
   },
   "&Window"    => "Window",
   "   > &Next" => {
                     -name    => "Next",
                     -onClick => sub { $Window->{Client}->Next; }
   },
   "   > &Previous" => {
                         -name    => "Prev",
                         -onClick => sub { $Window->{Client}->Previous; }
   },
   "   > -"        => 0,
   "   > &Cascade" => {
                        -name    => "Cascade",
-onClick => sub { $Window->{Client}->Cascade(); 0; }
   },
   "   > Tile &Horizontally" => {
                                -name    => "TileH",
-onClick => sub { $Window->{Client}->Tile(1); }
   },
   "   > Tile &Vertically" => {
                                -name    => "TileV",
-onClick => sub { $Window->{Client}->Tile(0); }
   },
   "&Help"       => "Help",
   "   > &About" => {
                      -name    => "About",
                      -onClick => sub { 1; }
   },
);

# First we create an MDIFrame window.
$Window = new Win32::GUI::MDIFrame(
   -title    => "Win32::GUI MDI Sample",
   -left     => 0,
   -top      => 0,
   -width    => $dw,
   -height   => $dh,
   -minsize  => [ 600, 450 ],
   -name     => "Window",
   -menu     => $Menu,
   -class    => $class,
   -popstyle =>
     WS_CLIPCHILDREN,    # So that the MDIClient's window is not clipped
   -onPaint     => \&paint,
   -onTerminate => sub { print "Terminate\n"; -1 },
   -onResize    => \&onResize,
 )
 or die "Window";
#
# Status Bar
#
my $status = $Window->AddStatusBar(
   -name => "status",
 )
 or die "new Statusbar. $!\n";

$status->Parts( 500, -1 );
$status->PartText( 0, "Example" );

# Store the StatusBar height
my $stbHeight = $status->ScaleHeight();

# We add an MDIClient window, This window manage Child Window.
$Window->AddMDIClient(
   -name       => "Client",
   -firstchild => 100,              # Define Child ID for menu item
   -windowmenu => $Menu->{Window}
     ->{-handle},    # Define Menu Handle where Add Window Child name
   -height => 1000,  #($Window->ScaleHeight() - $status->ScaleHeight()),

) or die "Client";

#
#create the child window which will contain the toolbar
#
my $band0 = new Win32::GUI::Window(
                                   -parent    => $Window,
                                   -name      => "ToolBar",
                                   -popstyle  => WS_CAPTION | WS_SIZEBOX,
                                   -pushstyle => WS_CHILD,
);

#create a child window for band 1 of the rebar control, this band will contain two buttons
my $band1 = new Win32::GUI::Window(
                                   -parent    => $Window,
                                   -name      => "Action",
                                   -popstyle  => WS_CAPTION | WS_SIZEBOX,
                                   -pushstyle => WS_CHILD,
);

#Add a button to band 1
$band1->AddButton(
                  -name    => "Button1",
                  -pos     => [ 0, 1 ],
                  -size    => [ 60, 20 ],
                  -text    => "Button 1",
                  -tip     => "Button 1",
                  -onClick => sub { print "Button 1 clicked" },
);

#Add a button to band 1
$band1->AddButton(
                  -name    => "Button2",
                  -pos     => [ 65, 1 ],
                  -size    => [ 60, 20 ],
                  -text    => "Button 2",
                  -tip     => "Button 2",
                  -onClick => sub { print "Button 2 clicked" },
);

#
#create a rebar control
#
my $rebar;
$rebar = $Window->AddRebar(
   -name        => "Rebar",
   -bandborders => 1,

   #-fixedorder  => 1,
   -onHeightChange => sub { print "Rebar_HeightChange" . $rebar->Height; },
);

#Insert band 1
$rebar->InsertBand(
                   -child     => $band0,
                   -width     => 100,
                   -minwidth  => 100,
                   -minheight => 24,
);

#Insert band 2
$rebar->InsertBand(
                   -child     => $band1,
                   -width     => 130,
                   -minwidth  => 130,
                   -minheight => 24,
);

#Add the toolbar to band 0
my $TB = $band0->AddToolbar(
   -name          => "Toolbar",
   -nodivider     => 1,
   -onButtonClick => sub {
       my ( $self, $button ) = @_;
       print " button $button clicked";
   },
);

#Set the image list, and add the styles
$TB->SetImageList($IL);
$TB->SetStyle(
TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | 1 | TBSTYLE_LIST | TBSTYLE_TOOLTIPS );
$TB->SetExtendedStyle(0x00000008);

#Add the buttons
$TB->AddButtons( 4, 0, 1, 4, 0, 0, 1, 2, 4, 0, 1, 0, 0, 0, TBSTYLE_SEP, 0, 2, 3,
                4, 0, 2, );

#add the tooltips
$TB->AddString("One");
$TB->AddString("Two");
$TB->AddString("Three");





# do some other stuff
sleep(1);

# show the main window and enter the dialog phase
# splash screen taken down after (default) 3 seconds
$Window->Center();

# Show main window and go to event loop
$Window->Show;
Win32::GUI::Dialog();

# We've got some closures on $Window in the
# functions below, which appear to be the cause of
# a 'Can't call Delete .. in global clean up' warning,
# udefining $Window here stops that.
undef $Window;
exit(0);





# Our window painting routine.  To avoid flicker we will
# paint the whole of the window, taking care not to draw any
# pixel more than once.
sub paint
{
   print "Painting...\n";
   my ( $window, $dc ) = @_;

# I will add StretchBlt to the next release so that we can stretch the
# image to fit the window, but it's not there right now.
#$dc->StretchBlt(0, 0, ($window->GetClientRect())[2..3], $memDC, 0, 0, $bmw, $bmh);

   # clip each of the MDIChild windows, to avoid us drawing over them
   # and so removing flicker
   # $clip_rgn is the rgion into which we can draw, initialise
   # it to the client window]

   my @ary_rgn = $window->GetClientRect();
   $ary_rgn[3] -= $stbHeight;

   my $clip_rgn = Win32::GUI::Region->CreateRectRgn(@ary_rgn);
   while ( my ( $name, $value ) = each %{ $window->{Client} } )
   {
       next unless $name =~ /^Child\d+/;
       my ( $l, $t, $r, $b ) = $value->GetWindowRect();

       # $child_rgn is the MDI child's region in our window's client
       # co-ordinates
       my $child_rgn =
Win32::GUI::Region->CreateRectRgn( $Window->ScreenToClient( $l, $t ), $Window->ScreenToClient( $r, $b - $stbHeight ) );

       # remove $child_rgn from the area we can draw
       $clip_rgn->CombineRgn( $clip_rgn, $child_rgn, 4 );
   }

   # selct the clip region into our DC.
   $dc->SelectClipRgn($clip_rgn) if $clip_rgn;

   #calculate the image position to center it in the window
   my ( $ww, $wh ) = ( $window->GetClientRect() )[ 2 .. 3 ];

   # stretch the image to fit the window
   $bm->StretchToDC( $dc, 0, 0, $ww, $wh - $stbHeight,
                     0, 0, $bmw, $bmh, 13369376 );


# We've drawn the background, so inform windows that there is nothing left
   # to draw.
   $dc->Validate();

   # we've processed the message, so return 0.
   return 0;
}

# This function create a new child window.
sub NewChild
{
   Win32::GUI::MessageBox( $Window, "NewChild", "Some Title",
                           &MB_OK | &MB_ICONWARNING | &MB_TASKMODAL );

   # Create a child window.
   my $Child = $Window->{Client}->AddMDIChild(
       -name         => "Child" . $ChildCount++,
       -onActivate   => sub { print "Activate\n"; },
       -onDeactivate => sub { print "Deactivate\n"; },
       -onTerminate  => sub {
           $Window->InvalidateRect(0);
           print "Terminate\n";
       },
       -onResize => \&ChildSize,
     )
     or die "Child";

   $Child->Hook( WM_MOVE, sub { $Window->InvalidateRect(0); return 1; } );

   # Add a text filed into child window.
   $Child->AddTextfield(
                         -name      => "Edit",
                         -multiline => 1,
                         -pos       => [ 0, 0 ],
                         -size      => [ 100, 100 ],
   );

   # Force a resize.
   ChildSize($Child);

   # Test Search Win
   Init();

   # Return Focus
   $Child->SetFocus();
}

# This function manage child window resize.
sub ChildSize
{
   my $self = shift;

   # Get handle to avoid undefine errors
   my $handle = $self->{-handle} || 0;

my ( $width, $height ) = ( $self->GetClientRect() )[ 2 .. 3 ] if $handle;

   # TextField take all client aera
   $self->{Edit}->Resize( $width, $height ) if exists $self->{Edit};
}

sub GetDW
{
   my $desk = Win32::GUI::GetDesktopWindow();
   my $dw   = Win32::GUI::Width($desk);
   my $dh   = Win32::GUI::Height($desk);

   return ( $dw, $dh );
}

sub Init
{
   #This is a class function, and is used to initilise all objects
   my $searchwindow = new Win32::GUI::DialogBox(
-name => "EmployeeSelector", -title => "Search for Employee",
                                               -size  => [ 300, 270 ],
   );
   $searchwindow->AddListView(
                               -name          => "ListView",
                               -pos           => [ 8, 8 ],
                               -size          => [ 280, 189 ],
                               -fullrowselect => 1,
   );
   $searchwindow->AddButton(
       -name => "OK",
       -text => "OK",
       -pos  => [ 164, 208 ],
       -size => [ 60, 21 ],

       #When we click ok, we populate the calling controls EmpID
       -onClick => sub {
           my $item = $searchwindow->ListView->SelectedItems();
           my %hItem = $searchwindow->ListView->ItemInfo( $item, 0 );
           print $hItem{-text} . "\n";
           return -1;
       },
   );
   $searchwindow->AddButton(
                             -name    => "Cancel",
                             -text    => "Cancel",
                             -pos     => [ 228, 208 ],
                             -size    => [ 60, 21 ],
                             -onClick => sub { return -1 },
   );

   #populate the list view
$searchwindow->ListView->InsertColumn( -width => 55, -text => "Emp ID" );
   $searchwindow->ListView->InsertColumn( -width => 205,
                                          -text  => "Employee Name" );
   $searchwindow->ListView->InsertItem( -text => [ 1234, "Bob Smith" ] );
   $searchwindow->ListView->InsertItem( -text => [ 4321, "Peter Jones" ] );
   $searchwindow->ListView->InsertItem( -text => [ 7890, "John Brown" ] );

   $searchwindow->Center;
   $searchwindow->DoModal(1);
}

sub onResize
{
   $status->Resize( $Window->ScaleWidth, $Window->ScaleHeight );

   #$Progress->Resize($status->Width/2,$status->Height-3);
   #$Progress->Move($status->Width/2,2);
}



Reply via email to