in reply to Win32 GUI scrolling controls within the main window

See the worked example at http://rob.themayfamily.me.uk/perl/win32-gui/scrollbars/sb1 and follow all seven parts.


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
  • Comment on Re: Win32 GUI scrolling controls within the main window

Replies are listed 'Best First'.
Re^2: Win32 GUI scrolling controls within the main window
by SteveR (Novice) on Jun 07, 2017 at 19:08 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

        I have managed to create a solution which lets Win32::GUI::Grid do the work for me

        That gets me an area of the screen that holds my Labels (in practice these are a 4 wide x X deep grid of pictures for my app) The labels are contained by the grid and no longer go over the status bar and the Grid control makes the scroll bars around itself appear and disappear as needed.

        In its simplest form here is some code.

        I would recommend using $Grid->AutoSize() just before $main->Show(); for a real grid to do the sizing but for this eaxmple I wanted 80 x 80 cells to make the scrollbar appear

        If you resize the window then the scrollbr should come and go

        use Win32::GUI; use Win32::GUI::Grid; use warnings; use strict; my $main = Win32::GUI::Window->new( -name => "Main", -title => "Test", -pos => [100, 100], -size => [200, 200], ) or die "new Window"; my $Grid = $main->AddGrid ( -name => "Grid", -pos => [20, 20], ) or die "new Grid"; $Grid->SetColumns(1); $Grid->SetRows(2); $Grid->SetRowHeight(0, 80); $Grid->SetRowHeight(1, 80); $Grid->SetColumnWidth(0, 80); $Grid->SetCellText(0, 0, 'Cell 1'); $Grid->SetCellText(1, 0, 'Cell 2'); my $sb = $main->AddStatusBar(); $main->Show(); Win32::GUI::Dialog(); sub Window_Terminate { return -1; } sub Main_Resize { $sb->Move(0, $main->ScaleHeight - $sb->Height); $sb->Resize($main->ScaleWidth, $sb->Height); my ($width, $height) = ($main->GetClientRect)[2..3]; $Grid->Resize (110, $height - $sb->Height - 20); }

        That helps thanks

        So that would imply that moving the contents around is 100% the scripters problem

        Rob's solution works nicely for bitmaps within a label but not so well for moving controls within the main window if you have a status bar :-(

        I will do some experiments to find a way to contain the labels to stop them from going over the top of the status bar and to get a pair of scroll buttons