Hi,
Sorry by my last mail. I sent you a wrong script. This it's my modified
MDI script with your code. The problem is that the new child window is
not visualized but the activate/deactivate events works when the window
is created.
Is there are any wrong in my code?
I'll appreciate your comments about this.
Best regards.
#! perl
#
# MDI sample
#
use Win32::GUI;
use Win32::GUI::BitmapInline();
use strict;
# My child counter for unique name.
my $ChildCount = 0;
my $Window;
# Load our bitmap
#my $bm = Win32::GUI::Bitmap->new("sail.bmp") or die "Creating Bitmap";
my $bm = get_bitmap();
# Store the width and height, as we'll use them a lot
my($bmw, $bmh) = ($bm->Info())[0..1];
# create a class without a background brush: this prevents
# defWindowProc erasing the window background, as we want to
# paint it ourselves to avoid flicker
my $class = Win32::GUI::Class->new(
-name => 'noflicker',
-brush => 0,
);
# 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 => 100,
-top => 100,
-width => 280,
-height => 280,
-name => "Window",
-menu => $Menu,
-class => $class,
-addstyle => WS_CLIPCHILDREN,
-onPaint => \&paint,
-onTerminate => sub {print "Terminate\n"; -1},
) or die "Window";
# 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
) or die "Client";
# Create a memory DC, compatible with our window's
# DC, containing our bitmap. Do this once, here, to speed
# up the painting routine. Use a local block, so that $dc
# goes out of scope, and $dc gets released (could call
# $dc->ReleaseDC() instead).
my $memDC;
{
my $dc = $Window->GetDC();
$memDC = $dc->CreateCompatibleDC();
$memDC->SelectObject($bm);
}
# We need a brush to paint the window background
# with, select a grey one. We don't need to worry
# about freeing stock objects when we're done with them
my $bkBrush = Win32::GUI::GetStockObject(1);
# Show main window and go to event loop
$Window->Show;
Win32::GUI::Dialog();
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
{
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);
#calculate the image position to center it in the window
my ($ww, $wh) = ($window->GetClientRect())[2..3];
my $l = ($ww - $bmw)/2;
my $t = ($wh - $bmh)/2;
my $r = $l + $bmw;
my $b = $t + $bmh;
# copy the image from the memory DC to the window's DC
$dc->BitBlt($l, $t, $bmw, $bmh, $memDC, 0, 0);
# fill the spaces around the image with our background brush.
# We should probably not draw when it is not necessary (i.e. when
# the image meets the side(s), but we can get away with not checking,
# as the DC is always clipped to the window's client rect.
$dc->FillRect(0, 0, $ww, $t, $bkBrush);
$dc->FillRect(0, $b, $ww, $wh, $bkBrush);
$dc->FillRect(0, $t, $l, $b, $bkBrush);
$dc->FillRect($r, $t, $ww, $b, $bkBrush);
# 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 {
# Create a child window.
my $Child = $Window->{Client}->AddMDIChild (
-name => "Child".$ChildCount++,
-onActivate => sub { print "Activate\n"; },
-onDeactivate => sub { print "Deactivate\n"; },
-onTerminate => sub { print "Terminate\n";},
-onResize => \&ChildSize,
) or die "Child";
# Add a text filed into child window.
$Child->AddTextfield (
-name => "Edit",
-multiline => 1,
-pos => [0,0],
-size => [100,100],
);
# Force a resize.
ChildSize($Child);
}
# This function manage child window resize.
sub ChildSize {
my $self = shift;
my ($width, $height) = ($self->GetClientRect())[2..3];
# TextField take all client aera
$self->{Edit}->Resize($width, $height) if exists $self->{Edit};
}
sub get_bitmap
{
return Win32::GUI::BitmapInline->new( q(
.....
);
}
Daniel Fernandez escribió:
Hi,
Thank you very much for your answer. I have been studying your code
and I arrived to the conclusion that is very difficult to track
all the child windows. Is easy with one object like a button, but
too difficult with many child windows (I'm not a windows expert), like
in the following example.
Thanks and regards
Robert May escribió:
Daniel Fernandez wrote:
Hello, perl-win32-gui-users,
Anybody knows if it's possible to display a background bitmap
image in a MDIFrame? If it's possible, I will appreciate a short
example .
Here's one way of doing it with a regular window. You should be able
to adjust this to work with an MDI frame. (Sorry about the big image)
Regards,
Rob.
#!perl -w
use strict;
use warnings;
use Win32::GUI;
use Win32::GUI::BitmapInline();
# Load our bitmap
#my $bm = Win32::GUI::Bitmap->new("sail.bmp") or die "Creating Bitmap";
my $bm = get_bitmap();
# Store the width and height, as we'll use them a lot
my($bmw, $bmh) = ($bm->Info())[0..1];
# create a class without a background brush: this prevents
# defWindowProc erasing the window background, as we want to
# paint it ourselves to avoid flicker
my $class = Win32::GUI::Class->new(
-name => 'noflicker',
-brush => 0,
);
# create a window, using our class. Add style WS_CLIPCHILDEN
# so that any child windows are automatically masked out of
# our window's DC, and then we don't need to worry about drawing
# over them
my $mw = Win32::GUI::Window->new(
-name => "ImgWindow",
-title => "Background Image",
-pos => [100,100],
-size => [550,450],
-class => $class,
-addstyle => WS_CLIPCHILDREN,
-onPaint => \&paint,
-onTerminate => sub {-1},
);
$mw->AddButton(
-name => "Button",
-pos => [100,100],
-text => "Example Child Window",
);
# Create a memory DC, compatible with our window's
# DC, containing our bitmap. Do this once, here, to speed
# up the painting routine. Use a local block, so that $dc
# goes out of scope, and $dc gets released (could call
# $dc->ReleaseDC() instead).
my $memDC;
{
my $dc = $mw->GetDC();
$memDC = $dc->CreateCompatibleDC();
$memDC->SelectObject($bm);
}
# We need a brush to paint the window background
# with, select a grey one. We don't need to worry
# about freeing stock objects when we're done with them
my $bkBrush = Win32::GUI::GetStockObject(1);
# Show the window and enter the dialog phase.
$mw->Show();
Win32::GUI::Dialog();
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
{
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);
#calculate the image position to center it in the window
my ($ww, $wh) = ($window->GetClientRect())[2..3];
my $l = ($ww - $bmw)/2;
my $t = ($wh - $bmh)/2;
my $r = $l + $bmw;
my $b = $t + $bmh;
# copy the image from the memory DC to the window's DC
$dc->BitBlt($l, $t, $bmw, $bmh, $memDC, 0, 0);
# fill the spaces around the image with our background brush.
# We should probably not draw when it is not necessary (i.e. when
# the image meets the side(s), but we can get away with not
checking,
# as the DC is always clipped to the window's client rect.
$dc->FillRect(0, 0, $ww, $t, $bkBrush);
$dc->FillRect(0, $b, $ww, $wh, $bkBrush);
$dc->FillRect(0, $t, $l, $b, $bkBrush);
$dc->FillRect($r, $t, $ww, $b, $bkBrush);
# 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;
}
sub get_bitmap
{
...
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing
& QA
Security * Process Improvement & Measurement *
http://www.sqe.com/bsce5sf
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing
& QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users