Andreik Posted August 10, 2020 Share Posted August 10, 2020 What's the relation between scrollbar range and the GUI size? I have a script like below where I create randomly a number of labels in a child window and I create a scrollbar that eventually should fit all the child window content but I don't see the relation between whatever unit is scrollbar using and the GUI content. expandcollapse popup#include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> Global $iPos = 0 $iRandom = Random(1, 15, 1) $hMain = GUICreate("Main", 1000, 700) $cPosDisplay = GUICtrlCreateLabel("", 10, 10, 200, 30, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) $cNumOfLabels = GUICtrlCreateLabel($iRandom, 10, 50, 200, 30, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) $hChild = GUICreate("", 500, 700, 250, 0, $WS_POPUP, $WS_EX_MDICHILD, $hMain) For $Index = 1 To $iRandom GUICtrlCreateLabel($Index, 10, 10 + ($Index - 1) * 500, 480, 480, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) Next GUISetState(@SW_SHOW, $hMain) GUISetState(@SW_SHOW, $hChild) GUIRegisterMsg($WM_VSCROLL, 'WM_VSCROLL') $hVScroll = _GUIScrollBars_Init($hChild) _GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 0, 700) ; << -- _GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) Do Sleep(10) Until GUIGetMsg() = -3 Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) Switch _WinAPI_LoWord($wParam) Case $SB_THUMBPOSITION $iPos = _WinAPI_HiWord($wParam) EndSwitch GUICtrlSetData($cPosDisplay, $iPos) _GUIScrollBars_SetScrollInfoPos($hChild, $SB_VERT, $iPos) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 10, 2020 Moderators Share Posted August 10, 2020 Andreik, Scrollbars work in character height and width units - not at all intuitive. Take a look at my Scrollbars UDF (the link is in my sig) and you will see how I went about trying to get them to work - or just use the UDF itself. M23 Andreik 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Andreik Posted August 10, 2020 Author Share Posted August 10, 2020 Thanks Melba, I'll take a look and come back if I have further questions. It's strange that nothing about measurement unit is written in help file. Link to comment Share on other sites More sharing options...
Zedna Posted August 11, 2020 Share Posted August 11, 2020 For detailed info you have to search in Microsoft's helpfile/doc for corresponding Win32 API function, not in AutoIt helpfile https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setscrollrange Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Andreik Posted August 11, 2020 Author Share Posted August 11, 2020 I know what you mean Zedna but it's not detailed info, it's basic info in my opinion and as Melba already pointed it's not intuitive at all. When you're looking in help file for example at _GUIScrollBars_Init() where you have two parameters and the only details are max size of horizontal/vertical scrollbar then you may can ignore such a description that is not helpful anyway since you don't have a clue what this size really is. All I want to say is that a hint would make things clear. Anyway I figured it out thanks to Melba's hint. Link to comment Share on other sites More sharing options...
Andreik Posted September 2, 2020 Author Share Posted September 2, 2020 @Melba23 I have one more question regarding scroll bars. What's the proper way to set scroll bar position to a certain position? Based on your UDF I wrote this function to create a scroll bar for a window to fit all controls and then a function to scroll to a certain control but it's very tedious and the scrolling effect is awful. expandcollapse popup#include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> $iRandom = Random(8, 20, 1) $iScrollTo = Random(1, $iRandom, 1) $hMain = GUICreate("Main", 1000, 700) $cScroll = GUICtrlCreateLabel($iScrollTo, 10, 10, 200, 30, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) $cNumOfLabels = GUICtrlCreateLabel($iRandom, 10, 50, 200, 30, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) $hChild = GUICreate("", 500, 700, 250, 0, $WS_POPUP, $WS_EX_MDICHILD, $hMain) For $Index = 1 To $iRandom GUICtrlCreateLabel($Index, 10, ($Index - 1) * 480, 480, 480, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) Next GUISetState(@SW_SHOW, $hMain) GUISetState(@SW_SHOW, $hChild) GUIRegisterMsg($WM_VSCROLL, 'WM_VSCROLL') SetWindowScrollbar($hChild, $iRandom * 480) ScrollTo($iScrollTo) Do Sleep(10) Until GUIGetMsg() = -3 Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $iIndex = -1, $yChar = 16, $yPos Local $Min, $Max, $Page, $Pos, $TrackPos Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") $yPos = DllStructGetData($tSCROLLINFO, "nPos") $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") $Pos = $yPos Switch $nScrollCode Case $SB_TOP DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) Case $SB_LINEDOWN DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) Case $SB_PAGEUP DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGEDOWN DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) Case $SB_THUMBTRACK DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) EndSwitch DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos)) $yPos = $Pos EndIf Return 0 EndFunc Func SetWindowScrollbar($hWnd, $iHeight) Local $iCharHeight = 16 Local $aClient = WinGetClientSize($hWnd) If $iHeight <= $aClient[1] Then Return 0 _GUIScrollBars_ShowScrollBar($hWnd, $SB_HORZ, False) _GUIScrollBars_ShowScrollBar($hWnd, $SB_VERT, True) Local $iPage = Floor($aClient[1] / $iCharHeight) Local $iMaxSize = Floor($iHeight / $iCharHeight) _GUIScrollBars_SetScrollInfoMax($hWnd, $SB_VERT, $iMaxSize) _GUIScrollBars_SetScrollInfoPage($hWnd, $SB_VERT, $iPage) EndFunc Func ScrollTo($iVal) For $Index = 1 To ($iVal - 1) * 30 ; 480 / 16 = 30 _SendMessage($hChild, $WM_VSCROLL, $SB_LINEDOWN) Next EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 2, 2020 Moderators Share Posted September 2, 2020 Andreik, Try this; expandcollapse popup#include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> $iRandom = Random(8, 20, 1) $iScrollTo = Random(1, $iRandom, 1) $hMain = GUICreate("Main", 1000, 700) $cScroll = GUICtrlCreateLabel($iScrollTo, 10, 10, 200, 30, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) $cNumOfLabels = GUICtrlCreateLabel($iRandom, 10, 50, 200, 30, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) $hChild = GUICreate("", 500, 700, 250, 0, $WS_POPUP, $WS_EX_MDICHILD, $hMain) For $Index = 1 To $iRandom GUICtrlCreateLabel($Index, 10, ($Index - 1) * 480, 480, 480, BitOR($SS_SUNKEN, $SS_CENTERIMAGE, $SS_CENTER)) Next GUISetState(@SW_SHOW, $hMain) GUISetState(@SW_SHOW, $hChild) GUIRegisterMsg($WM_VSCROLL, 'WM_VSCROLL') ; Get the scrollbar max position $iMax = SetWindowScrollbar($hChild, $iRandom * 480) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; Calculate the required position ScrollTo(($iScrollTo - 1)/ $iRandom * $iMax) Do Sleep(10) Until GUIGetMsg() = -3 Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $iIndex = -1, $yChar = 16, $yPos Local $Min, $Max, $Page, $Pos, $TrackPos Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") $yPos = DllStructGetData($tSCROLLINFO, "nPos") $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") $Pos = $yPos Switch $nScrollCode Case $SB_TOP DllStructSetData($tSCROLLINFO, "nPos", $Min) Case $SB_BOTTOM DllStructSetData($tSCROLLINFO, "nPos", $Max) Case $SB_LINEUP DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) Case $SB_LINEDOWN DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) Case $SB_PAGEUP DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGEDOWN DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page) Case $SB_THUMBTRACK DllStructSetData($tSCROLLINFO, "nPos", $TrackPos) EndSwitch DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos)) $yPos = $Pos EndIf Return 0 EndFunc Func SetWindowScrollbar($hWnd, $iHeight) Local $iCharHeight = 16 Local $aClient = WinGetClientSize($hWnd) If $iHeight <= $aClient[1] Then Return 0 ; You need to activate the scrollbar!!!!!!! _GUIScrollBars_Init($hWnd) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< _GUIScrollBars_ShowScrollBar($hWnd, $SB_HORZ, False) _GUIScrollBars_ShowScrollBar($hWnd, $SB_VERT, True) Local $iPage = Floor($aClient[1] / $iCharHeight) Local $iMaxSize = Floor($iHeight / $iCharHeight) _GUIScrollBars_SetScrollInfoMax($hWnd, $SB_VERT, $iMaxSize) _GUIScrollBars_SetScrollInfoPage($hWnd, $SB_VERT, $iPage) ; Return the max size Return $iMaxSize ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc Func ScrollTo($iVal) ; And move the scrollbar _GUIScrollBars_SetScrollInfoPos($hChild, $SB_VERT, $iVal) ; <<<<<<<<<<<<<<<<<<<< EndFunc M23 Andreik 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Andreik Posted September 2, 2020 Author Share Posted September 2, 2020 Thanks, it works like a charm. I feel so dumb I forgot to initialize the scrollbar and I was wondering why _GUIScrollBars_SetScrollInfoPos() it's not working properly. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now