Jump to content

Create ScrollBar control


Heron
 Share

Recommended Posts

Hi there,

is it possible to create a stand alone ScrollBar control. It will be used for something different then scrolling contents of a edit/listview control or window. It must generate notify messages to handle changes. I guess I'm not the only one with this desire. Anybody advise to get me on the way?

Thanks

- Heron -

Edited by Heron
Link to comment
Share on other sites

  • Moderators

Heron,

Use a slider control. :)

Here is a simple example where vertical and horizontal sliders notify movement of the slider thumb:

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

Global $fHSlider = False
Global $fVSlider = False

$hGUI = GUICreate("Test", 500, 500)

$hHSlider= GUICtrlCreateSlider(10, 10, 400, 20, BitOR($TBS_BOTH, $TBS_NOTICKS))
$hHSlider_Handle = GUICtrlGetHandle(-1)

$hVSlider= GUICtrlCreateSlider(10, 50, 20, 400, BitOR($TBS_BOTH, $TBS_NOTICKS, $TBS_VERT))
$hVSlider_Handle = GUICtrlGetHandle(-1)

GUISetState()

GUIRegisterMsg($WM_HSCROLL, "MY_WM_HVSCROLL")
GUIRegisterMsg($WM_VSCROLL, "MY_WM_HVSCROLL")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Example code
    If $fHSlider = True Then
        $fHSlider = False
        MsgBox(0, "Slider", "Horizontal Moved!")
    EndIf
    If $fVSlider = True Then
        $fVSlider = False
        MsgBox(0, "Slider", "Vertical Moved!")
    EndIf

WEnd

; Using GUICtrlSendToDummy triggers GUIGetMsg()
Func MY_WM_HVSCROLL($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $wParam
    Switch $iMsg
        Case $WM_HSCROLL
            Switch $lParam
                Case $hHSlider_Handle
                    ; Your code goes here

                    ; Example code
                    $fHSlider = True
            EndSwitch
        Case $WM_VSCROLL
            Switch $lParam
                Case $hVSlider_Handle
                    ; Your code goes here

                    ; Example code
                    $fVSlider = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG

EndFunc   ;==>MY_WM_HVSCROLL

But you can, of course, use GUICtrlRead if you only want a simple measurement of the slider position. ;)

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

Use a slider control. :)

Thanks for your fast reply! Indeed, I considered the slider already but wanted the standard look&feel. Also the slider has no 'line buttons' or however they are called, I mean the up/down buttons to scroll one line. But maybe I end up with the slider nevertheless ;)

- Heron -

Edited by Heron
Link to comment
Share on other sites

  • Moderators

Heron,

Is this a bit nearer what you want?

#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)
_GUIScrollBars_SetScrollRange($hScroller, $SB_VERT, 0, 127) ; You have to play with the max figure to get 0-100

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

I found that you need to play with the "Max" setting for the scroll bar to get it to read from 0-100. I imagine it is because it would normally expect to stop somewhere before 100 once the last bit of the window was displaying. Anyway, trial and error has proved successful in getting the range correct.

I enjoyed that - thanks for the question. :)

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

Heron,

I have found a way to set the Scroll range to 0-100 without the guesswork. Just replace this code:

_GUIScrollBars_Init($hScroller)
_GUIScrollBars_ShowScrollBar($hScroller, $SB_HORZ , False)
_GUIScrollBars_SetScrollRange($hScroller, $SB_VERT, 0, 127) ; You have to play with the max figure to get 0-100

with this:

_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)

If I come up with any other bright ideas, i will post them here. :)

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

@ Melba23

A thanks from my part also. Your code is exactly what I intended. Don't know how you people write a code "on-demand", so fast!!! amazing.

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Link to comment
Share on other sites

  • Moderators

HolmesShelock,

Make sure you check out the Scrollbars UDF in my sig - it is much more advanced than this old thread. :unsure:

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