Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Win32 GUI scrolling controls within the main window

by SteveR (Novice)
on Jun 07, 2017 at 14:07 UTC ( [id://1192278]=perlquestion: print w/replies, xml ) Need Help??

SteveR has asked for the wisdom of the Perl Monks concerning the following question:

I can't find any explanation of what I am supposed to do to get scrolling working and what any built in Win32 GUI scrolling capability will do for me and if its there how do I activate it.

I did find rob may's posting http://rob.themayfamily.me.uk/perl/win32-gui/scrollbars but I can't quite work out how to apply it to my problem

Here is a simple snippet of code that just draws a couple of labels with the second label going over the status bar and getting cut off at the bottom. There is a sub for scroll events but I don't know what to put in it

I'm trying to get the contents of the main window to scroll up and down in response to the scroll arrows on the right hand side

Am I supposed to just Move() the controls up and down within the main window ?

How do I get the bottom label to play nice with the status bar at the bottom and not go over it ?

I am a casual perl scripter who has written a fair number of Perl console scripts over the years and have been experimenting with win32 gui for a few weeks. I have managed a simple non resizable gui app with buttons and list boxes but for my next project I need to get some controls to scroll inside a window or Groupbox. Its the beginnings of a picture renaming app. I am using ActiveState Perl

use Win32::GUI qw( WS_CLIPCHILDREN ); use warnings; use strict; my $main = Win32::GUI::Window->new( -name => "Main", -title => "Test", -pos => [100, 100], -size => [200, 200], -pushstyle => WS_CLIPCHILDREN, -vscroll => 1, ) or die "new Window"; my $preview = $main->AddLabel( -name => 'label_bitmap', -top => 20, -left => 20, -height => 80, -width => 80, -background => [255,255,255], ); my $preview1 = $main->AddLabel( -name => 'label_bitmap1', -top => 120, -left => 20, -height => 80, -width => 80, -background => [255,255,255], ); my $sb = $main->AddStatusBar(); $main->Show(); Win32::GUI::Dialog(); sub Main_Scroll { print "Scroll control used\n"; } sub Main_Resize { $sb->Move(0, $main->ScaleHeight - $sb->Height); $sb->Resize($main->ScaleWidth, $sb->Height); }

Replies are listed 'Best First'.
Re: Win32 GUI scrolling controls within the main window
by BrowserUk (Patriarch) on Jun 07, 2017 at 17:33 UTC

      I have read that link thanks, its really good and about the only bit of code or explanation that I could find over the last few days

      However I do have a few questions about it as the vast majority is to do with moving the scrollbars around and displaying them. The scroll bars don't actually scroll the image until part 7. The bit that must be doing the work is

      sub process_scroll { ... if ( $bar == SB_VERT ) { $self->BM->Top( -$new_pos ); } else { # SB_HORZ $self->BM->Left( -$new_pos ); }
      I looked up Top on the Win32::GUI::Reference::Options and its says

      -top => NUMBER Specifies the top position (Y coordinate) for the window, in pixels. For Windows and DialogBoxes is absolute (screen position), while for controls is relative to the client area of their parent window.

      So what I don't understand is how moving the top or left hand side of the Label control (that has the bitmap attached and is not actually anchored to a specific part of the main window or is it) causes the image to scroll ?????

      If it isn't that bit of code then what is doing the work ?

        -top => NUMBER Specifies the top position (Y coordinate) for the window, in pixels. For Windows and DialogBoxes is absolute (screen position), while for controls is relative to the client area of their parent window. So what I don't understand is how moving the top or left hand side of the Label control (that has the bitmap attached and is not actually anchored to a specific part of the main window or is it) causes the image to scroll ?????

        As far as can tell, in this line:$self->BM->Top( -$new_pos ); is telling the label (a client window, thus relative positioning) containing the bitmap, which part of the bitmap to display.

        If you move the vertical scrollbar down 3 units, it needs to reposition the top of the bitmap -3 units above the top of the label client area, thus hiding those top 3 units worth of bitmap.

        Does that make things any clearer?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
        In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit
Re: Win32 GUI scrolling controls within the main window
by zentara (Archbishop) on Jun 07, 2017 at 15:19 UTC
    My advice, is find a simple example thru a google search where the scrollbars work, then do what they do in the code. There has to be a simple scrollbar example somewhere for Win32GUI.

    I'm not really a human, but I play one on earth. ..... an animated JAPH

      Thanks for the reply.

      Been trying to find a simple example for most of this week without any luck :-( Keep getting the same few results which work because its a single control with its own scroll bar or takes up all of the window

      I get the feeling that the answer to this one is either fiendishly difficult or trivial

      What I don't get is how the process is supposed to work. Am I responsible for moving everything around, resizing and clipping it or is there some sort of viewport where I can "see" part of a larger virtual window.

      If I stick too much on the window where does the excess go ? :-)

        Hi, I have to chuckle to myself, because at first I thought you were trying to get away with a free homework answer; but after going thru BrowserUk's 7 steps below, this is indeed a non-obvious coding task. :-)

        I'm not really a human, but I play one on earth. ..... an animated JAPH
Re: Win32 GUI scrolling controls within the main window
by Anonymous Monk on Jun 09, 2017 at 01:03 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1192278]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found