Jump to content

How to move scrollbar thumb to top or bottom?


ahha
 Share

Go to solution Solved by Nine,

Recommended Posts

Under program control is there an easy way to move a slider (thumb) to the top or bottom?
I am aware of Melba23's GUIScrollbars_Ex UDF (https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-bugfix-version-2-may-21/) but I believe it's overkill for my simple needs.

In a listview with a vertical scrollbar when the window is active one can hit Ctrl+Home to move the scrollbar slider (thumb) to the top and Ctrl+End to the bottom.
One can also right click the slider and choose Scroll Here, Top, Bottom, Page UP, Page Down, Scroll Up, and Scroll Down.

I must be doing something basically wrong but am stuck.  Move the thumb to the middle before clicking the Top button to test the code below (Bottom is not coded).  I've commented out other trys.  try #3 is a strange fail.

Any comments on what I'm missing greatly appreciated as I'm stuck :(

#AutoIt3Wrapper_run_debug_mode=Y
#include <Debug.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>
AutoItSetOption("MustDeclareVars", 1)
;v1b - cut out extraneous code

Example()
Exit

Func Example()
    Local $i, $j, $x, $hGUI, $idListView, $bTop, $bBottom
    $hGUI = GUICreate("Scrollbar Question", 300, 400)   ;get handle in case we need it later
    $idListView = GUICtrlCreateListView("Col 0", 10, 10, 280, 300)
    $bTop = GUICtrlCreateButton("Top", 10, 350, 60, 25)
    $bBottom = GUICtrlCreateButton("Bottom", 120, 350, 60, 25)
    ;Pause("$hGUI = '" & $hGUI &"'"& @CRLF & "$idListView = '" & $idListView &"'")
    For $i = 1 to 100
        _GUICtrlListView_AddItem($idListView, $i)
    Next
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $bTop
                ;drag thumb to middle of scrollbar before clicking Top button

                ;try #1 - FAILS
                Opt("WinTitleMatchMode", 2)     ;2 = Match any substring in the title
                $x = WinActivate("Scrollbar Question")      ;not $idListview but main GUI $hGUI - neither working
                If $x <> $hGUI Then Pause("WinActivate FAILED")
                Send("^{HOME}") ;Ctrl+home

                ;try#2 - FAILS
;~              $x = WinActivate($hGUI)     ;try Main GUI
;~              If $x <> $hGUI Then Pause("WinActivate FAILED")
;~              Send("^{HOME}") ;Ctrl+home

                ;try#3 - strange FAILS
;~              $x = WinActivate($idListview)       ;try $idListview
;~              If $x <> $idListview Then Pause("WinActivate FAILED")   ;strange it works BUT if I comment out this line it fails
;~              ;Sleep(1000)    ;it's not a time delay issue
;~              Send("^{HOME}") ;Ctrl+home

                ;try#4 - same strange fail as #3
;~              $x = WinActivate($idListview)       ;try $idListview
;~              If $x <> $idListview Then Pause("WinActivate FAILED")
;~              Send("{UP 100}")

                ;try#5 - what the heck is going on?  same strange fail as #3
                ;$x = WinActivate($idListview)      ;try $idListview
;~              $x = WinActivate($hGUI)     ;try Main GUI
;~              If $x <> $idListview Then Pause("WinActivate FAILED")
;~              MouseWheel($MOUSE_WHEEL_UP, 100)

                ;_GUIScrollBars_ScrollWindow($hGUI, 0, 100) ;NO - moves the ListView window in the $hGUI
                ;_GUIScrollBars_ScrollWindow($idListview, 0, 100)   ;does not seem to work

                ;_GUIScrollBars_SetScrollInfoPos($hGUI, $SB_VERT, 30)   ;does not work
                ;_GUIScrollBars_SetScrollInfoPos($idListview, $SB_VERT, 30) ;does not work

                ;I'm doing something very basic wrong.  I need help.

                Pause("Scrollbar thumb should be at Top")

            Case $bBottom
                Pause("In: Case $bBottom")
                Pause("Scroll bar should be at BOttom")
        EndSwitch
    WEnd

    GUIDelete($idListView)

EndFunc   ;Func Example()

Func  Pause($text="")
    MsgBox(262144, "DEBUG", "Paused: " & $text)
EndFunc

 

Link to comment
Share on other sites

Hi ahha,
This works for me :

; add $hListView to the list of variables
Local $i, $j, $x, $hGUI, $idListView, $hListView, $bTop, $bBottom
...
$idListView = GUICtrlCreateListView("Col 0", 10, 10, 280, 300)
$hListView = GuiCtrlGetHandle($idListView) ; add this line
...

; try #1
; Opt("WinTitleMatchMode", 2) ; 2 = Match any substring in the title
; $x = WinActivate("Scrollbar Question") ; not $idListview but main GUI $hGUI - neither working
; If $x <> $hGUI Then Pause("WinActivate FAILED")
If _WinAPI_GetFocus() <> $hListView Then _WinAPI_SetFocus($hListView)
; Send("^{HOME}") ;Ctrl+home
Send("{HOME}") ;home makes it too

 

Link to comment
Share on other sites

  • Solution

Or this variant of @pixelsearch

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <GuiScrollBars.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
  Local $hGUI = GUICreate("Scrollbar Question", 300, 400)
  Local $idListView = GUICtrlCreateListView("Col 0", 10, 10, 280, 300)
  Local $hListView = GUICtrlGetHandle($idListView)
  Local $bTop = GUICtrlCreateButton("Top", 10, 350, 60, 25)
  Local $bBottom = GUICtrlCreateButton("Bottom", 120, 350, 60, 25)

  For $i = 1 To 100
    _GUICtrlListView_AddItem($idListView, $i)
  Next
  GUISetState()

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $bTop
        ControlFocus($hGUI, "", $hListView)
        ControlSend($hGUI, "", $hListView, "{HOME}")
        Pause("Scrollbar thumb should be at Top")
      Case $bBottom
        ControlFocus($hGUI, "", $hListView)
        ControlSend($hGUI, "", $hListView, "{END}")
        Pause("Scroll bar should be at BOttom")
    EndSwitch
  WEnd
EndFunc   ;==>Example

Func Pause($text = "")
  MsgBox(262144, "DEBUG", "Paused: " & $text)
EndFunc   ;==>Pause

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...