Jump to content

How to move scrollbar thumb to top or bottom?


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 post
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 post
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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ahha
      Newbie to _GUICtrlListView_RegisterSortCallBack and can't get it to sort properly on date in format MM/DD/YYYY.
      Example code below.  Q - How do I get the date to sort properly?
      ;#AutoIt3Wrapper_run_debug_mode=Y #include <GUIConstantsEx.au3> #include <GuiListView.au3> Global $g_id_ListView Example() Exit Func Example() Local $idRow1, $idRow2, $idRow3 GUICreate("ListView Sort Question", 300, 200) $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date", 10, 10, 280, 180) $id_Row1 = GUICtrlCreateListViewItem("#1|Alice|01/15/2022", $g_id_ListView) $id_Row2 = GUICtrlCreateListViewItem("#2|Bob|02/22/2021", $g_id_ListView) $id_Row3 = GUICtrlCreateListViewItem("#3|Carol|03/13/2021", $g_id_ListView) $id_Row10 = GUICtrlCreateListViewItem("#10|Dave|10/09/2021", $g_id_ListView) $id_Row11 = GUICtrlCreateListViewItem("#11|Eve|11/21/2021", $g_id_ListView) GUISetState(@SW_SHOW) ;$vCompareType = 0 ;not ok as Row# sort #1, #10, and want #1, #2, ;$vCompareType = 1 ;not ok as Row# sort #1, #10, and want #1, #2, $vCompareType = 2 ;Row# okay but Date messed up _GUICtrlListView_RegisterSortCallBack($g_id_ListView, $vCompareType) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $g_id_ListView ;MsgBox(0,"","col="&GUICtrlGetState($g_id_ListView)) _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView)) EndSwitch WEnd _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView) GUIDelete($g_id_ListView) EndFunc ;Func Example()  
    • By mike1950r
      Hi,
      I have a problem with the scrollbar in edit control.
      In my case I use richedit, but it appears also in the "normal" editcontrol.
      The problem ONLY appears, when working with my program (including editcontrol) and another program like notpad on the other screen.
      It appears when using the scrollbar of notepad, then my scroll bar and so on ... (vertical scrollbars only)
      and then suddenly the area behind my scrollbar gets highlighted (black) like selected, above and below,
      if i move the mouse to the left during pressing, the whole area behind the scrollbar gets highlighted in black.
      When my program is loaded alone the problem NEVER happens.
      I have made two screenshots, 1st one when the problem appears, and the second one showing when moving to the left.
      I really have no idea and there is nothing special in my editcontrol.
      I would be really thankful, if someone could help me further to get this issue solved.
      thanks in advance
      cheers mike


       
    • By UEZ
      This project has been discontinued!
       
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from the live web site cannot be downloaded although they are visible!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.6 build 2020-09-23 beta.7z  (1557 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • By Cengokill
      Hi everyone,
      I have created a ListView that is in a tab, and I want to display an image in that tab, with the ListView on top.
      However, the image still appears on top of my ListView.
      If I remove the tabs everything works. 
      I looked at the autoit documentation and the <GuiListView.au3> documentation , I can't figure out how to display a background image, and put on top a ListView, inside a tab. 😥
      Here is the code:
      Opt("GUIOnEventMode", 1) $Form1 = GUICreate($Titre, 700, 627, $Form1Width, $Form1Height); main window $tabulation = GUICtrlCreateTab(148,0,700,580); creating tabs $tab1=GUICtrlCreateTabItem("Tab 1"); first tab GUICtrlSetState(-1, $GUI_SHOW); this tab is selected by default $Pic1 = GUICtrlCreatePic("image.jpg", 0, 30, 700, 627) GUICtrlSetState(-1, $GUI_DISABLE). $idListview = GUICtrlCreateListView("list 1|list 2|list 3", 200, 50, 390, 200) GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Thank you in advance.

    • By DrJohn
      Hello all.  It's me again.
      I've got a ListView with an associated ImageList to display icons.  What I seem to be hung up on is how to keep the ImageList updated to match the ListView as the latter changes.  I thought it was the case that the indices of the items in the ListView and those in the ImageList just needed to match.  So, for example, if I:
      Delete an item from the ListView [_GUICtrlListView_DeleteItem()], and also delete the image at the matching index in the ImageList [_GUIImageList_Remove()]. Then add a new item to the end of the ListView [_GUICtrlListView_AddItem()], and correspondingly add an image at the end of the ImageList [_GUIImageList_AddIcon()] Shouldn't everything stay in sync?
      Here's the code I thought would work:
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiImageList.au3> Test() func Test() $gui = GUICreate("Test", 400, 300) ; Create ListView $lv = _GUICtrlListView_Create($gui, "", 10, 10, 380, 240, $LVS_DEFAULT) _GUICtrlListView_AddColumn($lv, "Col1", 50) _GUICtrlListView_AddColumn($lv, "Col2", 50) for $i = 0 to 2 $s = StringFormat("%d,1", $i+1) _GUICtrlListView_AddItem($lv, $s, $i) $s = StringFormat("%d,2", $i+1) _GUICtrlListView_AddSubItem($lv, $i, $s, 1) next ; Add ImageList $img_list = _GUIImageList_Create(16, 16, 5, 3) for $i = 0 to 2 $ico = StringFormat("%d.ico", $i+1) _GUIImageList_AddIcon($img_list, $ico) next _GUICtrlListView_SetImageList($lv, $img_list, 1) ; $btn = GUICtrlCreateButton("Test", 10, 260, 60, 30) GUISetState(@SW_SHOW) HotKeySet("^q", Quit) ; Loop until the user exits. while True switch GUIGetMsg() case $GUI_EVENT_CLOSE Exit case $btn ; Remove 2nd list item and image _GUICtrlListView_DeleteItem($lv, 1) _GUIImageList_Remove($img_list, 1) ; Add new item to end of ListView $idx = _GUICtrlListView_AddItem($lv, "foo") _GUICtrlListView_AddSubItem($lv, $idx, "bar", 1) ; Add new image to end of ImageList _GUIImageList_AddIcon($img_list, "5.ico") endswitch wend GUIDelete() endfunc func Quit() Exit endfunc What seems to happen is that when the new item is added to the ListView, its icon is 1.ico (the first item in the ImageList), rather than 5.ico (the newly added item that should be at the end of the ImageList).
      Or do I need to re-create the whole ImageList any time the ListView changes?
      A zip file is attached that contains the script and also the .ico files, for easier testing.
      Thanks!
      /John
      test.zip
×
×
  • Create New...