Sign in to follow this  
Followers 0
Fran

scrolling problem

4 posts in this topic

Hi,

Can anyone please tell me why my horizontal scroll bar only appears if I drag the window smaller than about 500pixels? And the vertical scroll bar never goes away...

This is the first time I've tried using a scroll bar in my GUI.

#RequireAdmin
#Region -> Includes
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <file.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
#include <GUIScrollBars.au3>
#include <ScrollBarConstants.au3>
#include <StructureConstants.au3>
#EndRegion -> Includes

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt('MustDeclareVars', 0)
#EndRegion -> Options

#Region -> Declarations
Local $y = @DesktopWidth - 100, $z = @DesktopHeight - 100, $g = 15 ;y:gui width, g:margin, z:gui height
#EndRegion -> Declarations

$gui = GUICreate("Sroll bar", $y, $z, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
$tab = GUICtrlCreateTab("", "", $y, $z)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
$tab1 = GUICtrlCreateTabItem("Tab1")
Global $aFileList[51]
$aFileList[0] = 50

For $i = 1 To 50
    $aFileList[$i] = 'item' & $i
Next

$iMax = $aFileList[0]
$rows = Round((@DesktopHeight - 200) / 30)
$round = Round($iMax / $rows + 0.5, 0)
Global $input[$iMax], $but[$iMax], $change[$iMax], $pic[$iMax], $iniFile[$iMax], $label[$iMax]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $label[$iIndex] = GUICtrlCreateLabel($aFileList[$iIndex + 1], 30 + ($iX * 280), 60 + ($iY * 30), 80, 20)
        GUICtrlSetResizing(-1, $GUI_DOCKALL)
        $input[$iIndex] = GUICtrlCreateInput("", 30 + ($iX * 280) + 80, 60 + ($iY * 30), 110, 20, $ES_READONLY + $ES_AUTOHSCROLL)
        GUICtrlSetResizing(-1, $GUI_DOCKALL)
    Next
Next

$tab2 = GUICtrlCreateTabItem("Tab2")
Global $input2[$iMax], $label2[$iMax]
For $iX = 0 To $round - 1
    For $iY = 0 To $rows - 1
        $iIndex = ($iX * $rows) + $iY
        If $iIndex = $iMax Then ExitLoop
        $label2[$iIndex] = GUICtrlCreateLabel($aFileList[$iIndex + 1], 30 + ($iX * 280), 60 + ($iY * 30), 80, 20)
        GUICtrlSetResizing(-1, $GUI_DOCKALL)
        $input2[$iIndex] = GUICtrlCreateInput("", 30 + ($iX * 280) + 80, 60 + ($iY * 30), 110, 20, $ES_READONLY)
    Next
Next

GUICtrlCreateTabItem("")

$butUpdate = GUICtrlCreateButton("Update", $y - 90 - $g, $z - 45, 90, 30)
GUICtrlSetResizing(-1, 768 + 64 + 4)
$butCancel = GUICtrlCreateButton("Cancel", $y - (90 * 2) - ($g * 2), $z - 45, 90, 30)
GUICtrlSetResizing(-1, 768 + 64 + 4)


_Main()

Func _Main()
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
    GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
    GUISetState()
;~  GUISetState(@SW_MAXIMIZE)
    _GUIScrollBars_Init($gui)

    While 1
        $iMsg = GUIGetMsg()
        Switch ($iMsg)
            Case $GUI_EVENT_CLOSE, $butCancel
                Exit

            Case $butUpdate
                MsgBox(0, "", "You pressed the update button")
        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam
    Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax
    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $xClientMax = $aSB_WindowInfo[$index][1]
            $xChar = $aSB_WindowInfo[$index][2]
            $yChar = $aSB_WindowInfo[$index][3]
            $ivMax = $aSB_WindowInfo[$index][7]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

    Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)

    ; Retrieve the dimensions of the client area.
    $xClient = BitAND($lParam, 0x0000FFFF)
    $yClient = BitShift($lParam, 16)
    $aSB_WindowInfo[$index][4] = $xClient
    $aSB_WindowInfo[$index][5] = $yClient

    ; Set the vertical scrolling range and page size
    DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
    DllStructSetData($tSCROLLINFO, "nMin", 0)
    DllStructSetData($tSCROLLINFO, "nMax", $ivMax)
    DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)

    ; Set the horizontal scrolling range and page size
    DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
    DllStructSetData($tSCROLLINFO, "nMin", 0)
    DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar)
    DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)

    Local $index = -1, $xChar, $xPos
    Local $Min, $Max, $Page, $Pos, $TrackPos

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

;~  ; Get all the horizontal scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $xPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $xPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    #forceref $Min, $Max
    Switch $nScrollCode

        Case $SB_LINELEFT ; user clicked left arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)

        Case $SB_LINERIGHT ; user clicked right arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)

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

        Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of 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_HORZ, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_HSCROLL

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
    EndIf

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_VSCROLL

Share this post


Link to post
Share on other sites



Fran,

Scrollbars are very tricky to get right - especially on resizable GUIs. ;) So a couple of questions before we start in:

- 1. Do you really want the main GUI to be resizeable? If not then life is very easy - 1 line of code with my GUIScrollBars_Ex UDF. :idiot:

- 2. You currently have the tabs resizing with the GUI, but not the controls on the tabs. What exactly do you want to happen? Either we can have scrollbars on each resizing tab so that you can see all the controls on it, or we keep the tab structure the same size and scroll the main GUI so that you can see the whole thing. Your choice - each is equally doable with my GUIScrollBars_Size UDF, but the scolling GUI is relatively simpler to code. :idiot:

Over to you. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

M23,

Thanx for the reply.

The only reason why I made the GUI resizeable is because I couldn't see everything on the list.

My problem is that the list keeps getting bigger as the designer adds more themes to the database. So, whether the GUI scrolls or the tab.. I don't really mind - as long as I get to see everything on the list without needing to make any adjustments later on.

Fran

Share this post


Link to post
Share on other sites

Fran,

That makes it really easy - the GUIScrollbars_Ex UDF from my sig and just one line of code. :idiot:

#Region -> Includes
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <file.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <TabConstants.au3>
#include <GUIScrollBars_Ex.au3> ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#EndRegion -> Includes

#Region -> Options
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)
Opt('MustDeclareVars', 0)
#EndRegion -> Options

#Region -> Declarations

Global $iCount = 50 ; Number of items <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $iColumn_Number = 30 ; Number of items in each column
Global $iCols = Ceiling($iCount / $iColumn_Number) ; Number of columns necessary

; Calculate size of tab to accommodate the items and the buttons
Global $y = 30 + (($iCols + 1) * 280), $z = 60 + ($iColumn_Number * 30), $g = 15 ;y:gui width, g:margin, z:gui height

Global $aFileList[$iCount + 1] = [0]
For $i = 1 To $iCount
    $aFileList[$i] = 'item' & $i
Next

Global $input[$iCount + 1], $label[$iCount + 1]
Global $input2[$iCount + 1], $label2[$iCount + 1]

#EndRegion -> Declarations

_Main()

Func _Main()

    ; Create GUI
    $gui = GUICreate("Scroll bar", 500, 400) ; any size smaller than the tab dimensions and you will get scrollbars

    ; Create tab control
    $tab = GUICtrlCreateTab("", "", $y, $z)

    ; First tab
    $tab1 = GUICtrlCreateTabItem("Tab1")
    For $iX = 0 To $iCols - 1
        For $iY = 0 To $iColumn_Number - 1
            $iIndex = ($iX * $iColumn_Number) + $iY
            If $iIndex = $iCount Then ExitLoop
            $label[$iIndex] = GUICtrlCreateLabel($aFileList[$iIndex + 1], 30 + ($iX * 280), 60 + ($iY * 30), 80, 20)
            If $iIndex = 29 Then ConsoleWrite(60 + ($iY * 30) & @CRLF)
            $input[$iIndex] = GUICtrlCreateInput("", 30 + ($iX * 280) + 80, 60 + ($iY * 30), 110, 20, $ES_READONLY + $ES_AUTOHSCROLL)
        Next
    Next

    ; Second tab
    $tab2 = GUICtrlCreateTabItem("Tab2")
    For $iX = 0 To $iCols - 1
        For $iY = 0 To $iColumn_Number - 1
            $iIndex = ($iX * $iColumn_Number) + $iY
            If $iIndex = $iCount Then ExitLoop
            $label2[$iIndex] = GUICtrlCreateLabel($aFileList[$iIndex + 1], 30 + ($iX * 280), 60 + ($iY * 30), 80, 20)
            $input2[$iIndex] = GUICtrlCreateInput("", 30 + ($iX * 280) + 80, 60 + ($iY * 30), 110, 20, $ES_READONLY)
        Next
    Next

    GUICtrlCreateTabItem("")

    ; Create buttons
    $butUpdate = GUICtrlCreateButton("Update", $y - 90 - $g, $z - 45, 90, 30)
    GUICtrlSetResizing(-1, 768 + 64 + 4)
    $butCancel = GUICtrlCreateButton("Cancel", $y - (90 * 2) - ($g * 2), $z - 45, 90, 30)
    GUICtrlSetResizing(-1, 768 + 64 + 4)

    GUISetState()

    ; Generate scrollbars
    _GUIScrollbars_Generate($gui, $y, $z) ; This is all you need to do to get scrollbars <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    While 1
        $iMsg = GUIGetMsg()
        Switch ($iMsg)
            Case $GUI_EVENT_CLOSE, $butCancel
                Exit

            Case $butUpdate
                MsgBox(0, "", "You pressed the update button")
        EndSwitch
    WEnd

EndFunc   ;==>_Main

All you have to do is adjust the $iCount = 50 ; Number of items line and everything else is taken care of. :)

Please ask if anything is unclear. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


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
Sign in to follow this  
Followers 0