Jump to content

Scrollbars Made Easy - New version 27 Jan 22


Melba23
 Share

Recommended Posts

  • Moderators

corgano,

I want the guI to be resizable, like most windows are (click and drag corner, you know?) I want the position and size fo the buttons on the side to remain unchanged, I want the middle scrollable section to expand as the gui is expanded, and I want the buttons in the scrollable area to fill as many as will fit in the scrollable area

Quite a list - and what have you tried for yourself so far? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

corgano,

I have my version working. Where is your trial code? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The program is to assist some touchscreen till software, a button on the till launches the program, you can select the item by picture, and the program sends the item's code to the till. The zip has my script, source, and a fake "till" program that you can use to test the setup. The compiled produceselect.exe is an older version, and I tried to add resizability to the source but haven't had much luck.

Sorry about the long wait for reply. I gave up on it and started working on the rest of the program, now that the rest is finished I decided I'd take another go at it - however, as the gui resizes the child doesn't (probably because it's not really a control rather another window). I'm not sure what method is best to try and resize it with the parent window

zip with code and resources here

Edited by corgano

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • Moderators

corgano,

I will accept that as you making an effort! :D

Here is my version: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include "GUIScrollbars_Ex.au3"

; Scrollbar settings
Global $iScroll_Page = 1, $iScrollH_Max, $iH_Tight = 1, $iV_Tight = 1


; Button info and array to hold ControlIDs
$iNumber = 29
$iSpacing = 110
Global $aButton[$iNumber + 1] = [$iNumber]

; GUI initial data
$iGUI_Width = 575
$iGUI_Height = 600

; Create GUI
$hGUI = GUICreate("Scroll Bar Examples", $iGUI_Width, $iGUI_Height, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))
GUISetBkColor(0xC4C4C4)
$cButton_Up = GUICtrlCreateButton("/", $iGUI_Width - 10 - 75, 10, 75, 75)
$cButton_Down = GUICtrlCreateButton("/", $iGUI_Width - 10 - 75, $iGUI_Height - 75 - 10, 75, 75)
GUISetState()

; Size scroll GUI
$aClient = WinGetClientSize($hGUI)
$iSubView_W = $aClient[0] - 40 - 75
$iSubView_H = $aClient[1] - 40

; Create scroll GUI
$hSubContent = GUICreate("", $iSubView_W, $iSubView_H, 10, 10, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFFFFF)

; Create buttons
_Create_Buttons()

GUISetState()

; Register the sizing message
GUIRegisterMsg($WM_SIZING, "_WM_SIZING")

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_Up
            $iScroll_Page -= 1
            If $iScroll_Page < 1 Then $iScroll_Page = 1
            _GUIScrollbars_Scroll_Page($hSubContent, 0, $iScroll_Page)
        Case $cButton_Down
            $iScroll_Page += 1
            If $iScroll_Page > $iScrollH_Max Then $iScroll_Page = $iScrollH_Max
            _GUIScrollbars_Scroll_Page($hSubContent, 0, $iScroll_Page)
        Case $GUI_EVENT_RESIZED
            ; GUI has been resized so redraw buttons
            _Create_Buttons()
        Case Else
            For $i = 1 To $aButton[0]
                If $iMsg = $aButton[$i] Then
                    MsgBox(0, "Button pressed", $i -1)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

Func _WM_SIZING($hWnd, $iMsg, $wParam, $lParam)

    #forceref $iMsg, $wParam, $wParam

    If $hWnd = $hGUI Then
        ; Delete buttons if not yet done
        If $aButton[0] Then
            _GUIScrollbars_Scroll_Page($hSubContent, -1, 1)
            _Delete_Buttons()
        EndIf
        ; Resize the child
        Local $aClient = WinGetClientSize($hGUI)
        Local $aWinPos = WinGetPos($hSubContent)
        WinMove($hSubContent, "", $aWinPos[0], $aWinPos[1], $aClient[0] - 40 - 75, $aClient[1] - 40)
    EndIf

EndFunc   ;==>_WM_SIZING

Func _Create_Buttons()

    ; How many rows and columns can we fit in now
    Local $aClient = WinGetClientSize($hSubContent)
    $iHorz_Limit = Int($aClient[0] / $iSpacing)
    $iVert_Limit = Int($aClient[1] / $iSpacing)

    ; And how may rows do we need
    $iRows_Required = Ceiling($iNumber / $iHorz_Limit)

    ; Create scrollbatrs if needed
    If $iRows_Required > $iVert_Limit Then
        _GUIScrollbars_Generate($hSubContent, 0, $iRows_Required * $iSpacing, 0, $iV_Tight, True)
    Else
        _GUIScrollBars_ShowScrollBar($hSubContent, $SB_VERT, False)
    EndIf

    ; Create buttons
    $aButton[0] = $iNumber
    GUISwitch($hSubContent)
    For $i = 0 To $iRows_Required - 1
        $iY = $i * $iSpacing
        For $j = 0 To $iHorz_Limit -1
            $iX = $j * $iSpacing
            ; Which button
            $iItem = $j + ($i * $iHorz_Limit)
            ; Have we created enough?
            If $iItem = $iNumber Then
                ExitLoop 2
            EndIf
            $aButton[$iItem + 1] = GUICtrlCreateButton($iItem & " (" & $i & ", " & $j & ")", 10 + $iX, 10 + $iY, 100, 100)
        Next
    Next
    ; Set max page number
    $iScrollH_Max = Ceiling($iRows_Required * $iSpacing / $aClient[1])

EndFunc

Func _Delete_Buttons()

    ; Delete existing buttons
    For $i = 1 To $iNumber
        GUICtrlDelete($aButton[$i])
    Next
    $aButton[0] = 0

EndFunc

Any use? Happy to help if we need a bit of integration into your script. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks mate! This looks awesome! I think this should be added to the examples, as well as an input to change the number of buttons :P Slight issue found, when I made the example smaller than the width of 1 button, it stopped working O.o

Alright, so after experimenting, I found it harder than I thought to combine our scripts. Correct me if i'm wrong, but yours generates the gui and the scrollable sub GUI at the same time, and then when it's resized it deletes the buttons, resizes the GUI, and then re-creates the buttons?

Using an idea from yours, I added 3 lines to my version (which deletes the entire sub-GUI and re creates it) and it works!

However, when resizing, the gui doesn't look nearly as pretty as yours. Is that because I didn't delete the buttons? Or is there somthing else you did to the sub GUI?

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include 
#include 
#include 
#include 
#include 

#include "RecFileListToArray.au3"
#include "GUIScrollbars_Ex.au3"

Global $iScroll_Page = 1

$width = 575
$height = 600

$dBase = @scriptdir&"img"
$dCurrent = ""

$hGUI = GUICreate("Scroll Bar Examples", $width, $height, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))
$bUp = GUICtrlCreateButton("/", $width-10-75, 10, 75, 75)
$bDown = GUICtrlCreateButton("/", $width-10-75, 10+75+4, 75, 75)
$bCancil = GUICtrlCreateButton("Cancil", $width-10-75, $height-75-10, 75, 75)
GUISetState()

; Start example
While 1

;Get folders and files, n is to determine the number of buttons required
$n = 0
$aFolders = _RecFileListToArray($dBase&$dCurrent, "*", 2, 0, 1)
$aFiles = _RecFileListToArray($dBase&$dCurrent, "*", 1, 0, 1)
if IsArray($aFiles) Then $n += $aFiles[0]
if IsArray($aFolders) Then $n += $aFolders[0]
;Make an array to hold the button handles
dim $hButton[$n+1]
$hButton[0]=$n

;size SubView
$aClient = WinGetClientSize($hGUI)
$iSubView_W = $aClient[0] - 40 - 75
$iSubView_H = $aClient[1] - 40
;Calculate scroll limits
$iScroll_Ht = 120+(110*Ceiling($n/floor(($iSubView_W-10)/110)-1))

$numperrow = floor(($iSubView_W-10)/110)

$iH_Tight = 1
$iV_Tight = 1

$hSubContent = GUICreate("", $iSubView_W, $iSubView_H, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFFFFFF)
$bBack = GUICtrlCreateButton("Back",10,10,100,100)
if $dCurrent = "" Then GUICtrlSetState(-1, $GUI_DISABLE)

$iScroll_Max = Ceiling(10+Ceiling(($iScroll_Ht / $height)/110)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


$aSubContent = _GUIScrollbars_Generate($hSubContent, 0, $iScroll_Ht+100, 1, 1, True)
If @error Then
MsgBox(16, @error, "Scrollbar generation failed")
Exit
EndIf
$iSubView_W = $aSubContent[0]
$iSubView_H = $aSubContent[1]


$iLine_Width = $iSubView_W
$i = 1
If IsArray($aFolders) Then
For $i = $i To $i+$aFolders[0]-1
$x = Mod(($i),floor(($iSubView_W-10)/110))
$y = Floor(($i)/floor(($iSubView_W-10)/110))
$hButton[$i] = GUICtrlCreateButton(""&$aFolders[$i],10+$x*110,10+$y*110,100,100)
Next
EndIf
$temp = $i
If IsArray($aFiles) Then
For $i = $i To $i+$aFiles[0]-1
$x = Mod(($i),floor(($iSubView_W-10)/110))
$y = Floor(($i)/floor(($iSubView_W-10)/110))
$hButton[$i] = GUICtrlCreateButton("",10+$x*110, 10+$y*110, 100, 100, 0x0080)
GUICtrlSetImage(-1,$dBase&$dCurrent&""&$aFiles[$i+$temp-1])
Next
EndIf

GUICtrlCreateLabel("", $iSubView_W - 40, $iSubView_H - 50, 40, 100)
GUICtrlSetBkColor(-1, 0xFFC4C4)
GUICtrlCreateLabel("Page 1", $iSubView_W - 40, $iSubView_H - 15, 40, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlCreateLabel("Page 2", $iSubView_W - 40, $iSubView_H, 40, 15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

GUISetState()

GUICtrlCreateLabel("fdahadfh", -10, $iScroll_Ht - 10, 10, 10)
GUICtrlSetBkColor(-1, 0x0000FF)

While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $bCancil
Exit
Case $bUp ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$iScroll_Page -= 1
If $iScroll_Page < 1 Then $iScroll_Page = 1
_GUIScrollbars_Scroll_Page($hSubContent, 0, $iScroll_Page)
Case $bDown ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$iScroll_Page += 1
If $iScroll_Page > $iScroll_Max Then $iScroll_Page = $iScroll_Max
_GUIScrollbars_Scroll_Page($hSubContent, 0, $iScroll_Page)
Case $bBack
if $dCurrent <> "" Then
$dCurrent = StringLeft($dCurrent,StringInStr($dCurrent,"")-1)
GUIDelete($aSubContent)
ExitLoop 1
EndIf
Case $GUI_EVENT_RESIZED
GUIDelete($aSubContent)
ExitLoop 1

EndSwitch
if IsArray($hButton) Then
for $i = 1 to $hButton[0]
If $msg = $hButton[$i] Then
$tButton = GUICtrlRead($hButton[$i]&@CRLF)
If stringleft($tButton,1) = "" Then
ConsoleWrite($tButton&@CRLF)
$dCurrent&=$tButton
GUIDelete($aSubContent)
ExitLoop 2
Else
$temp = $i
if IsArray($aFolders) then $temp -=$aFolders[0]
$code = StringTrimRight($aFiles[$temp],4)
ControlSetText("Fake Till","","[CLASS:Edit; INSTANCE:1]",$code)
ControlClick("Fake Till","","[CLASS:Button; INSTANCE:14]")
Exit
EndIf
EndIf
Next
EndIf
WEnd
WEnd

0x616e2069646561206973206c696b652061206d616e20776974686f7574206120626f64792c20746f206669676874206f6e6520697320746f206e657665722077696e2e2e2e2e

Link to comment
Share on other sites

  • Moderators

corgano,

I think this is working correctly. I have limited the size of the GUI so that you can show at least 2 buttons and simplified the button writing code. I also renamed most of the variables so I could follow what was going on: ;)

#include "RecFileListToArray.au3"
#include "GUIScrollbars_Ex.au3"

; Declare scrollbar variables
Global $iScroll_Page = 1, $iScroll_Max, $iH_Tight = 1, $iV_Tight = 1

; Set GUI initial and minimum sizes
Global $iGUI_Width = 575, $iGUI_Height = 600, $iSpacing = 110
Global $iGUI_MinWidth = 250, $iGUI_MinHeight = 280

; Declare globals
Global $dBase = @ScriptDir & "img", $dCurrent = ""
Global $aButton[1] = [0]

; Create GUI
$hGUI = GUICreate("Scroll Bar Examples", $iGUI_Width, $iGUI_Height, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX))
GUISetBkColor(0xC4C4C4)

$cButton_Up = GUICtrlCreateButton("/", $iGUI_Width - 10 - 75, 10, 75, 75)
$cButton_Down = GUICtrlCreateButton("/", $iGUI_Width - 10 - 75, 10 + 75 + 4, 75, 75)
$cButton_Cancel = GUICtrlCreateButton("Cancel", $iGUI_Width - 10 - 75, $iGUI_Height - 75 - 10, 75, 75)

GUISetState()

; Size and create SubView
$aClient = WinGetClientSize($hGUI)
$iSubView_W = $aClient[0] - 40 - 65
$iSubView_H = $aClient[1] - 20
$hSubContent = GUICreate("", $iSubView_W, $iSubView_H, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetState()

; Register messages
GUIRegisterMsg($WM_SIZING, "_WM_SIZING")
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")

; Start example
While 1

    ;Get folders and files to determine the number of buttons required
    $iNumber = 1 ; Because there is always a "Back" button
    Global $aFolders = _RecFileListToArray($dBase & $dCurrent, "*", 2, 0, 1)
    If IsArray($aFolders) Then
        $iNumber += $aFolders[0]
    Else
        Global $aFolders[1] = [0] ; Declare a dummy array if nothing found
    EndIf
    Global $aFiles = _RecFileListToArray($dBase & $dCurrent, "*", 1, 0, 1)
    If IsArray($aFiles) Then
        $iNumber += $aFiles[0]
    Else
        Global $aFiles[1] = [0] ; Declare a dummy array if nothing found
    EndIf

    ; Size SubView
    $aClient = WinGetClientSize($hGUI)
    $iSubView_W = $aClient[0] - 40 - 65
    $iSubView_H = $aClient[1] - 20
    ;Calculate scroll limits
    $iScroll_Ht = 120 + (110 * Ceiling($iNumber / Floor(($iSubView_W - 10) / 110) - 1))

    ; Fill Subview with buttons
    _Create_Buttons()

    ; Wait for input
    While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE, $cButton_Cancel
                Exit
            Case $cButton_Up
                $iScroll_Page -= 1
                If $iScroll_Page < 1 Then $iScroll_Page = 1
                _GUIScrollbars_Scroll_Page($hSubContent, 0, $iScroll_Page)
            Case $cButton_Down
                $iScroll_Page += 1
                If $iScroll_Page > $iScroll_Max Then $iScroll_Page = $iScroll_Max
                _GUIScrollbars_Scroll_Page($hSubContent, 0, $iScroll_Page)
            Case $GUI_EVENT_RESIZED
                ; GUI has been resized so redraw buttons
                _Create_Buttons()
            Case $aButton[1] ; This is always the Back button - which is disabled if we are at the root
                ; Reset the current folder
                $dCurrent = StringLeft($dCurrent, StringInStr($dCurrent, "") - 1)
                ; And redraw the buttons
                ExitLoop 1
            Case Else
                ; Look for another button
                For $i = 2 To $aButton[0]
                    If $iMsg = $aButton[$i] Then
                        $sButton = GUICtrlRead($aButton[$i])
                        ; Is it a folder
                        If StringLeft($sButton, 1) = "" Then
                            ; Set the required folder
                            $dCurrent &= $sButton
                            ; And redraw the buttons
                            ExitLoop 2
                        Else
                            ; Get the image number
                            $sCode = StringTrimRight($aFiles[$i - $aFolders[0] - 1], 4)
                            ConsoleWrite($sCode & @CRLF)
                            ;ControlSetText("Fake Till", "", "[CLASS:Edit; INSTANCE:1]", $code)
                            ;ControlClick("Fake Till", "", "[CLASS:Button; INSTANCE:14]")
                        EndIf
                    EndIf
                Next
        EndSwitch
    WEnd
WEnd

Func _WM_SIZING($hWnd, $iMsg, $wParam, $lParam)

    #forceref $iMsg, $wParam, $wParam

    If $hWnd = $hGUI Then
        ; Delete buttons if not yet done
        If $aButton[0] Then
            _Delete_Buttons()
        EndIf
        ; Resize the child
        Local $aClient = WinGetClientSize($hGUI)
        Local $aWinPos = WinGetPos($hSubContent)
        WinMove($hSubContent, "", $aWinPos[0], $aWinPos[1], $aClient[0] - 40 - 65, $aClient[1] - 20)

        $aButPos = ControlGetPos($hGUI, "", $cButton_Up)
        ControlMove($hGUI, "", $cButton_Down, $aButPos[0], $aButPos[1] + 79)

    EndIf

EndFunc   ;==>_WM_SIZING

; Prevent GUI from getting too small
Func _WM_GETMINMAXINFO($hwnd, $iMsg, $wParam, $lParam)
    $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo, 7, $iGUI_MinWidth) ; min X
    DllStructSetData($tagMaxinfo, 8, $iGUI_MinHeight) ; min Y
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

Func _Create_Buttons()

    ; Delete current buttons
    _Delete_Buttons()

    ;Make an array to hold the button handles
    Global $aButton[$iNumber + 1]
    $aButton[0] = $iNumber

    ; How many rows and columns can we fit in now
    Local $aClient = WinGetClientSize($hSubContent)
    $iHorz_Limit = Int($aClient[0] / $iSpacing)
    $iVert_Limit = Int($aClient[1] / $iSpacing)

    ; And how may rows do we need
    $iRows_Required = Ceiling($iNumber / $iHorz_Limit)

    ; Create scrollbars if needed
    If $iRows_Required > $iVert_Limit Then
        _GUIScrollbars_Generate($hSubContent, 0, $iRows_Required * $iSpacing, 0, $iV_Tight, True)
    Else
        _GUIScrollBars_ShowScrollBar($hSubContent, $SB_VERT, False)
    EndIf

    GUISwitch($hSubContent)

    ; Create buttons
    For $i = 0 To $iRows_Required - 1
        $iY = $i * $iSpacing
        For $j = 0 To $iHorz_Limit -1
            $iX = $j * $iSpacing
            ; Button ID
            $iItem = $j + ($i * $iHorz_Limit)
            ; Have we created enough?
            If $iItem = $iNumber Then
                ExitLoop 2
            EndIf
            ; Is it the first?
            If $iItem = 0 Then
                $aButton[1] = GUICtrlCreateButton("Back", 10, 10, 100, 100)
                ; Disable if we are already at the root
                If Not $dCurrent Then
                    GUICtrlSetState(-1, $GUI_DISABLE)
                EndIf
                ContinueLoop
            EndIf
            ; Now create the buttons
            If $iItem <= $aFolders[0] Then
                ; These are folders
                $aButton[$iItem + 1] = GUICtrlCreateButton("" & $aFolders[$iItem], 10 + $iX, 10 + $iY, 100, 100)
            Else
                ; And these are images
                $aButton[$iItem + 1] = GUICtrlCreateButton("", 10 + $iX, 10 + $iY, 100, 100, 0x0080)
                GUICtrlSetImage(-1, $dBase & $dCurrent & "" & $aFiles[$iItem - $aFolders[0]])
            EndIf
        Next
    Next
    ; Set max page number
    $iScrollH_Max = Ceiling($iRows_Required * $iSpacing / $aClient[1])

EndFunc

Func _Delete_Buttons()

    ; Set scrollbars to top
    _GUIScrollbars_Scroll_Page($hSubContent, -1, 1)
    ; Delete existing buttons
    For $i = 1 To $aButton[0]
        GUICtrlDelete($aButton[$i])
    Next
    ; Set count to 0
    $aButton[0] = 0

EndFunc

Let me know if it is good enough. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 weeks later...

Hi Melba23,

we just found your code for creating scrollbars with AutoIT () which works great.

We are planning on using it for our in-house application and were wondering what license you’re publishing this code under.

Is it possible for us to use the code? We do not intend to publish or sell the code in any other way.

Thanx

mle

Link to comment
Share on other sites

  • Moderators

mle,

Thank you for both the compliments and the polite query. :)

Anything I post on the forum is free for anyone to use or modify - but if you could credit me as the author of that bit of code in the final script I would be more than happy. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 year later...

Hi,

After a request I needed to fix a bug on an old script.

In the same time I optimized it and figured out that the process dwm has a high CPU usage when scrolling  :( 

I recall having edited the ScrollBars UDF to be able to scroll with the middle mouse button and from a child window but unfortunately it has nothing to deal with the issue.

I am using Windows 7 64 bits and the latest autoit stable version.

Attached the script with some required files.

Thanks in advance :)

Br, FireFox.

autoitfirefox_scrollbar_dwm.zip

Edited by FireFox
Link to comment
Share on other sites

  • Moderators

FireFox,

Is there actually a question in that? What do you expect me to do?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 months later...

Test

Read

Test

Read

and now I ask...

P.S.
This is my first day of GUI programming, so any advice would be nice as well.

Error:

Line 54 blah blah blah

"Subscript used with non-Array variable"

Just the important bits --

Local $corrPosLAA = _GUIScrollbars_Locate_Ctrl($mainGUI, $lbAddAnotherPos[0], $lbAddAnotherPos[1] + 27)
$cmbSelection[$lastCommand] = GUICtrlCreateCombo("", $corrPosLAA[0], $corrPosLAA[1], 188)

And entire code, just in case:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIScrollBars.au3>
#include "GUIScrollbars_Ex.au3"

Global $lastCommand = 1
Global $cmbSelection[4]
Global $commandList = "item1|item2|item3"
Global $scrollBarDimension = 239

;GUI
$mainGUI = GUICreate("Command Creation", 300, 250)
GUICtrlCreateLabel("First you should:", 5, 10, 150)
GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
$cmbSelection[1] = GUICtrlCreateCombo("", 95, 5, 200)
GUICtrlSetData($cmbSelection[1], $commandList)
GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
$lbAddAnother = GUICtrlCreateLabel("Add Another...", 80, 45, 100, 20)
GUICtrlSetFont(-1, 10, 800, 4, "Trebuchet MS")
$btnFinish = GUICtrlCreateButton("Finish", 100, 100, 50)
GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
_GUIScrollBars_Generate($mainGUI, 0, $scrollBarDimension)
GUISetState(@SW_SHOW)

While 1
    $mouse = GUIGetCursorInfo()
    If IsArray($mouse) = 1 Then
        If $mouse[4] = $lbAddAnother Then
            GUISetCursor(0, 1)
        Else
            GUISetCursor(2, 1)
        EndIf
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $lbAddAnother
                CreateNewCommandOption()
        EndSwitch
    EndIf
    Sleep(10)
WEnd

Func CreateNewCommandOption()
    ;Creates a new Command Combo Box as well as moving controls below Command boxes down.
    Local $lbAddAnotherPos = ControlGetPos("", "", $lbAddAnother)
    Local $btnFinishPos = ControlGetPos("", "", $btnFinish)
    Local $commandPos = ControlGetPos("", "", $cmbSelection[$lastCommand])
    Local $corrPosLAA = _GUIScrollbars_Locate_Ctrl($mainGUI, $lbAddAnotherPos[0], $lbAddAnotherPos[1] + 27)

    $lastCommand = $lastCommand + 1
    GUICtrlCreateLabel("Then:", $commandPos[0] - 30, $commandPos[1] + 27, 27)
    GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
    ;$cmbSelection[$lastCommand] = GUICtrlCreateCombo("", $commandPos[0], $commandPos[1] + 27, 188)
    $cmbSelection[$lastCommand] = GUICtrlCreateCombo("", $corrPosLAA[0], $corrPosLAA[1], 188)
    GUICtrlSetData(-1, $commandList)
    GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
    GUICtrlSetPos($lbAddAnother, $lbAddAnotherPos[0], $lbAddAnotherPos[1] + 27)
    GUICtrlSetPos($btnFinish, $btnFinishPos[0], $btnFinishPos[1] + 27)
    ReDim $cmbSelection[$lastCommand + 3]

    ;Change Scrollbar dimensions
    If $lastCommand > 5 Then
        $scrollBarDimension = $scrollBarDimension + 27
        _GUIScrollBars_Generate($mainGUI, 0, $scrollBarDimension)
    EndIf
EndFunc   ;==>CreateNewCommandOption

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

What is the Add Another click supposed to generate, and why are you getting the position of the label to use as the position of the scroll bars? Your X position is returning 72, and that is telling the scrollbar function to use that as to where to find the control. The control you're trying to find isn't at 72, it's at 0 for the X position, so the function returns an error and you don't get the array you think you're getting.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

The button adds another label and combo box 27 pixels below the last label/combo. I have to know the position of the scrollbar in comparison to the label, because if you scroll, there is an error that will cause the new label/combo to be placed in the wrong location.

If you take out line 54, and put line 53 back in. It should show you what the program is supposed to do.

 

Perhaps I don't understand how to properly use GUI Scrollbars Locate Ctrl... Could you explain that particular function?

Edited by Sori

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

  • Moderators

Sori,

For an expanding scrollbar you need to use the GUI_Scrollbar_Size UDF - the GUIScrollbar_Ex UDF is designed for a fixed size scrolling area. ;)

I think this script does what you want and shows how you use the GUI_Scrollbar_Size UDF to resize the scrolled area as you add controls:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIScrollbars_Size.au3"

Global $lastCommand = 1
Global $cmbSelection[4]
Global $commandList = "item1|item2|item3"
Global $scrollBarDimension = 260

GUISetFont(8.5, 0, 0, "Trebuchet MS") ; Set the font here, not for each control

; Create and show the GUI
$mainGUI = GUICreate("Command Creation", 300, 250)
GUISetState(@SW_SHOW)

; Size the scrollbars to be just too big for the GUI - that way they are created BEFORE any of the controls
$aRet = _GUIScrollbars_Size(0, $scrollBarDimension, 300, 250)

GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL") ; You need a handler - see below

; Create the scrollbars
_GUIScrollBars_Init($mainGUI)
_GUIScrollBars_ShowScrollBar($mainGUI, $SB_VERT, True)
_GUIScrollBars_ShowScrollBar($mainGUI, $SB_HORZ, False)
_GUIScrollBars_SetScrollInfoPage($mainGUI, $SB_VERT, $aRet[2])
_GUIScrollBars_SetScrollInfoMax($mainGUI, $SB_VERT, $aRet[3])

; Now create the controls
GUICtrlCreateLabel("First you should:", 5, 10, 150) ; This is too wide and overlaps the combo as shown by the colour line below
GUICtrlSetBkColor(-1, 0xFF0000) ; Remove this when you have resized the label above
;GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
$cmbSelection[1] = GUICtrlCreateCombo("", 95, 5, 185)
GUICtrlSetData($cmbSelection[1], $commandList)
;GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
$lbAddAnother = GUICtrlCreateLabel("Add Another...", 80, 45, 100, 20)
;GUICtrlSetFont(-1, 10, 800, 4, "Trebuchet MS")
GUICtrlSetCursor(-1, 0) ; Use this to set the cursor <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$btnFinish = GUICtrlCreateButton("Finish", 100, 100, 50)
;GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")

While 1
    ; As you have already set the cursor, you do not need the GUIGetCursorInfo stuff here <<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    ; All you do need is the simple GUIGetMsg loop
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $lbAddAnother
            CreateNewCommandOption()
    EndSwitch
    ;Sleep(10) ; Not required as GUIGetMsg has its own built-in Sleep <<<<<<<<<<<<<<<<<<<<<<
WEnd

Func CreateNewCommandOption()

    Local $lbAddAnotherPos = ControlGetPos($mainGUI, "", $lbAddAnother)
    Local $btnFinishPos = ControlGetPos($mainGUI, "", $btnFinish)
    Local $commandPos = ControlGetPos($mainGUI, "", $cmbSelection[$lastCommand])
    $lastCommand += 1
    GUICtrlCreateLabel("Then:", $commandPos[0] - 30, $commandPos[1] + 27, 27)
    ;GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
    $cmbSelection[$lastCommand] = GUICtrlCreateCombo("", $commandPos[0], $commandPos[1] + 27, 188)
    GUICtrlSetData(-1, $commandList)
    ;GUICtrlSetFont(-1, 8.5, 0, 0, "Trebuchet MS")
    GUICtrlSetPos($lbAddAnother, $lbAddAnotherPos[0], $lbAddAnotherPos[1] + 27)
    GUICtrlSetPos($btnFinish, $btnFinishPos[0], $btnFinishPos[1] + 27)
    ReDim $cmbSelection[$lastCommand + 3]

    ; Do we need to resize the scrollbar?  Is the button too near the bottom edge?
    If $btnFinishPos[1] + 27 > 200 Then
        ; Increase the scroll distance
        $scrollBarDimension += 27
        ; Resize the scrollbars
        $aRet = _GUIScrollbars_Size(0, $scrollBarDimension, 300, 250)
        _GUIScrollBars_SetScrollInfoPage($mainGUI, $SB_VERT, $aRet[2])
        _GUIScrollBars_SetScrollInfoMax($mainGUI, $SB_VERT, $aRet[3])
    EndIf

EndFunc

; But you do need this handler
Func _Scrollbars_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)

    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

    For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
        If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $yChar = $__g_aSB_WindowInfo[$iIndex][3]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGEUP
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_Scrollbars_WM_VSCROLL
I have also made a number of other changes to the script to simplify it. Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Everything looks pretty straightforward. Thank you for your help.

I'm getting an issue inside the handler though.

If I even click on the scrollbar I receive:

Line 78

For $x = 0 to UBound($__g_aSB_WindowInfo) - 1

For $x = 0 to Ubound(^ ERROR

Error: Variable used without being declared.

Edited by Sori

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

  • Moderators

Sori,

You need the latest Beta to run that code - the variables have been renamed and I used the new name. :)

If you rename each insance of that variable to $aSB_WindowInfo it should work with earlier versions.

;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Sori,

Great. Let me know if I can help again - but please post in the General Help area unless it is specifically scrollbar related. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Melba23 changed the title to Scrollbars Made Easy - New version 27 Jan 22

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...