Perl‎ > ‎Win32::GUI‎ > ‎Scrollbars‎ > ‎

Scrollbars - Part 2 - Adding a large control

Take the scratch program from part 1, and we'll add a Label displaying a bitmap that is too large to fit in the window.

5 use Win32::GUI 1.05 qw( CW_USEDEFAULT WS_CLIPCHILDREN );
6
7 my $mw = Win32::GUI::Window->new(
8 -title => "Scrollbar 02: Scratch Program with picture",
9 -left => CW_USEDEFAULT,
10 -size => [ 400, 300 ],
11 -addstyle => WS_CLIPCHILDREN,
12 );

We add the style WS_CLIPCHILDREN to the window to prevent flickering caused by the erase of the window background followed by the re-draw of the bitmap when the window is re-sized. This is one of a number of flicker-reducing techniques that might make for a good series of articles in the future.

13
14 my $bm = Win32::GUI::Bitmap->new("kids.bmp");
15
16 $mw->AddLabel( -bitmap => $bm );

Adding a bitmap is as simple as creating a Win32::GUI::Bitmap object, passing the bitmap's filename to the constructor, and then passing the object to the AddLabel() method. A Label automatically sizes to the size of its bitmap if no other sizing options are supplied.

Again, here's the full code for this article:

#!perl -w
use strict;
use warnings;

use Win32::GUI 1.05 qw( CW_USEDEFAULT WS_CLIPCHILDREN );

my $mw = Win32::GUI::Window->new(
-title => "Scrollbar 02: Scratch Program with picture",
-left => CW_USEDEFAULT,
-size => [ 400, 300 ],
-addstyle => WS_CLIPCHILDREN,
);

my $bm = Win32::GUI::Bitmap->new("kids.bmp");

$mw->AddLabel( -bitmap => $bm );

$mw->Show();
Win32::GUI::Dialog();
$mw->Hide();
exit(0);

Source code can be downloaded from the series index page. Back to Part 1. Move on to Part 3.

Comments