| 1 | ;; Something_Wrong_Between_Docking_and_GUI_ScrollBars.au3
|
|---|
| 2 | ;; Notes:
|
|---|
| 3 | ;; 1. This script is based upon the example in the AutoIt help
|
|---|
| 4 | ;; file for UDF function _GUIScrollBars_Init. Similar effects
|
|---|
| 5 | ;; can be observed using that example, although the child GUIs
|
|---|
| 6 | ;; seem to behave correctly.
|
|---|
| 7 | ;;
|
|---|
| 8 | ;; 2. Melba23's UDF, "Scrollbars Made Easy" also exhibits issue #1, but not #2.
|
|---|
| 9 | ;; http://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-new-version-9-aug-14/
|
|---|
| 10 |
|
|---|
| 11 | #include <GUIConstantsEx.au3>
|
|---|
| 12 | #include <GuiScrollBars.au3>
|
|---|
| 13 | #include <StructureConstants.au3>
|
|---|
| 14 | #include <WindowsConstants.au3>
|
|---|
| 15 |
|
|---|
| 16 | Example()
|
|---|
| 17 |
|
|---|
| 18 | Func Example()
|
|---|
| 19 | Local $hGUIMsg, $hGUI
|
|---|
| 20 |
|
|---|
| 21 | Local $iMaxHScroll = 425
|
|---|
| 22 | Local $iMaxVScroll = 325
|
|---|
| 23 |
|
|---|
| 24 | Local $iGUIHeight = 300
|
|---|
| 25 |
|
|---|
| 26 | $hGUI = GUICreate("2 ScrollBar Issues", 400, $iGUIHeight, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
|
|---|
| 27 | GUISetBkColor(0x88AABB)
|
|---|
| 28 |
|
|---|
| 29 | $b0 = GUICtrlCreateButton("0,0 x 100,40", 0, 0, 100, 40)
|
|---|
| 30 | GUICtrlSetResizing(-1, $GUI_DOCKALL)
|
|---|
| 31 |
|
|---|
| 32 | $b1 = GUICtrlCreateButton("Show Issue 1", 120, 0, 100, 40)
|
|---|
| 33 | GUICtrlSetResizing(-1, $GUI_DOCKALL)
|
|---|
| 34 |
|
|---|
| 35 | $b2 = GUICtrlCreateButton("Show Issue 2", 230, 0, 100, 40)
|
|---|
| 36 | GUICtrlSetResizing(-1, $GUI_DOCKALL)
|
|---|
| 37 |
|
|---|
| 38 | Local $sIssue1 = _
|
|---|
| 39 | " 1. Start the script." & @LF & _
|
|---|
| 40 | " 2. Note the location of the leftmost button is 0,0." & @LF & _
|
|---|
| 41 | " 3. Drag the horizontal scroll bar a little to the right." & @LF & _
|
|---|
| 42 | " The left button scrolls off the left side as it should." & @LF & _
|
|---|
| 43 | " So far, all is well." & @LF & _
|
|---|
| 44 | " 4. Drag the bottom of the GUI up or down, noting that the button" & @LF & _
|
|---|
| 45 | " moves completely into view (it should NOT do that!)." & @LF & _
|
|---|
| 46 | " This note moves too, just like the button." & @LF & _
|
|---|
| 47 | " 5. Drag the horizontal scroll bar all the way to the left." & @LF & _
|
|---|
| 48 | " 6. Note the location of the leftmost button and this note. " & @LF & _
|
|---|
| 49 | " They're NOT where they should be. The leftmost button" & @LF & _
|
|---|
| 50 | " should be at 0,0. Click that button to get its position." & @LF & _
|
|---|
| 51 | " 7. Drag the bottom of the GUI up or down, " & @LF & _
|
|---|
| 52 | " and the button repositions correctly." & @LF & _
|
|---|
| 53 | " 8. The same thing happens with the vertical scroll bar," & @LF & _
|
|---|
| 54 | " and/or combinations of dragging the GUI borders." & @LF & _
|
|---|
| 55 | " 9. This is NOT an issue if the window cannot be resized." & @LF & _
|
|---|
| 56 | "10. This same issue occurs in Melba23's 'Scrollbars Made Easy' UDF."
|
|---|
| 57 |
|
|---|
| 58 | Local $sIssue2 = _
|
|---|
| 59 | " 1. The height of the vertical scroll bar thumb, and its maximum " & @LF & _
|
|---|
| 60 | " range are incorrect. Since the height of the GUI is " & $iGUIHeight & ", and" & @LF & _
|
|---|
| 61 | " function _GUIScrollBars_Init specifies the maximum vertical " & @LF & _
|
|---|
| 62 | " value as " & $iMaxVScroll & ", the height of the thumb should be greater" & @LF & _
|
|---|
| 63 | " then it is, and the movement should be very little, much like" & @LF & _
|
|---|
| 64 | " the horizontal scroll bar."
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | ;; Start with Issue 1 displayed in the label
|
|---|
| 68 | $l1 = GUICtrlCreateLabel($sIssue1, 60, 45, 400, 240)
|
|---|
| 69 | GUICtrlSetResizing(-1, $GUI_DOCKALL)
|
|---|
| 70 | GUICtrlSetBkColor(-1, 0xffffff)
|
|---|
| 71 |
|
|---|
| 72 | GUIRegisterMsg($WM_SIZE, "WM_SIZE")
|
|---|
| 73 | GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")
|
|---|
| 74 | GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
|
|---|
| 75 |
|
|---|
| 76 | GUISetState(@SW_SHOW)
|
|---|
| 77 |
|
|---|
| 78 | ;; _GUIScrollBars_Init($hGUI)
|
|---|
| 79 | _GUIScrollBars_Init($hGUI, $iMaxHScroll, $iMaxVScroll)
|
|---|
| 80 |
|
|---|
| 81 | While 1
|
|---|
| 82 | $hGUIMsg = GUIGetMsg()
|
|---|
| 83 |
|
|---|
| 84 | Switch $hGUIMsg
|
|---|
| 85 | Case $GUI_EVENT_CLOSE
|
|---|
| 86 | ExitLoop
|
|---|
| 87 |
|
|---|
| 88 | Case $b0
|
|---|
| 89 | Local $a1 = ControlGetPos("2 ScrollBar Issues", "", $b0)
|
|---|
| 90 | MsgBox(4096, "Button Position", "The position of this button is " & $a1[0] & "," & $a1[1])
|
|---|
| 91 |
|
|---|
| 92 | Case $b1
|
|---|
| 93 | ;; Display issue 1
|
|---|
| 94 | GUICtrlSetData($l1, $sIssue1)
|
|---|
| 95 |
|
|---|
| 96 | Case $b2
|
|---|
| 97 | ;; Display issue 2
|
|---|
| 98 | GUICtrlSetData($l1, $sIssue2)
|
|---|
| 99 |
|
|---|
| 100 | EndSwitch
|
|---|
| 101 | WEnd
|
|---|
| 102 |
|
|---|
| 103 | Exit
|
|---|
| 104 | EndFunc ;==>Example
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
|
|---|
| 108 | #forceref $iMsg, $wParam
|
|---|
| 109 | Local $iIndex = -1, $iCharY, $iCharX, $iClientMaxX, $iClientX, $iClientY, $iMax
|
|---|
| 110 | For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
|
|---|
| 111 | If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
|
|---|
| 112 | $iIndex = $x
|
|---|
| 113 | $iClientMaxX = $__g_aSB_WindowInfo[$iIndex][1]
|
|---|
| 114 | $iCharX = $__g_aSB_WindowInfo[$iIndex][2]
|
|---|
| 115 | $iCharY = $__g_aSB_WindowInfo[$iIndex][3]
|
|---|
| 116 | $iMax = $__g_aSB_WindowInfo[$iIndex][7]
|
|---|
| 117 | ExitLoop
|
|---|
| 118 | EndIf
|
|---|
| 119 | Next
|
|---|
| 120 | If $iIndex = -1 Then Return 0
|
|---|
| 121 |
|
|---|
| 122 | Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO)
|
|---|
| 123 |
|
|---|
| 124 | ; Retrieve the dimensions of the client area.
|
|---|
| 125 | $iClientX = BitAND($lParam, 0x0000FFFF)
|
|---|
| 126 | $iClientY = BitShift($lParam, 16)
|
|---|
| 127 | $__g_aSB_WindowInfo[$iIndex][4] = $iClientX
|
|---|
| 128 | $__g_aSB_WindowInfo[$iIndex][5] = $iClientY
|
|---|
| 129 |
|
|---|
| 130 | ; Set the vertical scrolling range and page size
|
|---|
| 131 | DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
|
|---|
| 132 | DllStructSetData($tSCROLLINFO, "nMin", 0)
|
|---|
| 133 | DllStructSetData($tSCROLLINFO, "nMax", $iMax)
|
|---|
| 134 | DllStructSetData($tSCROLLINFO, "nPage", $iClientY / $iCharY)
|
|---|
| 135 | _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
|
|---|
| 136 |
|
|---|
| 137 | ; Set the horizontal scrolling range and page size
|
|---|
| 138 | DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE))
|
|---|
| 139 | DllStructSetData($tSCROLLINFO, "nMin", 0)
|
|---|
| 140 | DllStructSetData($tSCROLLINFO, "nMax", 2 + $iClientMaxX / $iCharX)
|
|---|
| 141 | DllStructSetData($tSCROLLINFO, "nPage", $iClientX / $iCharX)
|
|---|
| 142 | _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
|
|---|
| 143 |
|
|---|
| 144 | Return $GUI_RUNDEFMSG
|
|---|
| 145 | EndFunc ;==>WM_SIZE
|
|---|
| 146 |
|
|---|
| 147 | Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)
|
|---|
| 148 | #forceref $iMsg, $lParam
|
|---|
| 149 | Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
|
|---|
| 150 |
|
|---|
| 151 | Local $iIndex = -1, $iCharX, $iPosX
|
|---|
| 152 | Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
|
|---|
| 153 |
|
|---|
| 154 | For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
|
|---|
| 155 | If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
|
|---|
| 156 | $iIndex = $x
|
|---|
| 157 | $iCharX = $__g_aSB_WindowInfo[$iIndex][2]
|
|---|
| 158 | ExitLoop
|
|---|
| 159 | EndIf
|
|---|
| 160 | Next
|
|---|
| 161 | If $iIndex = -1 Then Return 0
|
|---|
| 162 |
|
|---|
| 163 | ; ; Get all the horizontal scroll bar information
|
|---|
| 164 | Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
|
|---|
| 165 | $iMin = DllStructGetData($tSCROLLINFO, "nMin")
|
|---|
| 166 | $iMax = DllStructGetData($tSCROLLINFO, "nMax")
|
|---|
| 167 | $iPage = DllStructGetData($tSCROLLINFO, "nPage")
|
|---|
| 168 | ; Save the position for comparison later on
|
|---|
| 169 | $iPosX = DllStructGetData($tSCROLLINFO, "nPos")
|
|---|
| 170 | $iPos = $iPosX
|
|---|
| 171 | $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
|
|---|
| 172 | #forceref $iMin, $iMax
|
|---|
| 173 | Switch $iScrollCode
|
|---|
| 174 |
|
|---|
| 175 | Case $SB_LINELEFT ; user clicked left arrow
|
|---|
| 176 | DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)
|
|---|
| 177 |
|
|---|
| 178 | Case $SB_LINERIGHT ; user clicked right arrow
|
|---|
| 179 | DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)
|
|---|
| 180 |
|
|---|
| 181 | Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box
|
|---|
| 182 | DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage)
|
|---|
| 183 |
|
|---|
| 184 | Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box
|
|---|
| 185 | DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage)
|
|---|
| 186 |
|
|---|
| 187 | Case $SB_THUMBTRACK ; user dragged the scroll box
|
|---|
| 188 | DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos)
|
|---|
| 189 | EndSwitch
|
|---|
| 190 |
|
|---|
| 191 | ; // Set the position and then retrieve it. Due to adjustments
|
|---|
| 192 | ; // by Windows it may not be the same as the value set.
|
|---|
| 193 |
|
|---|
| 194 | DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
|
|---|
| 195 | _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
|
|---|
| 196 | _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
|
|---|
| 197 | ;// If the position has changed, scroll the window and update it
|
|---|
| 198 | $iPos = DllStructGetData($tSCROLLINFO, "nPos")
|
|---|
| 199 | If ($iPos <> $iPosX) Then _GUIScrollBars_ScrollWindow($hWnd, $iCharX * ($iPosX - $iPos), 0)
|
|---|
| 200 | Return $GUI_RUNDEFMSG
|
|---|
| 201 | EndFunc ;==>WM_HSCROLL
|
|---|
| 202 |
|
|---|
| 203 | Func WM_VSCROLL($hWnd, $iMsg, $wParam, $lParam)
|
|---|
| 204 | #forceref $iMsg, $wParam, $lParam
|
|---|
| 205 | Local $iScrollCode = BitAND($wParam, 0x0000FFFF)
|
|---|
| 206 | Local $iIndex = -1, $iCharY, $iPosY
|
|---|
| 207 | Local $iMin, $iMax, $iPage, $iPos, $iTrackPos
|
|---|
| 208 |
|
|---|
| 209 | For $x = 0 To UBound($__g_aSB_WindowInfo) - 1
|
|---|
| 210 | If $__g_aSB_WindowInfo[$x][0] = $hWnd Then
|
|---|
| 211 | $iIndex = $x
|
|---|
| 212 | $iCharY = $__g_aSB_WindowInfo[$iIndex][3]
|
|---|
| 213 | ExitLoop
|
|---|
| 214 | EndIf
|
|---|
| 215 | Next
|
|---|
| 216 | If $iIndex = -1 Then Return 0
|
|---|
| 217 |
|
|---|
| 218 | ; Get all the vertial scroll bar information
|
|---|
| 219 | Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
|
|---|
| 220 | $iMin = DllStructGetData($tSCROLLINFO, "nMin")
|
|---|
| 221 | $iMax = DllStructGetData($tSCROLLINFO, "nMax")
|
|---|
| 222 | $iPage = DllStructGetData($tSCROLLINFO, "nPage")
|
|---|
| 223 | ; Save the position for comparison later on
|
|---|
| 224 | $iPosY = DllStructGetData($tSCROLLINFO, "nPos")
|
|---|
| 225 | $iPos = $iPosY
|
|---|
| 226 | $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
|
|---|
| 227 |
|
|---|
| 228 | Switch $iScrollCode
|
|---|
| 229 | Case $SB_TOP ; user clicked the HOME keyboard key
|
|---|
| 230 | DllStructSetData($tSCROLLINFO, "nPos", $iMin)
|
|---|
| 231 |
|
|---|
| 232 | Case $SB_BOTTOM ; user clicked the END keyboard key
|
|---|
| 233 | DllStructSetData($tSCROLLINFO, "nPos", $iMax)
|
|---|
| 234 |
|
|---|
| 235 | Case $SB_LINEUP ; user clicked the top arrow
|
|---|
| 236 | DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1)
|
|---|
| 237 |
|
|---|
| 238 | Case $SB_LINEDOWN ; user clicked the bottom arrow
|
|---|
| 239 | DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1)
|
|---|
| 240 |
|
|---|
| 241 | Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
|
|---|
| 242 | DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage)
|
|---|
| 243 |
|
|---|
| 244 | Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
|
|---|
| 245 | DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage)
|
|---|
| 246 |
|
|---|
| 247 | Case $SB_THUMBTRACK ; user dragged the scroll box
|
|---|
| 248 | DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos)
|
|---|
| 249 | EndSwitch
|
|---|
| 250 |
|
|---|
| 251 | ; // Set the position and then retrieve it. Due to adjustments
|
|---|
| 252 | ; // by Windows it may not be the same as the value set.
|
|---|
| 253 |
|
|---|
| 254 | DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
|
|---|
| 255 | _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
|
|---|
| 256 | _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
|
|---|
| 257 | ;// If the position has changed, scroll the window and update it
|
|---|
| 258 | $iPos = DllStructGetData($tSCROLLINFO, "nPos")
|
|---|
| 259 |
|
|---|
| 260 | If ($iPos <> $iPosY) Then
|
|---|
| 261 | _GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos))
|
|---|
| 262 | $iPosY = $iPos
|
|---|
| 263 | EndIf
|
|---|
| 264 |
|
|---|
| 265 | Return $GUI_RUNDEFMSG
|
|---|
| 266 | EndFunc ;==>WM_VSCROLL
|
|---|