SlowCoder74 Posted January 31, 2012 Share Posted January 31, 2012 Hey all. New member, and new AutoIT user! I'm doing a couple of projects for work, and I've been asked to modify some existing AutoIT code. As I'm familiar with VB scripting, I'm finding it easy to get along in AutoIT. However, one of these projects has a lot of GUI elements. As they ask me to add objects to the GUI, I will need to be able to move objects around on the window. To ease the transition, I'd like to know if it's possible to do either of these: 1. Can a form frame, like in VB, be created as a container for child GUI objects, thereby allowing me to move the frame without having to change the position of each object? 2. Is there a way to obtain the left/top position of, say, a title label, so that I can use it as a reference for positioning other objects? Thanks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 31, 2012 Moderators Share Posted January 31, 2012 SlowCoder74 Welcome to the AutoIt forum. Child GUIs could well be the solution you are looking for - you can drag them with a mouse. Does this seem to fit the bill? expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() $aPos = WinGetPos($hGUI) $hChild_1 = GUICreate("", 100, 100, -1, -1, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFFC0C0) $hButton_1 = GUICtrlCreateButton("Button 1", 10, 10, 80, 30) WinMove($hChild_1, "", $aPos[0] + 10, $aPos[1] + 50) GUISetState() $hChild_2 = GUICreate("", 100, 100, -1, -1, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xC0FFC0) $hButton_2 = GUICtrlCreateButton("Button 2", 10, 10, 80, 30) WinMove($hChild_2, "", $aPos[0] + 300, $aPos[1] + 300) GUISetState() $hChild_3 = GUICreate("", 100, 100, -1, -1, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xC0C0FF) $hButton_3 = GUICtrlCreateButton("Button 3", 10, 10, 80, 30) WinMove($hChild_3, "", $aPos[0] + 100, $aPos[1] + 200) GUISetState() GUIRegisterMsg($WM_NCHITTEST, "_WM_NCHITTEST") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 MsgBox(0, "Test", "Button 1 pressed") Case $hButton_2 MsgBox(0, "Test", "Button 2 pressed") Case $hButton_3 MsgBox(0, "Test", "Button 3 pressed") Case $GUI_EVENT_PRIMARYDOWN ; Are we over a control? $cInfo = GUIGetCursorInfo($hGUI) $iControl = $cInfo[4] ; If so If $iControl Then ; Get control position $aPos = ControlGetPos($hGUI, "", $iControl) ; Where is it on GUI $iSubtractX = $cInfo[0] - $aPos[0] $iSubtractY = $cInfo[1] - $aPos[1] Do ; get cursor position $cInfo = GUIGetCursorInfo($hGUI) ; And move control ControlMove($hGUI, "", $iControl, $cInfo[0] - $iSubtractX, $cInfo[1] - $iSubtractY) ; Until the mouse is no longer pressed Until Not $cInfo[2] EndIf EndSwitch WEnd Func _WM_NCHITTEST($hWnd, $uMsg, $wParam, $lParam) Switch $hWnd Case $hChild_1, $hChild_2, $hChild_3 Local $aPos = WinGetPos($hWnd) ; Check if mouse is over GUI If Abs(BitAND(BitShift($lParam, 16), 0xFFFF) - $aPos[1]) < 100 Then Return $HTCAPTION EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NCHITTEST Any use? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kazio3001 Posted June 6, 2013 Share Posted June 6, 2013 Melba23 A little remark: If you comment the case: $GUI_EVENT_PRIMARYDOWN your script still work the same. kazio3001 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 6, 2013 Moderators Share Posted June 6, 2013 kazio3001,Quite right - well spotted. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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