Thanks to all for your help. During this weekend I made several tests, investigate a little and finally I be able to expand the image inside a MDI Frame without using calls to the APIS (gdi32.dll). I use the functions
# Load our bitmap
my $bm = newFromFile Win32::GUI::DIBitmap ('backgound.bmp') or die "newFromFile"; ... #Store the width and height, ace we'll uses them to lot my($bmw, $bmh) = ($bm->GetWidth (), $bm->GetHeight ());
 ...

#stretch the image to fit the window $bm->StretchToDC ($dc, 0, 0, $ww, $wh, 0, 0, $bmw, $bmh, 13369376); If somebody are interested one, here I send them the code that I uses in my tests.

Best Regards



#!perl -w
#
#  MDI sample
#

use strict;
use warnings;




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



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



# Obtine las dimensiones fisicas de la pantalla
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 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 => 0,
  -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},   ) 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";




# 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 $clip_rgn = Win32::GUI::Region->CreateRectRgn($window->GetClientRect());
  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));
   # 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, 0, 0, $bmw, $bmh, 13369376);
   #$bm->StretchToDC ($dc, 0, 0, $ww, $wh, 0, 0, $bmw, $bmh, SRCCOPY);

# 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 {
#MessageBox("NewChild", 'Perl Alert', &MB_OK|&MB_ICONWARNING|&MB_TASKMODAL); 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 modal
  Init();
}

# This function manage child window resize.
sub ChildSize {
   my $self = shift;
# Determina si la ventana esta definida y tiene un controlador
   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);
}



Jeremy White escribió:

I'm trying to implement the StretchBlt function using a call to gdi32.dll in order to fill the window with the image.


I've just added a feature request for this function to be supported natively within Win32-GUI.

As a side note, many functions are straightforward to add (including this one), so if you find a function missing, create a tracker for it:)

Cheers,

jez.




Reply via email to