Jump to content

Problem with control positions when resizing child gui

Recommended Posts

Hello there.

I'm quite new to AutoIt and have been lurking the forum for a while now. I've found most of the answers for my previous problems on the forum, but not for this one.

My script makes a GUI and a child GUI with Melba23's Scrollbars, then it adds Edit controls to the child GUI. The controls work fine at first, but when the scrollable area gets bigger and I try to resize the window, they flip out.

Code is pretty messy, but I hope you can work it out.

Thanks in advance.

#include <GuiEdit.au3>
#include <GUIScrollbars_Ex.au3>
#include "GUIScrollbars_Size.au3"
Global $parentGUI, $childGUI, $input, $sendButton, $input, $rezLabel
Global $W_input = 533, $H_input = 61, $L_input = 4, $T_input = 396 ;input size & pos
Global $W_sendButton = 81, $H_sendButton = 61, $L_sendButton = 540, $T_sendButton = 396 ;sendButton size & pos
Global $W_parentGUI = 625, $H_parentGUI = 460, $L_parentGUI = 207, $T_parentGUI = 194 ;parentGUI size & pos
Global $W_rezLabel = 507, $H_rezLabel = 362, $L_rezLabel = 15, $T_rezLabel = 25 ;rezLabel size and pos
Global $OS_X_childGUI = $L_parentGUI + 8, $OS_Y_childGUI = $T_parentGUI + 30
Global $W_childGUI = $W_rezLabel, $H_childGUI = $H_rezLabel, $L_childGUI = $L_rezLabel + $OS_X_childGUI, _
  $T_childGUI = $T_rezLabel + $OS_Y_childGUI ;childGUI size and pos (rezlabel)
Global $messages[200]
Global $minWidth = $W_parentGUI, $minHeight = $H_parentGUI
Global $lastMsgYPos = 25, $msgNo = 0, $allMsgH, $firstExpand = True
Global $msgSpace = 5
Global $iChildGUIHeight = $lastMsgYPos
Global $msgBkColor = 0xEFFFFF
Global $messageColumnOffSet = 108, $messageColumnSize = $W_childGUI - $messageColumnOffSet - 20
$W_input = $messageColumnSize
$L_input = $messageColumnOffSet + $L_rezLabel
$L_sendButton = $L_input + $W_input
Global $msgSpace = 5
Global $iChildGUIHeight = $lastMsgYPos
Global $msgBkColor = 0xEFFFFF
Func main()
While True
EndFunc   ;==>main
Func startup()
Opt("GUIOnEventMode", 1)
$parentGUI = GUICreate("parentGUI", $W_parentGUI, $H_parentGUI, $L_parentGUI, $T_parentGUI, _
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
$input = GUICtrlCreateEdit("some text", $L_rezLabel + $messageColumnOffSet, $T_input, $messageColumnSize, $H_input, _
$sendButton = GUICtrlCreateButton("send", $L_sendButton, $T_sendButton, $W_sendButton, $H_sendButton, BitOR($WS_GROUP, $WS_BORDER))
GUICtrlSetOnEvent($sendButton, "SpecialEvents")
$rezLabel = GUICtrlCreateLabel("", $L_rezLabel, $T_rezLabel, $W_rezLabel, $H_rezLabel)
ControlHide($parentGUI, "", $rezLabel)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
Dim $accelKeys[1][2] = [["{ENTER}", $sendButton]]
GUISetState(@SW_SHOW, $parentGUI)
$childGUI = GUICreate("child", $W_childGUI, $H_childGUI, $L_childGUI, $T_childGUI, $WS_POPUP, $WS_EX_TOOLWINDOW, $parentGUI)
GUISetState(@SW_SHOW, $childGUI)
$aRet = _GUIScrollbars_Size(0, $H_childGUI, $W_childGUI, $H_childGUI)
If @error Then
  ConsoleWrite($aRet & " - " & @error & " - " & @extended & @CRLF)
  For $i = 0 To 5
   ConsoleWrite($aRet[$i] & @CRLF)
GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")
_GUIScrollBars_ShowScrollBar($childGUI, $SB_HORZ, False)
_GUIScrollBars_SetScrollInfoPage($childGUI, $SB_VERT, $aRet[2])
_GUIScrollBars_SetScrollInfoMax($childGUI, $SB_VERT, $aRet[3])
_GUIScrollBars_SetScrollInfoPos($childGUI, $SB_VERT, _GUIScrollBars_GetScrollInfoMax($childGUI, $SB_VERT))
_GUIScrollBars_ShowScrollBar($childGUI, $SB_VERT, False)
GUIRegisterMsg($WM_MOVE, "_followParentGUI")
ControlFocus($parentGUI, "", $input)
EndFunc   ;==>createparentGUI

Func SpecialEvents()
Switch @GUI_CtrlId
  Case $sendButton
   _GUIScrollbars_Restore($childGUI, True, False) ; We only want the vertical scrollbar to show
   MsgBox(0, "", "")
EndFunc   ;==>SpecialEvents
Func _exit()
EndFunc   ;==>_exit
Func _addMessage()
Local $text, $lines = 1
Local $lastMsgXY
Local $H_childGUI
Local $currentMsgPos
$lines = _GUICtrlEdit_GetLineCount($input)
$text = _GUICtrlEdit_GetText($input)
GUICtrlSetData($input, "")
If $msgNo > 0 Then
  $lastMsgXY = ControlGetPos($childGUI, "", $messages[$msgNo - 1])
  $lastMsgYPos = $lastMsgXY[1] + $lastMsgXY[3] + $msgSpace
  $iChildGUIHeight += $lastMsgXY[3] + $msgSpace
$messages[$msgNo] = GUICtrlCreateEdit($text, $messageColumnOffSet, $lastMsgYPos, $messageColumnSize, $lines * 15, _
GUICtrlSetBkColor($messages[$msgNo], $msgBkColor)
GUICtrlSetResizing($messages[$msgNo], $GUI_DOCKALL)
$lastMsgXY = ControlGetPos($childGUI, "", $messages[$msgNo])
$currentMsgPos = $lastMsgXY[1] + $lastMsgXY[3] + $msgSpace
$H_chiGUI = WinGetPos($childGUI)
If $currentMsgPos >= $H_chiGUI[3] Then
  If $firstExpand Then
   _GUIScrollBars_ShowScrollBar($childGUI, $SB_VERT, True)
  $aRet = _GUIScrollbars_Size(0, $iChildGUIHeight + 25, $W_childGUI, $H_chiGUI[3])
  If IsArray($aRet) Then
   _GUIScrollBars_SetScrollInfoPage($childGUI, $SB_VERT, $aRet[2])
   _GUIScrollBars_SetScrollInfoMax($childGUI, $SB_VERT, $aRet[3])
  $firstExpand = False
_GUIScrollBars_SetScrollInfoPos($childGUI, $SB_VERT, _GUIScrollBars_GetScrollInfoMax($childGUI, $SB_VERT))
$msgNo += 1
EndFunc   ;==>_addMessage
Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
If $hWnd = $parentGUI Then
  Local $iWidth = _WinAPI_LoWord($lParam)
  Local $iHeight = _WinAPI_HiWord($lParam)
  Local $H_RL = $iHeight - ($H_parentGUI - $H_rezLabel)
  Local $L_RL = ($iWidth - ($W_parentGUI - $L_rezLabel))
  Local $T_CI = $iHeight - ($H_parentGUI - $T_input)
  Local $L_CT = $L_RL + $messageColumnOffSet
  Local $L_SB = $L_CT + $W_input + 4
  Local $T_SB = $iHeight - ($H_parentGUI - $T_sendButton)
  GUICtrlSetPos($input, $L_CT, $T_CI, $messageColumnSize, $H_input)
  GUICtrlSetPos($sendButton, $L_SB, $T_SB, $W_sendButton, $H_sendButton)
  GUICtrlSetPos($rezLabel, $L_RL, $T_rezLabel, $W_rezLabel, $H_RL)
  Local $xy = ControlGetPos($parentGUI, "", $rezLabel)
  Local $L_CG = $L_RL + $OS_X_childGUI
  Local $T_CG = $T_rezLabel + $OS_Y_childGUI
  Local $H_CG = $H_RL
  WinMove($childGUI, "", $L_CG, $T_CG, $W_childGUI, $H_CG)
EndFunc   ;==>WM_SIZE
Func WM_GETMINMAXINFO($hWnd, $MsgID, $wParam, $lParam)
If $hWnd = $parentGUI Then
  Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
  DllStructSetData($minmaxinfo, 7, $minWidth) ; min width
  DllStructSetData($minmaxinfo, 8, $minHeight) ; min height
Func _followParentGUI($hWnd, $iMsg, $wParam, $lParam)
#forceref $iMsg, $wParam, $lParam
If $hWnd <> $parentGUI Then Return
Local $parentGUI_pos = WinGetPos($parentGUI)
Local $xy = ControlGetPos($parentGUI, "", $rezLabel)
ConsoleWrite($xy[0] & "," & $xy[1] & @LF)
ConsoleWrite($parentGUI_pos[0] & "," & $parentGUI_pos[1] & @LF)
$OS_X_childGUI = $parentGUI_pos[0] + 8
$OS_Y_childGUI = $parentGUI_pos[1] + 30
Local $L_CG = $OS_X_childGUI + $xy[0]
Local $T_CG = $OS_Y_childGUI + $xy[1]
WinMove($childGUI, "", $L_CG, $T_CG)
EndFunc   ;==>_followParentGUI
Edited by Chuba
Link to post
Share on other sites
  • Moderators


You do not need both the UDF #include files - in fact you will get an error if you try to as they both contain a _GUIScrollbars_Restore function. From what I can see you only need the GUIScrollbars_Size UDF - replace your _GUIScrollbars_Restore function with _GUIScrollbars_Restore. :doh:

When you add controls to a scrollable GUI, you need to scroll the GUI to the top before you do so - this post from a few days ago shows how to do it. If you do not do this the controls position strangely as you have found - an explanation can be found here. :bye:

Finally, why are you even adding multiple edit controls - one for each entered line? As you can only enter single lines, why not use a list control which looks after its own scrollbars? :oops:


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:


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


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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...