Jump to content
buymeapc

_GUIScrollBars Question

Recommended Posts

Hey gang,

I've taken advantage of Melba's excellent scrollbar UDF for my GUI and I'm having a great time with it, but I'm encountering an issue that I'm hoping to get some help on.

Once the GUIs are loaded, things work great. However, if I scroll all the way to the bottom, then maximize the window, the scrollbar stays where it is and the secondary window is proportioned properly, but I can now scroll up into basically empty space. I'm not quite sure how to remedy this.

Here's a quick reproducer to show what I'm talking about. All you need to do to replicate is scroll the scrollbar to the bottom of the window, then maximize the window. You'll see the scrollbar at the bottom of the window and the controls that were at the top, are now in view and I can now scroll up into nothingness.

Any help would be greatly appreciated. Thanks!!

#include <GUIScrollBars_Ex.au3>

$iLeft = 5 ; The distance of the labels from the left edge of the window
$iTop = 40 ; First label's distance from the top edge of the window
$iWidth = 100 ; Width of labels
$iHeight = 25 ; Height of labels
$iSpacing = 30 ; Vertical distance between the labels

$hGUI = GUICreate('Calculate exact scrollheight for dynamic labels after maximize window', 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
GUICtrlCreateTab(2, 2, 496, 496)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("Example")
$hGUI2 = GUICreate("", 488, 464, $iLeft, 26, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
For $i = 1 To 50
    GUICtrlCreateLabel('Label ' & $i, $iLeft, $iTop, $iWidth, $iHeight)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetResizing(-1, $GUI_DOCKALL) ; Prevent resizing
    $bot = $iTop + $iHeight ; Bottom edge of the last label
    $iTop = $bot + $iSpacing ; Top of next label
Next

$cButton = GUICtrlCreateButton("Maximize", 400, 40, 50, 30)
GUICtrlCreateTabItem("")

$iMaxScrollHeight = $iTop

_GUIScrollbars_Generate($hGUI2, 0, $iMaxScrollHeight)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI2)

GUIRegisterMsg($WM_SIZE, "_WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            GUISetState(@SW_MAXIMIZE)
    EndSwitch
Wend

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
        #forceref $iMsg, $wParam, $lParam
        If $hWnd = $hGUI Then
            ; Get new GUI size
            Local $aGUI_Size = WinGetClientSize($hGUI)
            ; Resize scroll GUI
            WinMove($hGUI2, "", Default, Default, ($aGUI_Size[0] - 14), ($aGUI_Size[1] - 34))
            ; Create scrollbar if needed
            If $aGUI_Size[1] < $iMaxScrollHeight Then
                _GUIScrollbars_Generate($hGUI2, 0, $iMaxScrollHeight)
            EndIf
        EndIf
EndFunc   ;==>_WM_SIZE

 

Share this post


Link to post
Share on other sites

buymeapc,

Personally I would do it like this:

#include <GUIScrollBars_Ex.au3>

$iLeft = 5 ; The distance of the labels from the left edge of the window
$iTop = 40 ; First label's distance from the top edge of the window
$iWidth = 100 ; Width of labels
$iHeight = 25 ; Height of labels
$iSpacing = 30 ; Vertical distance between the labels

$hGUI = GUICreate('Calculate exact scrollheight for dynamic labels after maximize window', 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))
GUICtrlCreateTab(2, 2, 496, 496)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM)
GUICtrlCreateTabItem("Example")

$hGUI2 = GUICreate("", 488, 464, $iLeft, 26, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
For $i = 1 To 50
    GUICtrlCreateLabel('Label ' & $i, $iLeft, $iTop, $iWidth, $iHeight)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetResizing(-1, $GUI_DOCKALL) ; Prevent resizing
    $bot = $iTop + $iHeight ; Bottom edge of the last label
    $iTop = $bot + $iSpacing ; Top of next label
Next

$cButton = GUICtrlCreateButton("Maximize", 400, 40, 50, 30)
GUICtrlCreateTabItem("")

$iMaxScrollHeight = $iTop

_GUIScrollbars_Generate($hGUI2, 0, $iMaxScrollHeight)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI2)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            ; Get new GUI size
            Local $aGUI_Size = WinGetClientSize($hGUI)
            ; Get current scroll bar position
            $iPos = _GUIScrollBars_GetScrollInfoPos($hGUI2, $SB_VERT)
            ; And set scrollbar to top
            _GUIScrollBars_SetScrollInfoPos($hGUI2, $SB_VERT, 0)
            ; Resize scroll GUI
            WinMove($hGUI2, "", Default, Default, ($aGUI_Size[0] - 14), ($aGUI_Size[1] - 34))
            ; Reset scrollbar position
            _GUIScrollBars_SetScrollInfoPos($hGUI2, $SB_VERT, $iPos)
        Case $cButton
            GUISetState(@SW_MAXIMIZE)
    EndSwitch
Wend

And was there any particular reason why you did not post this in the UDF thread so that I would be guaranteed to see it?

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

 

Share this post


Link to post
Share on other sites

Thank you for the help, Melba! That was just what I needed.

1 hour ago, Melba23 said:

And was there any particular reason why you did not post this in the UDF thread so that I would be guaranteed to see it?

Hmm...good point. I did not think to post to your UDF thread. I will definitely post there if I have another question. Thanks again.

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

×
×
  • Create New...