Jump to content

if gui moves, move child gui's


Tomb
 Share

Recommended Posts

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]
Link to comment
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?

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]
Link to comment
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

Link to comment
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]
Link to comment
Share on other sites

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
Link to comment
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"

Link to comment
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
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
Link to comment
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]
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...