Jump to content

Problem with control positions when resizing child gui


Chuba
 Share

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
main()
Func main()
startup()
While True
  Sleep(10)
WEnd
EndFunc   ;==>main
Func startup()
Opt("GUIOnEventMode", 1)
$parentGUI = GUICreate("parentGUI", $W_parentGUI, $H_parentGUI, $L_parentGUI, $T_parentGUI, _
       BitOR($WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetBkColor(0xF0F0F0)
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, _
       BitOR($ES_AUTOVSCROLL, $ES_OEMCONVERT, $ES_MULTILINE, $ES_WANTRETURN))
$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")
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
Dim $accelKeys[1][2] = [["{ENTER}", $sendButton]]
GUISetAccelerators($accelKeys)
GUISetState(@SW_SHOW, $parentGUI)
$childGUI = GUICreate("child", $W_childGUI, $H_childGUI, $L_childGUI, $T_childGUI, $WS_POPUP, $WS_EX_TOOLWINDOW, $parentGUI)
GUISetBkColor(0xFFFFFF)
_addMessage()
GUISetState(@SW_SHOW, $childGUI)
$aRet = _GUIScrollbars_Size(0, $H_childGUI, $W_childGUI, $H_childGUI)
If @error Then
  ConsoleWrite($aRet & " - " & @error & " - " & @extended & @CRLF)
Else
  For $i = 0 To 5
   ConsoleWrite($aRet[$i] & @CRLF)
  Next
EndIf
GUIRegisterMsg($WM_VSCROLL, "_Scrollbars_WM_VSCROLL")
_GUIScrollBars_Init($childGUI)
_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
   _addMessage()
  Case $GUI_EVENT_CLOSE
   _exit()
  Case $GUI_EVENT_RESTORE
   _GUIScrollbars_Restore($childGUI, True, False) ; We only want the vertical scrollbar to show
   MsgBox(0, "", "")
   Sleep(300)
  Case $GUI_EVENT_MINIMIZE
   _GUIScrollbars_Minimize($childGUI)
EndSwitch
EndFunc   ;==>SpecialEvents
Func _exit()
GUIDelete()
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, "")
GUISwitch($childGUI)
If $msgNo > 0 Then
  $lastMsgXY = ControlGetPos($childGUI, "", $messages[$msgNo - 1])
  $lastMsgYPos = $lastMsgXY[1] + $lastMsgXY[3] + $msgSpace
  $iChildGUIHeight += $lastMsgXY[3] + $msgSpace
EndIf
$messages[$msgNo] = GUICtrlCreateEdit($text, $messageColumnOffSet, $lastMsgYPos, $messageColumnSize, $lines * 15, _
     BitOR($ES_READONLY, $ES_MULTILINE, $ES_AUTOVSCROLL, $ES_WANTRETURN), $WS_EX_TRANSPARENT)
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)
  EndIf
  $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])
  EndIf
  $firstExpand = False
EndIf
_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)
  ;rezLabel
  Local $H_RL = $iHeight - ($H_parentGUI - $H_rezLabel)
  Local $L_RL = ($iWidth - ($W_parentGUI - $L_rezLabel))
  ;input
  Local $T_CI = $iHeight - ($H_parentGUI - $T_input)
  Local $L_CT = $L_RL + $messageColumnOffSet
  ;sendButton
  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)
EndIf
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
  Return "GUI_RUNDEFMSG"
EndIf
EndFunc   ;==>WM_GETMINMAXINFO
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 comment
Share on other sites

  • Moderators

Chuba,

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:

M23

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:

Spoiler

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 comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...