[Class] ScrollBar - A class to simplify the use and management of scrollbars in a Gui object

Post your working scripts, libraries and tools.
Pianisuto
Posts: 1
Joined: 26 Mar 2023, 20:22
Contact:

[Class] ScrollBar - A class to simplify the use and management of scrollbars in a Gui object

Post by Pianisuto » 26 Mar 2023, 20:41

Hey everyone :wave:,

I wanted to share a class that I created to simplify the use and management of scrollbars in a Gui object. The class is based on research of "winuser.h" and some posts from the AutoHotkey forums, particularly the post located at https://www.autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/#entry168174. The class provides functionality to create a scrollable GUI with the use of a scrollbar.

Here's an example usage of the ScrollBar class:

Code: Select all

M := Gui('+Resize')
Loop 15 {
    M.Add("Button", "x5 y" 10 + ((A_Index - 1) * 100) " w800 h80", A_Index)
}
SB := ScrollBar(M, 120, 200)
M.Show('w500 h200')
M.OnEvent "Close", (*) => ExitApp()
M.OnEvent "Escape", (*) => ExitApp()

#HotIf WinActive(M.Hwnd)
    WheelUp::
    WheelDown::
    +WheelUp::
    +WheelDown:: {
        SB.ScrollMsg(InStr(A_ThisHotkey,"Down") ? 1 : 0, 0, GetKeyState("Shift") ? 0x114 : 0x115, M.Hwnd)
        return
    }
#HotIf
More details at https://github.com/Pianisuto/autohotkey-v2-scroll-bar.

The class constructor takes a Gui object, width, and height as parameters. You can optionally pass in the width and height to calculate the scrollbar sizes based on the control size.

I hope you find this class useful! Let me know if you have any feedback or suggestions. :)

Best regards :salute:,
Pianisuto

Return to “Scripts and Functions (v2)”