"is it possible to use a scroll bar within a window, and not on one of it's 
edges?"

Yes, it is. Although I did not implement this yet. What you get when you do it 
is one of those scrollbars where the scroll handle blinks on focus. It is 
theoretically possible to add scrollbars to anything, but what I was suggesting 
you do was as follows:

Create a child window with WS_CHILD and no WS_CAPTION. (-pushstyle => WS_CHILD, 
-popstyle => WS_CAPTION - you might need to -popstyle => WS_BORDER as well), 
and add scrollbars to it. Assign it a parent using the SetParent() method I 
previously described. Now what you will have is a flat, captionless, borderless 
"pane" with scrollbars, inside your window. It cannot be moved or resized.

Now repeat the process (create another child window...), but this time when you 
call SetParent(win, parent), you should make the parent window the child you 
created above. What you now have is a window in a window in a window. It is the 
last child you created that you can put your widgets (buttons etc) in. When 
your scrollable child receives Scroll messages, you should move the window with 
buttons in appropriately.

The attached script should demonstrate things a little better. I don't think 
this is the most intuitive way to do things, I do know that the only thing that 
receives the Scroll event is a window or dialogbox, because I coded it that 
way. I'm thinking of removing this explicit limitation on what can be scrolled. 
You can still add scrollbars to and set scroll parameters on any widget.

Steve

  ----- Original Message ----- 
  From: Jez White 
  To: Stephen Pick ; Win32-GUI 
  Sent: Friday, January 16, 2004 1:34 PM
  Subject: Re: [perl-win32-gui-users] Scroll bar example


  Thanks for all the replies/suggestions.

  I have to admit I'm more confused now than I was when I started:)

  I tried your suggestions Steve, I end up with something that works like an 
MDI application - which is nice in itself, but not what I was after:) 

  Basically is it possible to use a scroll bar within a window, and not on one 
of it's edges? I'm trying to think of a clearer example than my tab strip one. 
Imagine a image viewing program with the main window filled with controls, the 
image could be larger than the screen so you want to place scroll bars on the 
image and not on the window (almost like putting a scroll bar on a control). I 
had assumed you could use somesort of child window to achieve this kind of 
effect?

  My thought process was basically inline with what Johan was suggesting - if a 
child window could be just another control, then the parent window would not 
lose focus and everything would be hunky dory. Using a child window in this 
manor would also make sense when attaching a child window to a band in the 
rebar control.

  Or am I just way off the mark here?:)

  Cheers,

  jez.

    ----- Original Message ----- 
    From: Stephen Pick 
    To: Jez White ; Win32-GUI 
    Sent: Friday, January 16, 2004 12:58 PM
    Subject: RE: [perl-win32-gui-users] Scroll bar example


    Your code is bad. What you're doing is creating a floating 
"BorderlessWindow" positioned over the top of the main window. If you want to 
put your window *INSIDE* the client area I suggest you do this:

    use Win32::API;
    our $SETPARENT = new Win32::API("user32","SetParent","NN","N") or croak 
"Failed to load SetParent from user32.dll";

    my $child = new Win32::GUI::DialogBox(
        -parent => $win,
        -name => "Child",
        -left => 0,
        -top => 0,
        -text => "Child",
        -width => 100,
        -height => 100,
        -style => WS_CHILD,
       );

    $SETPARENT->Call($child->{-handle}, $win->{-handle});
    $child->Width($child->Width); # force update.

    After doing this stuff, you'll find you have a dialogbox inside the main 
window. It also clips if you drag it "out" of the main window, so it truely is 
inside. You can even give it a WS_CAPTION and drag it around in the client area.

    Giving things a -parent argument does NOT mean SetParent is called on them 
in Win32::GUI.

    Steve


    -----Original Message-----
    From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Jez White
    Sent: 16 January 2004 12:37
    To: Win32-GUI
    Subject: [perl-win32-gui-users] Scroll bar example


      Hi,

      The example below will only work on the latest code line from CVS. 

      I'm trying to get my head round using scroll bars. In my test example I 
want to create a window containing one tab strip. In the tab strip there will 
be a child window containing a scroll bar and 10 buttons. Scrolling the scroll 
bar will move the buttons into and out view.

      Now, the scrolling part works fine - but is using a child window in this 
way the correct approach? For example, interacting with the child window 
(clicking on a button, or scrolling) loses focus (which you would expect for a 
normal window) but is not the correct behaviour in this case. Am I missing 
something fundamental?

      Apologies for the dodgy code - is a hack job:)

      cheers,

      jez.

      ===========
      use Win32::GUI;
      use Win32::GUI::BorderlessWindow;

      #create the main window
      my $win = new Win32::GUI::Window (
       -name => "MainWin",
       -left => 0,
       -top => 100,
       -width => 500,
       -height => 300,
       -sizable => 1,
       -text => "Scrollbar Test 2",
       -noflicker => 1,
      );

      #create a tab strip
      $win->AddTabStrip (
       -name => "Tab",
       -left => 0,
       -top => 100,
       -width => 250,
       -height => 150,  
      );
      $win->Tab->InsertItem(-text => 'Some Tab');

      #create a child window with a scroll bar
      my $childwin = new Win32::GUI::BorderlessWindow (
       -name => "Child",
       -parent =>$win,
       -left => 10,
       -top => 250,
       -width => 200,
       -height => 120,
       -hscroll => 1,
       -noflicker => 1,
       -onScroll => \&scrolled
      );

      #create content for our child window, 10 buttons.
      foreach (0..9) {
        $childwin->AddButton (
                 -name     => "Button".$_,
                 -pos      => [$_*50, 30],
                 -size     => [50, 20],
                 -text     => 'Button'.$_,);
      }

      #set the scrollbar range and starting pos
      $childwin->ScrollRange(0,0,450);
      $childwin->ScrollPos(0,0);

      $win->Show;
      $childwin->Show;
      Win32::GUI::Dialog;

      sub scrolled {
       my($object,$bar,$operation,$pos) = @_;
       my $string;
       $object->Scroll($bar,$operation,$pos);
       #Scroll the buttons...
       if($operation == SB_THUMBTRACK) {
          foreach (0..9) {
            $string='Button'.$_;
            $childwin->$string->Move(($_*50)-$pos,30);
          }
        }
      }

Attachment: scrolldemo.pl
Description: Binary data

Reply via email to