Sign in to follow this  
Followers 0
darkjohn20

Lock windows together?

2 posts in this topic

I've seen a program with a main GUI have a child window that moves along with the parent, and I was wondering how you can lock the child to the side of the parent.

For example, I have Window_One as the main window, and Window_Two needs to be locked to the right side of it.

OOOOTTTT

OOOOTTTT

OOOOTTTT

That's a rough "drawing".

I have this code:

While 1
    $WinPos = WinGetPos("Parent")
    $Child = WinMove("Child", "", $WinPos[0]+$WinPos[2]+10, $WinPos[1])
    Sleep(100)
WEnd

which moves the child correctly, but only AFTER I finish dragging the parent around. How can I make it follow the parent even WHILE I am dragging it?

Share this post


Link to post
Share on other sites



; *** Start added by AutoIt3Wrapper ***
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
Global Const $WM_ENTERSIZEMOVE = 0x231, $WM_EXITSIZEMOVE = 0x232


$gp = GUICreate("main gui", 300, 300, 200, 200)
GUISetState()
$gs = GUICreate("dragged gui", 200, 150, 400, 400)
GUISetState()


Global $RelPos[2]
GUIRegisterMsg($WM_ENTERSIZEMOVE, "setrelpos")
GUIRegisterMsg($WM_MOVE, "followme")

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func followme($hW, $iM, $wp, $lp)

    If $hW <> $gp Then Return

    Local $xypos = WinGetPos($gp);use WingetPos rather than the values in $lP
    WinMove($gs, "", $xypos[0] - $RelPos[0], $xypos[1] - $RelPos[1])

EndFunc ;==>followme


;When the primary window starts moving we want to know the relative position of the secondary window.
Func SetRelPos($hW, $iM, $wp, $lp)

    If $hW <> $gp Then Return

    Local $gpp = WinGetPos($gp)
    Local $gsp = WinGetPos($gs)

    $RelPos[0] = $gpp[0] - $gsp[0]
    $RelPos[1] = $gpp[1] - $gsp[1]


EndFunc ;==>SetRelPos

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