Tvern Posted March 27, 2009 Share Posted March 27, 2009 (edited) Hi there. I am making the initial layout of a GUI for a database program I am writing, but I ran into a problem. The goal is the following: * Having a menu on the left with at least a vertical scroll bar. * Having a window on the right with 2 scroll bars. * Being able to drag the divider between the 2 to resize them. The following script does all the above, but the $SW_SIZEBOX style forces the left menu to have a border. It makes allot of sense, as you need something to drag, but in my case I only need to resize horizontally, so I only need something to grab onto on the right side. so my questions are: Is there a way to only enable horizontal resizing on a child gui? and Is there a way to modify the border of a resizable child gui, so it doesn't stand out as much? Ofcoarse suggestions for better ways to do what I want are welcome too. The code I have so far: expandcollapse popupOpt("MustDeclareVars",1) #include <GuiConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> #Include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> Local $ParentGUI, $LeftMenuGUI, $RightMenuGUI Local $StatusBar Local $LeftMenuWidth = 200, $Size, $aParts[3] = [75, 150, -1], $SCROLL_AMOUNTS[1][3] Local $flag, $style $SCROLL_AMOUNTS[0][0] = 1 $flag = MsgBox(4,"How do you want to run the script?","'Yes' for desired look," & @CRLF & "'No' for desired functionality") If $flag = 6 Then $style = $WS_CHILD Else $style = BitOR($WS_SIZEBOX,$WS_CHILD) EndIf $ParentGUI = GUICreate("Example GUI",400,400,-1,-1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN)) GUICtrlCreateMenu("&File") $StatusBar = _GUICtrlStatusBar_Create($ParentGUI) _GUICtrlStatusBar_SetParts($StatusBar, $aParts) $Size = WinGetClientSize($ParentGUI) $LeftMenuGUI = GUICreate("",200,$Size[0]-30,10,10, $style,Default, $ParentGUI) GUISetState() $RightMenuGUI = GUICreate("",$Size[1]-220,$Size[0]-30,220,10, $WS_CHILD, Default, $ParentGUI) GUISetState() GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") GUIRegisterMsg($WM_SIZE, 'WM_SIZE') WM_SIZE($ParentGUI, 5, 0x000000,0x000000) GUISetState(@SW_SHOW,$ParentGUI) While GUIGetMsg() <> -3 WEnd Func _exit() Exit EndFunc #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.13.3 (beta) Author: Kip Script Function: Template AutoIt script. Functions: Scrollbar_Create($hWnd, $iBar, $iMax) Scrollbar_Scroll($hWnd, $iBar, $iPos) Scrollbar_GetPos($hWnd, $iBar) Scrollbar_Step($iStep, $hWnd=0, $iBar=0) #ce func Scrollbar_Create($hWnd, $iBar, $iMax) Local $Size = WinGetClientSize($hWnd) If $iBar = $SB_HORZ Then $Size = $Size[0] ElseIf $iBar = $SB_VERT Then $Size = $Size[1] Else Return 0 EndIf ReDim $SCROLL_AMOUNTS[UBound($SCROLL_AMOUNTS)+1][3] $SCROLL_AMOUNTS[UBound($SCROLL_AMOUNTS)-1][0] = $hWnd $SCROLL_AMOUNTS[UBound($SCROLL_AMOUNTS)-1][1] = $iBar $SCROLL_AMOUNTS[UBound($SCROLL_AMOUNTS)-1][2] = $SCROLL_AMOUNTS[0][0] _GUIScrollBars_EnableScrollBar($hWnd, $iBar) _GUIScrollBars_SetScrollRange($hWnd, $iBar, 0,$iMax-1) _GUIScrollBars_SetScrollInfoPage($hWnd, $iBar, $Size) Return $iMax EndFunc Func Scrollbar_GetPos($hWnd, $iBar) Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $iBar) Return DllStructGetData($tSCROLLINFO, "nPos") EndFunc Func Scrollbar_Scroll($hWnd, $iBar, $iPos) Local $iCurrentPos, $iRound Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $iBar) $iCurrentPos = DllStructGetData($tSCROLLINFO, "nPos") DllStructSetData($tSCROLLINFO, "nPos", $iPos) DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $iBar, $tSCROLLINFO) If $iBar = $SB_VERT Then $iRound = 0 for $i = 1 to UBound($SCROLL_AMOUNTS)-1 If $SCROLL_AMOUNTS[$i][0] = $hWnd And $SCROLL_AMOUNTS[$i][1] = $SB_VERT Then $iRound = $SCROLL_AMOUNTS[$i][2] EndIf Next If Not $iRound Then Return 0 _GUIScrollBars_ScrollWindow($hWnd, 0, Round(($iCurrentPos-$iPos)/$iRound)*$iRound) ElseIf $iBar = $SB_HORZ Then $iRound = 0 for $i = 1 to UBound($SCROLL_AMOUNTS)-1 If $SCROLL_AMOUNTS[$i][0] = $hWnd And $SCROLL_AMOUNTS[$i][1] = $SB_HORZ Then $iRound = $SCROLL_AMOUNTS[$i][2] EndIf Next If Not $iRound Then Return 0 _GUIScrollBars_ScrollWindow($hWnd, Round(($iCurrentPos-$iPos)/$iRound)*$iRound, 0) Else Return 0 EndIf Return 1 EndFunc Func Scrollbar_Step($iStep, $hWnd=0, $iBar=0) Local $iID If not $hWnd or Not $iBar Then $SCROLL_AMOUNTS[0][0] = $iStep Return 1 EndIf $iID = 0 for $i = 1 to UBound($SCROLL_AMOUNTS)-1 If $SCROLL_AMOUNTS[$i][0] = $hWnd And $SCROLL_AMOUNTS[$i][1] = $iBar Then $iID = $i ExitLoop EndIf Next If Not $iID Then Return 0 $SCROLL_AMOUNTS[$iID][2] = $iStep Return 1 EndFunc Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax, $Bottom, $Right ;---------------------------------------------- If $hWnd = $ParentGUI Then _GUICtrlStatusBar_Resize($StatusBar) $Bottom = ControlGetPos("","",$StatusBar) $Right = WinGetClientSize($ParentGUI) WinMove($LeftMenuGUI,"",0,0,$LeftMenuWidth,$Bottom[1]) Scrollbar_Create($LeftMenuGUI, $SB_HORZ, 300) Scrollbar_Create($LeftMenuGUI, $SB_VERT, 600) WinMove($RightMenuGUI,"",$LeftMenuWidth,0,$Right[0]-$LeftMenuWidth,$Bottom[1]) Scrollbar_Create($RightMenuGUI, $SB_HORZ, 300) Scrollbar_Create($RightMenuGUI, $SB_VERT, 600) ElseIf $hWnd = $LeftMenuGUI Then $LeftMenuWidth = WinGetPos($LeftMenuGUI) $LeftMenuWidth = $LeftMenuWidth[2] $Bottom = ControlGetPos("","",$StatusBar) $Right = WinGetClientSize($ParentGUI) WinMove($LeftMenuGUI,"",0,0,Default,$Bottom[1]) Scrollbar_Create($LeftMenuGUI, $SB_HORZ, 300) Scrollbar_Create($LeftMenuGUI, $SB_VERT, 600) WinMove($RightMenuGUI,"",$LeftMenuWidth,0,$Right[0]-$LeftMenuWidth,$Bottom[1]) Scrollbar_Create($RightMenuGUI, $SB_HORZ, 300) Scrollbar_Create($RightMenuGUI, $SB_VERT, 600) EndIf ;----------------------------------------- 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_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, $iRound ; 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") $iRound = 0 for $i = 1 to UBound($SCROLL_AMOUNTS)-1 If $SCROLL_AMOUNTS[$i][0] = $hWnd And $SCROLL_AMOUNTS[$i][1] = $SB_VERT Then $iRound = $SCROLL_AMOUNTS[$i][2] EndIf Next if Not $iRound Then Return $GUI_RUNDEFMSG 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 - $iRound) Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + $iRound) 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", Round($TrackPos/$iRound)*$iRound) 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, $yPos - $Pos) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_VSCROLL Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $yChar, $yPos Local $Min, $Max, $Page, $Pos, $TrackPos, $iRound = 0 ; Get all the vertial 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 $yPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $yPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") $iRound = 0 for $i = 1 to UBound($SCROLL_AMOUNTS)-1 If $SCROLL_AMOUNTS[$i][0] = $hWnd And $SCROLL_AMOUNTS[$i][1] = $SB_HORZ Then $iRound = $SCROLL_AMOUNTS[$i][2] EndIf Next if Not $iRound Then Return $GUI_RUNDEFMSG 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 - $iRound) Case $SB_LINEDOWN ; user clicked the bottom arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + $iRound) 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", Round($TrackPos/$iRound)*$iRound) 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 <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, $yPos - $Pos, 0) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL Thanks in advance Tom Edited March 30, 2009 by Tvern Link to comment Share on other sites More sharing options...
martin Posted March 29, 2009 Share Posted March 29, 2009 Maybe Kip's splitter udf would help. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Tvern Posted March 30, 2009 Author Share Posted March 30, 2009 Maybe Kip's splitter udf would help.Looks nice I'll give it a go.Thnx for the reply. 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