Sign in to follow this  
Followers 0
SlowCoder74

GUI Frame Support?

4 posts in this topic

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.

Share this post


Link to post
Share on other sites



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?

#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._______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

 

Share this post


Link to post
Share on other sites

Melba23

A little remark: If you comment the case: $GUI_EVENT_PRIMARYDOWN your script still work the same.

kazio3001

Share this post


Link to post
Share on other sites

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._______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

 

Share this post


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
Sign in to follow this  
Followers 0