Scrollbars - Part 3 - Adding the scrollbars

In part 1 and part 2 of this series we set up the framework, and now we can get down to the real business of adding scrollbars, so that we can see the parts of our image that don't fit into the window frame.

In this article we add the scrollbars to the main window:

7 my $mw = Win32::GUI::Window->new(

8 -title => "Scrollbar 03: Adding Scrollbars",

9 -left => CW_USEDEFAULT,

10 -size => [ 400, 300 ],

11 -addstyle => WS_CLIPCHILDREN,

12 -vscroll => 1,

13 -hscroll => 1,

14 );

Using the '-vscroll' and '-hscroll' options we request that the window has both vertical and horizontal scroll bars. But that's all these options do - they ask for the scrollbars to be drawn. The scrollbars are drawn, but they don't do anything - we will need to add code for that. Next time we'll look at the 'Scroll' event handler, and investigate the messages that we get passed that we will need to process.

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 03: Adding Scrollbars",

-left => CW_USEDEFAULT,

-size => [ 400, 300 ],

-addstyle => WS_CLIPCHILDREN,

-vscroll => 1,

-hscroll => 1,

);

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 2. Move on to Part 4.