Sign in to follow this  
Followers 0
Tomb

if gui moves, move child gui's

13 posts in this topic

hi. is there any way to do this? if I move my main gui, my child gui's stay in the same spot and it looks silly. if i move my main gui, is there any way i can have my child gui's move along with it?

Share this post


Link to post
Share on other sites



Found this in my "Help Files" folder:

#include <GuiConstants.au3>
$Main_GUI = GUICreate("Main")
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Main_GUI)
$Child_GUI = GUICreate("Child", 200, 100, 10, 50);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $Child_GUI)
DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child_GUI), "hwnd", WinGetHandle($Main_GUI))



While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Btn_Exit
            ConsoleWrite($Child_GUI &' '&WinGetHandle(''))
            Exit
    EndSwitch
WEnd

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

so how is that whole thing causing child to move with main GUI ?

Share this post


Link to post
Share on other sites

DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Child_GUI), "hwnd", WinGetHandle($Main_GUI))
That uses a dll to connect the movements of the two windows so that when the parent is dragged the child gets moved too.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

is there a way to make a child gui move without it having to be 'inside' the main gui? Something like a toolwindow that is attached to the main window but from outside of the main window?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

is there a way to make a child gui move without it having to be 'inside' the main gui? Something like a toolwindow that is attached to the main window but from outside of the main window?

This is a rather sloppy way of doing it:

#include <GuiConstants.au3>
$Main_GUI = GUICreate("Main", 300, 100, 0, 0)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Main_GUI)
$Child_GUI = GUICreate("Child", 300, 100, 0, 126);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $Child_GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Btn_Exit
            ConsoleWrite($Child_GUI &' '&WinGetHandle(''))
            Exit
    EndSwitch
    
    $pos = WinGetPos($Main_GUI) 
    $childPos= WinGetPos($Child_GUI) 
    If $pos[0] <> $childPos[0] or $pos[1] <> $childPos[1] + 126 then 
        WinMove($child_GUI, '', $pos[0], $pos[1] + 126)
    EndIf
WEnd

Edit: I know there's a better way I just don't know what it is...

Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

This is a rather sloppy way of doing it:

#include <GuiConstants.au3>
$Main_GUI = GUICreate("Main", 300, 100, 0, 0)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Main_GUI)
$Child_GUI = GUICreate("Child", 300, 100, 0, 126);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $Child_GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Btn_Exit
            ConsoleWrite($Child_GUI &' '&WinGetHandle(''))
            Exit
    EndSwitch
    
    $pos = WinGetPos($Main_GUI) 
    $childPos= WinGetPos($Child_GUI) 
    If $pos[0] <> $childPos[0] or $pos[1] <> $childPos[1] + 126 then 
        WinMove($child_GUI, '', $pos[0], $pos[1] + 126)
    EndIf
WEnd

Edit: I know there's a better way I just don't know what it is...

where does the 126 come from?

what i have is a gui window and 4 child gui windows and if the gui moves, i want the child gui's to follow it

Share this post


Link to post
Share on other sites

where does the 126 come from?

what i have is a gui window and 4 child gui windows and if the gui moves, i want the child gui's to follow it

The 126 was just the distance between the two GUI's...

Here's my code a little bit changed it order to support more GUI's...

#include <GuiConstants.au3>
$Main_GUI = GUICreate("Main", 300, 100, 0, 0)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Main_GUI)
$gui1 = GUICreate("Child", 300, 100, 0, 126);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui1)
$gui2 = GUICreate("Child", 300, 100, 0, 252);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui2)
$gui3 = GUICreate("Child", 300, 100, 0, 378);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui3)
$gui4 = GUICreate("Child", 300, 100, 0, 504);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui4)

$oldPos = WinGetPos($Main_GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Btn_Exit
;~           ConsoleWrite($Child_GUI &' '&WinGetHandle(''))
            Exit
    EndSwitch
    
    $pos = WinGetPos($Main_GUI)
    If $pos[0] <> $oldPos[0] or $pos[1] <> $oldPos[1] then
        WinMove($gui1, '', $pos[0], $pos[1] + 126)
        WinMove($gui2, '', $pos[0], $pos[1] + 252)
        WinMove($gui3, '', $pos[0], $pos[1] + 378)
        WinMove($gui4, '', $pos[0], $pos[1] + 504)
    EndIf
WEnd
I still think there is a more efficient way, but this still works decently...

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The 126 was just the distance between the two GUI's...

Here's my code a little bit changed it order to support more GUI's...

#include <GuiConstants.au3>
$Main_GUI = GUICreate("Main", 300, 100, 0, 0)
$Btn_Exit = GUICtrlCreateButton("E&xit", 10, 10, 90, 20)
GUISetState(@SW_SHOW, $Main_GUI)
$gui1 = GUICreate("Child", 300, 100, 0, 126);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui1)
$gui2 = GUICreate("Child", 300, 100, 0, 252);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui2)
$gui3 = GUICreate("Child", 300, 100, 0, 378);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui3)
$gui4 = GUICreate("Child", 300, 100, 0, 504);, $WS_POPUP, $WS_EX_TOOLWINDOW)
GUISetState(@SW_SHOW, $gui4)

$oldPos = WinGetPos($Main_GUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Btn_Exit
;~           ConsoleWrite($Child_GUI &' '&WinGetHandle(''))
            Exit
    EndSwitch
    
    $pos = WinGetPos($Main_GUI)
    If $pos[0] <> $oldPos[0] or $pos[1] <> $oldPos[1] then
        WinMove($gui1, '', $pos[0], $pos[1] + 126)
        WinMove($gui2, '', $pos[0], $pos[1] + 252)
        WinMove($gui3, '', $pos[0], $pos[1] + 378)
        WinMove($gui4, '', $pos[0], $pos[1] + 504)
    EndIf
WEnd
I still think there is a more efficient way, but this still works decently...
that looks pretty good

although, how can i relate this to 5 gui windows, 4 on top of the other. 4 are child guis, and their location is in the center of the main GUI. i will try and edit your code for this purpose, but it is a little tricky

Edited by Tomb616

Share this post


Link to post
Share on other sites

#include <GuiConstantsEx.au3>

Global Const $WM_MOVING = 0x0216

$hGui1 = GUICreate("Main", 200, 200)
$hGui2 = GUICreate("Child", 200, 200, -1, -1, -1, -1, $hGui1)

Global $aMainPos = WinGetPos($hGui1)
WinMove($hGui2, '', $aMainPos[0]+$aMainPos[2], $aMainPos[1])

GUIRegisterMsg($WM_MOVING, 'On_WM_MOVING')
GUISetState(@SW_SHOW, $hGui1)
GUISetState(@SW_SHOW, $hGui2)

While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch
WEnd

Func On_WM_MOVING($hWnd, $Msg, $wParam, $lParam)
;;wParam - unused, lParam - pointer to a RECT structure
    If $hWnd = $hGui1 Then
        Local $tRect = DllStructCreate('int;int;int;int', $lParam), $iXcurr = DllStructGetData($tRect, 1), $iYcurr = DllStructGetData($tRect, 2), $aChildPos = WinGetPos($hGui2)
        WinMove($hGui2, "", $aChildPos[0]+$iXcurr-$aMainPos[0], $aChildPos[1]+$iYcurr-$aMainPos[1])
        $aMainPos[0] = $iXcurr
        $aMainPos[1] = $iYcurr
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

#include <GuiConstantsEx.au3>

Global Const $WM_MOVING = 0x0216

$hGui1 = GUICreate("Main", 200, 200)
$hGui2 = GUICreate("Child", 200, 200, -1, -1, -1, -1, $hGui1)

Global $aMainPos = WinGetPos($hGui1)
WinMove($hGui2, '', $aMainPos[0]+$aMainPos[2], $aMainPos[1])

GUIRegisterMsg($WM_MOVING, 'On_WM_MOVING')
GUISetState(@SW_SHOW, $hGui1)
GUISetState(@SW_SHOW, $hGui2)

While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch
WEnd

Func On_WM_MOVING($hWnd, $Msg, $wParam, $lParam)
;;wParam - unused, lParam - pointer to a RECT structure
    If $hWnd = $hGui1 Then
        Local $tRect = DllStructCreate('int;int;int;int', $lParam), $iXcurr = DllStructGetData($tRect, 1), $iYcurr = DllStructGetData($tRect, 2), $aChildPos = WinGetPos($hGui2)
        WinMove($hGui2, "", $aChildPos[0]+$iXcurr-$aMainPos[0], $aChildPos[1]+$iYcurr-$aMainPos[1])
        $aMainPos[0] = $iXcurr
        $aMainPos[1] = $iYcurr
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
i copied all pieces from this into my code, all i had to comment out was the WinMove, that was moving my game gui way to the side, and now if i move my main GUI my child gui moves along with it. :) :) :)

Thank you very much

Edited by Tomb

Share this post


Link to post
Share on other sites

#include <GuiConstantsEx.au3>

Global Const $WM_MOVING = 0x0216

$hGui1 = GUICreate("Main", 200, 200)
$hGui2 = GUICreate("Child", 200, 200, -1, -1, -1, -1, $hGui1)

Global $aMainPos = WinGetPos($hGui1)
WinMove($hGui2, '', $aMainPos[0]+$aMainPos[2], $aMainPos[1])

GUIRegisterMsg($WM_MOVING, 'On_WM_MOVING')
GUISetState(@SW_SHOW, $hGui1)
GUISetState(@SW_SHOW, $hGui2)

While 1
    Switch GUIGetMsg()
    Case -3
        Exit
    EndSwitch
WEnd

Func On_WM_MOVING($hWnd, $Msg, $wParam, $lParam)
;;wParam - unused, lParam - pointer to a RECT structure
    If $hWnd = $hGui1 Then
        Local $tRect = DllStructCreate('int;int;int;int', $lParam), $iXcurr = DllStructGetData($tRect, 1), $iYcurr = DllStructGetData($tRect, 2), $aChildPos = WinGetPos($hGui2)
        WinMove($hGui2, "", $aChildPos[0]+$iXcurr-$aMainPos[0], $aChildPos[1]+$iYcurr-$aMainPos[1])
        $aMainPos[0] = $iXcurr
        $aMainPos[1] = $iYcurr
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
That's what I had seen before, now I remember... using GuiRegisterMsg()

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

That's what I had seen before, now I remember... using GuiRegisterMsg()

also thank you Piano for your try to help me :)

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