#include-once ; #INDEX# ============================================================================================================ ; Title .........: GUIExtender_Ex ; AutoIt Version : v3.3 or higher ; Language ......: English ; Description ...: Extends and retracts user-defined sections of a GUI either vertically or horizontally while ; GUI remains same size with scrollbars giveing access to visible sections ; Remarks .......: ; Note ..........: ; Author(s) .....: Melba23 ; ==================================================================================================================== #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7 ; #INCLUDES# ========================================================================================================= #include #include #include #include "GuiExtender_Test.au3" ; #GLOBAL VARIABLES# ================================================================================================= Global $iGUIExt_GUI_ScrollPos = 0 ; #CURRENT# ========================================================================================================== ; _GUIExtender_Ex_ScrollInit: Initialise scrollbars in a GUI_Extender GUI initialised with $iFixed = 3 ; _GUIExtender_Ex_EventMonitor: Used in GUIGetMsg loops to detect events requiring UDF action ; ==================================================================================================================== ; #INTERNAL_USE_ONLY#================================================================================================= ; __GUIExtender_ScrollSize: Calculate required height for scrollbars ; __GUIExtender_Ex_WM_VSCROLL_Handler: Windows handler for vertical scrollbars ; __GUIExtender_Ex_WM_HSCROLL_Handler: Windows handler for horizontal scrollbars ; ==================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Ex_ScrollInit ; Description ...: Initialise scrollbars in a GUI_Extender GUI initialised with $iFixed = 3 ; Syntax.........: _GUIExtender_Ex_ScrollInit($hWnd, $iHorz, $iVert, $bRegister = True) ; Parameters ....: $hWnd - Handle of GUI containing the section ; $iHorz - GUI width ; $iVert - GUI height ; $bRegister - (Default = True) Register correct scrollbar handle ; Requirement(s).: v3.3 + ; Return values .: Success: Returns 1 ; Failure: Returns 0 and sets @error as follows: ; 1 = GUI not initialised by GUIExtender ; 2 = GUI not initialised with $iFixed = 3 (with scrollbars) ; Author ........: Melba23 ; Remarks .......: The function initialises the scrollbars for a GUIExtender GUI initialised with $iFixed = 3 ; Example........: Yes ; ==================================================================================================================== Func _GUIExtender_Ex_ScrollInit($hWnd, $iHorz, $iVert, $bRegister = True) Local $aActive_Section_Data ; Get copy of active GUI section data array For $iGUI_Index = 1 To $aGUIExt_GUI_Data[0][0] If $aGUIExt_GUI_Data[$iGUI_Index][0] = $hWnd Then $aActive_Section_Data = $aGUIExt_GUI_Data[$iGUI_Index][1] ExitLoop EndIf Next If Not IsArray($aActive_Section_Data) Then Return SetError(1, 0, 0) EndIf ; Check if GUI initialised for scrollbars If $aActive_Section_Data[0][4] <> 3 Then Return SetError(2, 0, 0) EndIf ; Check orientation Local $iBar = (($aActive_Section_Data[0][1] = 1) ? ($SB_HORZ) : ($SB_VERT)) Switch $iBar Case 0 If $bRegister Then GUIRegisterMsg($WM_HSCROLL, "__GUIExtender_Ex_WM_HSCROLL_Handler") EndIf Case 1 If $bRegister Then GUIRegisterMsg($WM_VSCROLL, "__GUIExtender_Ex_WM_VSCROLL_Handler") EndIf EndSwitch _GUIScrollBars_Init($hWnd) _GUIScrollBars_ShowScrollBar($hWnd, $iBar, False) __GUIExtender_Restore() Local $aRet = _GUIScrollbars_Size(0, __GUIExtender_ScrollSize($hWnd), $iHorz, $iVert) If Not @error Then _GUIScrollBars_ShowScrollBar($hWnd, $iBar, True) _GUIScrollBars_SetScrollInfoPage($hWnd, $iBar, $aRet[2]) _GUIScrollBars_SetScrollInfoMax($hWnd, $iBar, $aRet[3]) EndIf Return 1 EndFunc ;==>_GUIExtender_Ex_ScrollInit ; #FUNCTION# ========================================================================================================= ; Name...........: _GUIExtender_Ex_EventMonitor ; Description ...: Used in GUIGetMsg loops to detect events requiring UDF action whenusing scrollbars ; Syntax.........: _GUIExtender_Ex_EventMonitor($hWnd, $iMsg) ; Parameters ....: $hWnd - Handle of GUI containing the section ; $iMsg - Return from GUIGetMsg ; Requirement(s).: v3.3 + ; Return values .: Success: Returns: ; 0 - No section actioned ; 1 - Section(s) actioned - @extended set to index of actioned section or 0 for all sections ; Failure: Sets @error as follows: ; 1 = GUI not initialised ; Author ........: Melba23 ; Remarks .......: The function uses the return from GUIGetMsg to determine if a section action control was clicked ; When using multiple GUIs, use "advanced" parameter with GUIGetMsg and pass the returned values to this function ; Also checks for $GUI_EVENT_RESTORE and calls internal function to correctly display GUI ; and adjusts scrollbars to match size of expanded sections ; Example........: Yes ; ==================================================================================================================== Func _GUIExtender_Ex_EventMonitor($hWnd, $iMsg) Local $aActive_Section_Data ; Get copy of active GUI section data array For $iGUI_Index = 1 To $aGUIExt_GUI_Data[0][0] If $aGUIExt_GUI_Data[$iGUI_Index][0] = $hWnd Then $aActive_Section_Data = $aGUIExt_GUI_Data[$iGUI_Index][1] ExitLoop EndIf Next If Not IsArray($aActive_Section_Data) Then Return SetError(1, 0, 0) EndIf ; Check orientation Local $iBar = (($aActive_Section_Data[0][1] = 1) ? ($SB_HORZ) : ($SB_VERT)) ; Default return values Local $iRet = 0, $iLastActioned = 0 Switch $iMsg Case -5 ; $GUI_EVENT_RESTORE _GUIScrollBars_SetScrollInfoPos($hWnd, $iBar, 0) __GUIExtender_Restore() _GUIScrollBars_SetScrollInfoPos($hWnd, $iBar, $iGUIExt_GUI_ScrollPos) Case -4 ; $GUI_EVENT_MINIMIZE $iGUIExt_GUI_ScrollPos = _GUIScrollBars_GetScrollInfoPos($hWnd, $iBar) Case Else ; Check if "all" action button clicked If $iMsg = $aActive_Section_Data[0][5] Then ; Action all sections - required state determined later _GUIExtender_Section_Action($hWnd, 0) $iRet = 1 Else ; Check if a section action control has been clicked For $i = 1 To $aActive_Section_Data[0][0] ; If action button clicked If $iMsg = $aActive_Section_Data[$i][5] Then ; Toggle section state _GUIExtender_Section_Action($hWnd, $i, 9) $iRet = 1 $iLastActioned = $i ExitLoop EndIf Next EndIf EndSwitch ; Adjust scrollbar if required If $iRet Then Local $iScrollPos = _GUIScrollBars_GetScrollInfoPos($hWnd, $iBar) _GUIScrollBars_SetScrollInfoPos($hWnd, $iBar, 0) Local $aRet = _GUIScrollbars_Size(0, __GUIExtender_ScrollSize($hWnd) + 17, 600, 500) If @error Then _GUIScrollBars_ShowScrollBar($hWnd, $iBar, False) __GUIExtender_Restore() Else _GUIScrollBars_ShowScrollBar($hWnd, $iBar, True) _GUIScrollBars_SetScrollInfoPage($hWnd, $iBar, $aRet[2]) _GUIScrollBars_SetScrollInfoMax($hWnd, $iBar, $aRet[3]) __GUIExtender_Restore() _GUIScrollBars_SetScrollInfoPos($hWnd, $iBar, $iScrollPos) EndIf EndIf Return SetError(0, $iLastActioned, $iRet) EndFunc ;==>_GUIExtender_Ex_EventMonitor ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __GUIExtender_ScrollSize ; Description ...: Calculate required height for scrollbars ; Author ........: Melba23 ; Modified.......: ; Remarks .......: ;===================================================================================================================== Func __GUIExtender_ScrollSize($hWnd) ; Get copy of active GUI section data array For $iGUI_Index = 1 To $aGUIExt_GUI_Data[0][0] If $aGUIExt_GUI_Data[$iGUI_Index][0] = $hWnd Then Local $aActive_Section_Data = $aGUIExt_GUI_Data[$iGUI_Index][1] ExitLoop EndIf Next If $iGUI_Index > $aGUIExt_GUI_Data[0][0] Then Return SetError(1, 0, 0) EndIf Return __GUIExtender_CurrentSize($aActive_Section_Data) EndFunc ;==>__GUIExtender_ScrollSize ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __GUIExtender_Ex_WM_VSCROLL_Handler ; Description ...: Windows handler for vertical scrollbars ; Author ........: Help file ; Modified.......: ; Remarks .......: ;===================================================================================================================== Func __GUIExtender_Ex_WM_VSCROLL_Handler($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam, $lParam Local $iScrollCode = BitAND($wParam, 0x0000FFFF) Local $iIndex = -1, $iCharY, $iPosY Local $iMin, $iMax, $iPage, $iPos, $iTrackPos For $x = 0 To UBound($__g_aSB_WindowInfo) - 1 If $__g_aSB_WindowInfo[$x][0] = $hWnd Then $iIndex = $x $iCharY = $__g_aSB_WindowInfo[$iIndex][3] ExitLoop EndIf Next If $iIndex = -1 Then Return 0 ; Get all the vertial scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $iMin = DllStructGetData($tSCROLLINFO, "nMin") $iMax = DllStructGetData($tSCROLLINFO, "nMax") $iPage = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $iPosY = DllStructGetData($tSCROLLINFO, "nPos") $iPos = $iPosY $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") Switch $iScrollCode Case $SB_TOP ; user clicked the HOME keyboard key DllStructSetData($tSCROLLINFO, "nPos", $iMin) Case $SB_BOTTOM ; user clicked the END keyboard key DllStructSetData($tSCROLLINFO, "nPos", $iMax) Case $SB_LINEUP ; user clicked the top arrow DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1) Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1) Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage) Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos) EndSwitch DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) $iPos = DllStructGetData($tSCROLLINFO, "nPos") If ($iPos <> $iPosY) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $iCharY * ($iPosY - $iPos)) $iPosY = $iPos EndIf Return $GUI_RUNDEFMSG EndFunc ;==>__GUIExtender_Ex_WM_VSCROLL_Handler ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: __GUIExtender_Ex_WM_HSCROLL_Handler ; Description ...: Windows handler for horizontal scrollbars ; Author ........: Help file ; Modified.......: ; Remarks .......: ;===================================================================================================================== Func __GUIExtender_Ex_WM_HSCROLL_Handler($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $lParam Local $iScrollCode = BitAND($wParam, 0x0000FFFF) Local $iIndex = -1, $iCharX, $iPosX Local $iMin, $iMax, $iPage, $iPos, $iTrackPos For $x = 0 To UBound($__g_aSB_WindowInfo) - 1 If $__g_aSB_WindowInfo[$x][0] = $hWnd Then $iIndex = $x $iCharX = $__g_aSB_WindowInfo[$iIndex][2] ExitLoop EndIf Next If $iIndex = -1 Then Return 0 ; ; Get all the horizontal scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $iMin = DllStructGetData($tSCROLLINFO, "nMin") $iMax = DllStructGetData($tSCROLLINFO, "nMax") $iPage = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $iPosX = DllStructGetData($tSCROLLINFO, "nPos") $iPos = $iPosX $iTrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") #forceref $iMin, $iMax Switch $iScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO, "nPos", $iPos - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO, "nPos", $iPos + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iPos - $iPage) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iPos + $iPage) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO, "nPos", $iTrackPos) EndSwitch DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) $iPos = DllStructGetData($tSCROLLINFO, "nPos") If ($iPos <> $iPosX) Then _GUIScrollBars_ScrollWindow($hWnd, $iCharX * ($iPosX - $iPos), 0) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>__GUIExtender_Ex_WM_HSCROLL_Handler