Jump to content

Help with horizontal scrollbar


ajit
 Share

Recommended Posts

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xCECECE, $hGUI)

$hLabel_1 = GUICtrlCreateLabel("Scroll position", 10, 10, 100, 20)
$hLabel_2 = GUICtrlCreateLabel("", 10, 50, 100, 20)

GUISetState()

$hScroller = GUICreate("Child GUI", 17, 480, 480, 10, $WS_CHILD, -1, $hGUI)
GUISetState()

_GUIScrollBars_Init($hScroller)
_GUIScrollBars_ShowScrollBar($hScroller, $SB_HORZ , False)
; Move thumb to bottom - or at least as far as it will go
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_VERT, 100)
; Read current max value and reset max value so position reads 100 when thumb is at bottom
_GUIScrollBars_SetScrollRange($hScroller, $SB_VERT, 0, (200 - _GUIScrollBars_GetScrollInfoPos($hScroller, $SB_VERT)))
; Reset thumb to top
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_VERT, 0)
 

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

$iCurr_Scroll_Pos = 9999

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

; This function comes directly from the _GUiScrollBars_Init example - except the <<<<<<<<<<<< line

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

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

    ; Get all the vertial scroll bar information
    Local $tSCROLLINFO = _GUiScrollBars_GetSCROLLInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")

    Switch $nScrollCode
        Case $SB_TOP ; user clicked the HOME keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Min)

        Case $SB_BOTTOM ; user clicked the END keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Max)

        Case $SB_LINEUP ; user clicked the top arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

        Case $SB_LINEDOWN ; user clicked the bottom arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

        Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)

        Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)

        Case $SB_THUMBTRACK ; user dragged the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUiScrollBars_SetSCROLLInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUiScrollBars_GetSCROLLInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")

    If ($Pos <> $yPos) Then
        _GUiScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
        GUICtrlSetData($hLabel_2, $Pos) ; I only added this bit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL

Hi

This is an example by Melba for scrollbar notification. I want to use it for audio position in my audio player instead of a slider. The example uses a vertical scrollbar. However much I tried I could not get it to work as an horizontal scrollbar.

Could someone help me with it.

Would be very thankful for any help.

Regards

Ajit

Link to comment
Share on other sites

  • Moderators

Ajit,

Could someone help me with it

Of course - you do it like this: :idea:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xCECECE, $hGUI)

$hLabel_1 = GUICtrlCreateLabel("Scroll position", 10, 10, 100, 20)
$hLabel_2 = GUICtrlCreateLabel("", 10, 50, 100, 20)

GUISetState()

$hScroller = GUICreate("Child GUI", 500, 20, 0, 480, $WS_CHILD, -1, $hGUI)
GUISetState()

_GUIScrollBars_Init($hScroller)
_GUIScrollBars_ShowScrollBar($hScroller, $SB_VERT , False)
; Move thumb to bottom - or at least as far as it will go
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_HORZ, 100)
; Read current max value and reset max value so position reads 100 when thumb is at bottom
_GUIScrollBars_SetScrollRange($hScroller, $SB_HORZ, 0, (200 - _GUIScrollBars_GetScrollInfoPos($hScroller, $SB_HORZ)))
; Reset thumb to top
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_HORZ, 0)


GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

$iCurr_Scroll_Pos = 9999

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

; This function comes directly from the _GUiScrollBars_Init example - except the <<<<<<<<<<<< line

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

    #forceref $iMsg, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $xChar, $xPos
    Local $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $xChar = $aSB_WindowInfo[$iIndex][2]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $xPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $xPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    Switch $nScrollCode
        Case $SB_LINELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

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

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $xPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
        GUICtrlSetData($hLabel_2, $Pos) ; I only added this bit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL

Is that enough for you to get your script to work? :)

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

Melba:

That was beautiful. Thanks very much for your help as always.

Scrollbars do look beautiful when used in conjunction with child GUIs for controls such as audio position, volume control, speed etc.

Thanks again.

Regards

Ajit

Edited by ajit
Link to comment
Share on other sites

  • Moderators

ajit,

How do I make the thumb of the scrollbar smaller

Now we get complicated! :)

The size of the thumb depends on the relationship between the page size and the max value. Basically you need to make your max size big enough so that the page size can be sufficiently small to create a minimalist thumb. Try putting this into the code I posted earlier:

$iSize = 2000
_GUIScrollBars_Init($hScroller)
_GUIScrollBars_ShowScrollBar($hScroller, $SB_VERT , False)
; Set basic limits
_GUIScrollBars_SetScrollInfoPage($hScroller, $SB_VERT, 1) ; Set very small page
_GUIScrollBars_SetScrollRange($hScroller, $SB_HORZ, 0, $iSize) ; Set very large max
; Move thumb to bottom - or at least as far as it will go
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_HORZ, $iSize)
; Read current max value and reset max value so position reads 1000 when thumb is at right
_GUIScrollBars_SetScrollRange($hScroller, $SB_HORZ, 0, (($iSize * 2) - _GUIScrollBars_GetScrollInfoPos($hScroller, $SB_HORZ)))
; Reset thumb to top
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_HORZ, 0)

GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

You will see you get a smaller thumb, but you will need to do some maths on the scrollbar return value to get 0-100 as a displayed value - this ought to do it: :(

GUICtrlSetData($hLabel_2, Int($Pos * 100 / $iSize))

If you adjust the value of $iSize you can vary the size of the thumb. Note that there is a minimum size to make sure that there is something to get hold of! :)

Scrollbars are soooo easy.......NOT! :idea:

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 weeks later...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiScrollBars.au3>
#include <ScrollBarConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xCECECE, $hGUI)

$hLabel_1 = GUICtrlCreateLabel("Scroll position Top", 10, 10, 100, 20)
$hLabel_2 = GUICtrlCreateLabel("0", 10, 50, 100, 20)

$hLabel_3 = GUICtrlCreateLabel("Scroll position Bottom", 120, 10, 120, 20)
$hLabel_4 = GUICtrlCreateLabel("0", 120, 50, 100, 20)

GUISetState()

$hScroller = GUICreate("Child GUI", 500, 20, 0, 480, $WS_CHILD, -1, $hGUI)
GUISetState()

$iSize = 100
_GUIScrollBars_Init($hScroller)
_GUIScrollBars_ShowScrollBar($hScroller, $SB_VERT , False)
; Set basic limits
_GUIScrollBars_SetScrollInfoPage($hScroller, $SB_VERT, 1) ; Set very small page
_GUIScrollBars_SetScrollRange($hScroller, $SB_HORZ, 0, $iSize) ; Set very large max
; Move thumb to bottom - or at least as far as it will go
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_HORZ, $iSize)
; Read current max value and reset max value so position reads 1000 when thumb is at right
_GUIScrollBars_SetScrollRange($hScroller, $SB_HORZ, 0, (($iSize * 2) - _GUIScrollBars_GetScrollInfoPos($hScroller, $SB_HORZ)))
; Reset thumb to top
_GUIScrollBars_SetScrollInfoPos($hScroller, $SB_HORZ, 0)

GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

$iCurr_Scroll_Pos = 9999

GUISwitch($hGUI)

Global $hGUI_Child
$hGUI_Child = GUICreate("Child GUI", 500, 18, 0, 100 , $WS_CHILD, "", $hGUI) 
GLobal $iSize2 = 100

_GUIScrollBars_Init($hGUI_Child)
_GUIScrollBars_ShowScrollBar($hGUI_Child, $SB_VERT , False)
; Set basic limits
_GUIScrollBars_SetScrollInfoPage($hGUI_Child, $SB_VERT, 1) ; Set very small page
_GUIScrollBars_SetScrollRange($hGUI_Child, $SB_HORZ, 0, $iSize2) ; Set very large max
; Move thumb to bottom - or at least as far as it will go
_GUIScrollBars_SetScrollInfoPos($hGUI_Child, $SB_HORZ, $iSize2)
; Read current max value and reset max value so position reads 1000 when thumb is at right
_GUIScrollBars_SetScrollRange($hGUI_Child, $SB_HORZ, 0, (($iSize2 * 2) - _GUIScrollBars_GetScrollInfoPos($hGUI_Child, $SB_HORZ)))
; Reset thumb to top
_GUIScrollBars_SetScrollInfoPos($hGUI_Child, $SB_HORZ, 0)


GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")

GUISetState()


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

; This function comes directly from the _GUiScrollBars_Init example - except the <<<<<<<<<<<< line

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

    #forceref $iMsg, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $iIndex = -1, $xChar, $xPos
    Local $Page, $Pos, $TrackPos

    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $iIndex = $x
            $xChar = $aSB_WindowInfo[$iIndex][2]
            ExitLoop
        EndIf
    Next
    If $iIndex = -1 Then Return 0

    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $xPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $xPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    Switch $nScrollCode
        Case $SB_LINELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGELEFT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGERIGHT
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch

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

    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $xPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
        GUICtrlSetData($hLabel_2, $Pos) ; I only added this bit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL
Hello:

Just another question. If I have two scrollbars in a single GUI (with a child GUI) how do I get the values (scrollbar position) seperately.

I have posted my code with two scrollbars. Please help me out as I need more than one scrollbar in my GUI.

Regards

Ajit

Link to comment
Share on other sites

  • Moderators

ajit,

Just check for which window sent the message. Replace the final lines of the message handler with this: :mellow:

$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $xPos) Then
    _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
    Switch $hWnd
        Case $hScroller
            GUICtrlSetData($hLabel_4, $Pos)
        Case $hGUI_Child
            GUICtrlSetData($hLabel_2, $Pos)
    EndSwitch
EndIf

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

ajit,

My pleasure as always. :mellow:

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

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...