Jump to content

Drag child gui with parent


Miliardsto
 Share

Recommended Posts

Hello.

Drag option works only on parent window but as we can see on the parent gui is showed up child gui (on the right side with the color).

Desired action is when we want to drag whole program we can also drag child gui and child gui will drag with parent gui.

How to do this?

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST")

$hGUI = GUICreate("Test", 500, 500, -1, -1)

$cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30)
$cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30)
$cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30)


GUISetState(@SW_SHOW, $hGUI)

; guis
Global $hChild_[3]
Global $countGUI = UBound($hChild_) - 1
;MsgBox("","",$countGUI)
; licznik dla GUI
Global $gui = 0



$hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFF0000)

GUISetState(@SW_SHOW, $hChild_[0])

$hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x00FF00)

GUISetState(@SW_HIDE, $hChild_[1])

$hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x0000FF)

GUISetState(@SW_HIDE, $hChild_[2])


While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_0
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[0])
            $gui = 0
        Case $cButton_1
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[1])
            $gui = 1
        Case $cButton_2
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[2])
            $gui = 2
    EndSwitch

WEnd



Func _All_Hide()
    GUISetState(@SW_HIDE, $hChild_[0])
    GUISetState(@SW_HIDE, $hChild_[1])
    GUISetState(@SW_HIDE, $hChild_[2])
EndFunc



Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam)
    If $hWnd = $hGUI Then
        Local $aPos = WinGetPos($hWnd)
        If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

  • Moderators

Miliardsto,

How about this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500, -1, -1)

$cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30)
$cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30)
$cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30)

GUISetState(@SW_SHOW, $hGUI)

; guis
Global $hChild_[3]
Global $countGUI = UBound($hChild_) - 1
Global $gui = 0

$hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW, $hChild_[0])

$hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x00FF00)
GUISetState(@SW_HIDE, $hChild_[1])

$hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x0000FF)
GUISetState(@SW_HIDE, $hChild_[2])

GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_0
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[0])
            $gui = 0
        Case $cButton_1
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[1])
            $gui = 1
        Case $cButton_2
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[2])
            $gui = 2
    EndSwitch

WEnd

Func _All_Hide()
    GUISetState(@SW_HIDE, $hChild_[0])
    GUISetState(@SW_HIDE, $hChild_[1])
    GUISetState(@SW_HIDE, $hChild_[2])
EndFunc

Func _NCHITTEST($hWnd, $iMsg, $wParam, $lParam)

    For $i = 0 To $countGUI
        If $hWnd = $hChild_[$i] Then
            Local $aPos = WinGetPos($hWnd)
            If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG
EndFunc

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

  • 2 weeks later...
  • Moderators

Miliardsto,

How about this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500, -1, -1)

$cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30)
$cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30)
$cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30)

GUISetState(@SW_SHOW, $hGUI)

; guis
Global $hChild_[3]
Global $countGUI = UBound($hChild_) - 1
Global $gui = 0

$hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW, $hChild_[0])

; Get difference in position of main and child GUIs
$aMainPos = WinGetPos($hGUI)
$aChildPos = WinGetPos($hChild_[0])
Global $iDiff_X = $aMainPos[0] - $aChildPos[0]
Global $iDiff_Y = $aMainPos[1] - $aChildPos[1]

$hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x00FF00)
GUISetState(@SW_HIDE, $hChild_[1])

$hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x0000FF)
GUISetState(@SW_HIDE, $hChild_[2])

GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST")
GUIRegisterMsg($WM_MOVE, "_WM_MOVE")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_0
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[0])
            $gui = 0
        Case $cButton_1
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[1])
            $gui = 1
        Case $cButton_2
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[2])
            $gui = 2
    EndSwitch

WEnd

Func _All_Hide()
    GUISetState(@SW_HIDE, $hChild_[0])
    GUISetState(@SW_HIDE, $hChild_[1])
    GUISetState(@SW_HIDE, $hChild_[2])
EndFunc

Func _NCHITTEST($hWnd, $iMsg, $wParam, $lParam)

    For $i = 0 To $countGUI
        If $hWnd = $hChild_[$i] Then
            Local $aPos = WinGetPos($hWnd)
            If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION
            ExitLoop
        EndIf
    Next
    Return $GUI_RUNDEFMSG
EndFunc

Func _WM_MOVE($hWnd, $iMsg, $wParam, $lParam)

    For $i = 0 To $countGUI
        If $hWnd = $hChild_[$i] Then
            ; Get child position
            Local $aPos = WinGetPos($hWnd)
            ; Adjust main GUI position
            WinMove($hGUI, "", $aPos[0] + $iDiff_X, $aPos[1] + $iDiff_Y)
            ExitLoop
        EndIf
    Next

EndFunc

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

Changed  your _NCHITTEST func and it  works like i wanted

can be drag by main gui and by child gui . awesome

thansks u very much for help kind guy B)

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 500, 500, -1, -1)

$cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30)
$cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30)
$cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30)

GUISetState(@SW_SHOW, $hGUI)

; guis
Global $hChild_[3]
Global $countGUI = UBound($hChild_) - 1
Global $gui = 0

$hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0xFF0000)
GUISetState(@SW_SHOW, $hChild_[0])

; Get difference in position of main and child GUIs
$aMainPos = WinGetPos($hGUI)
$aChildPos = WinGetPos($hChild_[0])
Global $iDiff_X = $aMainPos[0] - $aChildPos[0]
Global $iDiff_Y = $aMainPos[1] - $aChildPos[1]

$hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x00FF00)
GUISetState(@SW_HIDE, $hChild_[1])

$hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
GUISetBkColor(0x0000FF)
GUISetState(@SW_HIDE, $hChild_[2])

GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST")
GUIRegisterMsg($WM_MOVE, "_WM_MOVE")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton_0
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[0])
            $gui = 0
        Case $cButton_1
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[1])
            $gui = 1
        Case $cButton_2
            _All_Hide()
            GUISetState(@SW_SHOW, $hChild_[2])
            $gui = 2
    EndSwitch

WEnd

Func _All_Hide()
    GUISetState(@SW_HIDE, $hChild_[0])
    GUISetState(@SW_HIDE, $hChild_[1])
    GUISetState(@SW_HIDE, $hChild_[2])
EndFunc

Func _NCHITTEST($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd = $hGUI Then
        Local $aPos = WinGetPos($hWnd)
        If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION
    Else
        For $i = 0 To $countGUI
            If $hWnd = $hChild_[$i] Then
                Local $aPos = WinGetPos($hWnd)
                If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION
                ExitLoop
            EndIf
        Next
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Func _WM_MOVE($hWnd, $iMsg, $wParam, $lParam)

    For $i = 0 To $countGUI
        If $hWnd = $hChild_[$i] Then
            ; Get child position
            Local $aPos = WinGetPos($hWnd)
            ; Adjust main GUI position
            WinMove($hGUI, "", $aPos[0] + $iDiff_X, $aPos[1] + $iDiff_Y)
            ExitLoop
        EndIf
    Next

EndFunc

 

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

×
×
  • Create New...