Jump to content
Miliardsto

Drag child gui with parent

Recommended Posts

Miliardsto

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

 

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

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
Miliardsto

good but child gui has to be drag with parent gui

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

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
Miliardsto

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

 

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
    • XinYoung
      By XinYoung
      For fun, I'm building an app that opens a webpage and refreshes it every 30 seconds.
      But once the script performs _IEAction($oIE, "refresh"), the GUI closes.
      Any help is appreciated.
       

      #include <ButtonConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <WinAPIFiles.au3>
      #include <Array.au3>
      #include <File.au3>
      #include <Excel.au3>
      #include <DateTimeConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIShellEx.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <ComboConstants.au3>
      #include <guimenu.au3>
      #include <IE.au3>
      HotKeySet("{F4}", "_Exit")
      ;Open the file(s) in the selected folder
      $extension = ".txt"
      $app2openWith = @SystemDir & "\notepad.exe"
      Func Begin()
          Global $loopTrick = 0
          #Region ### START Koda GUI section ### Form=c:\users\mchu\downloads\autoit\my code\form1.kxf
          Global $UI = GUICreate("Hit Em Up!", 256, 113, -1, -1)
          GUISetBkColor(0x000000)
          $menu = _GUICtrlMenu_GetSystemMenu($UI)
          _GUICtrlMenu_EnableMenuItem($menu, $SC_CLOSE, 1, False)
          Global $url = GUICtrlCreateInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 81, 8, 160, 21)
          $Label1 = GUICtrlCreateLabel("Target:", 16, 8, 55, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          Global $StartBut = GUICtrlCreateButton("Start", 16, 40, 67, 25)
          GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
          GUICtrlSetBkColor(-1, 0x008000)
          $Label2 = GUICtrlCreateLabel("(Press F4 to Exit)", 96, 40, 8000, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          GUISetState(@SW_SHOW)
          #EndRegion ### END Koda GUI section ###
          While 1
              $UIfunc = GUIGetMsg()
              Select
                  Case $UIfunc = $GUI_EVENT_CLOSE
                      _Exit()
                  Case $UIfunc = $StartBut
                      If GUICtrlRead($url) = "" Then
                          MsgBox(48, "Um...", "Give me a target you idiot.")
                      Else
                          GUICtrlSetState($url, $GUI_DISABLE)
                          GUICtrlSetState($StartBut, $GUI_DISABLE)
                          Start()
                      EndIf
              EndSelect
          WEnd
      EndFunc   ;==>Begin
      Func Start()
          If $loopTrick = 0 Then
              Global $oIE = _IECreate(GUICtrlRead($url))
              _IELoadWait($oIE)
              Again()
          ElseIf $loopTrick = 1 Then
              Sleep(3000)
              _IEAction($oIE, "refresh")
              Sleep(3000)
              Start()
          EndIf
      EndFunc   ;==>Start
      Func Again()
          $loopTrick = 1
          Start()
      EndFunc   ;==>Again
      Func _Exit()
          Exit
      EndFunc   ;==>_Exit
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • kcvinu
      By kcvinu
      Hi all,
      I am playing with _GUICtrlButton_Create function. How can i change this button's (or the entire form's) font ?. The in-built GUICtrlSetFont function is not working even when i convert the control handle to control ID with _WinAPI_GetDlgCtrlID ( ) function.  Do i need to use CreateFont api finction and send WM_SETFONT message ? Or is there any other easy and safe ways to do this ?. Thanks in advance.
      Note : This window is created by CreateWindowEx function, not by GUICreate function. 
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.