Jump to content

_ChildFollow


zcoacoaz
 Share

Recommended Posts

Here is _ChildFollow

Global Const $CF_TOP = 0
Global Const $CF_LEFT = 1
Global Const $CF_RIGHT = 2
Global Const $CF_BOTTOM = 3

Func _ChildFollow ( $Parent, $Child, $ChildSide=0 )
    If $ChildSide=0 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $X = ($MovePos[2]-$PPos[2])/2+$MovePos[0]
        WinMove ( $Child, "", $X , $MovePos[1] - ($PPos[3]-1) )
    ElseIf $ChildSide=1 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $Y = ($MovePos[3]-$PPos[3])/2+$MovePos[1]
        WinMove ( $Child, "", $MovePos[0]-$PPos[2] , $Y )
    ElseIf $ChildSide=2 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $Y = ($MovePos[3]-$PPos[3])/2+$MovePos[1]
        WinMove ( $Child, "", $MovePos[0]+$MovePos[2] , $Y )
    ElseIf $ChildSide=3 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $X = ($MovePos[2]-$PPos[2])/2+$MovePos[0]
        WinMove ( $Child, "", $X , $MovePos[3] + $MovePos[1] )
    EndIf
EndFunc

And here is the _ChildFollow example

#include <GUIConstants.au3>
Global Const $CF_TOP = 0
Global Const $CF_LEFT = 1
Global Const $CF_RIGHT = 2
Global Const $CF_BOTTOM = 3
Opt ( "GUIOnEventMode", 1 )
GuiCreate("Child",400,80,350,300)
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )
GUICreate ( "Parent", 600, 400, -1, -1, $WS_SIZEBOX + $WS_SYSMENU )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )

While 1
    _ChildFollow ( "Parent", "Child", $CF_BOTTOM )
WEnd

Func Quit()
    Exit
EndFunc

Func _ChildFollow ( $Parent, $Child, $ChildSide=0 )
    If $ChildSide=0 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $X = ($MovePos[2]-$PPos[2])/2+$MovePos[0]
        WinMove ( $Child, "", $X , $MovePos[1] - ($PPos[3]-1) )
    ElseIf $ChildSide=1 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $Y = ($MovePos[3]-$PPos[3])/2+$MovePos[1]
        WinMove ( $Child, "", $MovePos[0]-$PPos[2] , $Y )
    ElseIf $ChildSide=2 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $Y = ($MovePos[3]-$PPos[3])/2+$MovePos[1]
        WinMove ( $Child, "", $MovePos[0]+$MovePos[2] , $Y )
    ElseIf $ChildSide=3 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $X = ($MovePos[2]-$PPos[2])/2+$MovePos[0]
        WinMove ( $Child, "", $X , $MovePos[3] + $MovePos[1] )
    EndIf
EndFunc

Here is the bigger _ChildFollow example

#include <GUIConstants.au3>
Global Const $CF_TOP = 0
Global Const $CF_LEFT = 1
Global Const $CF_RIGHT = 2
Global Const $CF_BOTTOM = 3
Opt ( "GUIOnEventMode", 1 )
GuiCreate("Child",400,80,350,300)
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )
GUICreate ( "Parent", 600, 400, -1, -1, $WS_SIZEBOX + $WS_SYSMENU )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )
GUICreate ( "Second Child", 80, 200 )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )
GUICreate ( "Third Child", 80, 200 )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )
GUICreate ( "Forth Child", 400, 80 )
GUISetOnEvent ( $GUI_EVENT_CLOSE, "Quit" )
GUISetState ( )

While 1
    _ChildFollow ( "Parent", "Child", $CF_BOTTOM )
    _ChildFollow ( "Parent", "Second Child", $CF_LEFT )
    _ChildFollow ( "Parent", "Third Child", $CF_RIGHT )
    _ChildFollow ( "Parent", "Forth Child", $CF_TOP )
WEnd

Func Quit()
    Exit
EndFunc

Func _ChildFollow ( $Parent, $Child, $ChildSide=0 )
    If $ChildSide=0 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $X = ($MovePos[2]-$PPos[2])/2+$MovePos[0]
        WinMove ( $Child, "", $X , $MovePos[1] - ($PPos[3]-1) )
    ElseIf $ChildSide=1 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $Y = ($MovePos[3]-$PPos[3])/2+$MovePos[1]
        WinMove ( $Child, "", $MovePos[0]-$PPos[2] , $Y )
    ElseIf $ChildSide=2 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $Y = ($MovePos[3]-$PPos[3])/2+$MovePos[1]
        WinMove ( $Child, "", $MovePos[0]+$MovePos[2] , $Y )
    ElseIf $ChildSide=3 Then
        $PPos = WinGetPos ( $Child )
        $MovePos = WinGetPos ( $Parent )
        $X = ($MovePos[2]-$PPos[2])/2+$MovePos[0]
        WinMove ( $Child, "", $X , $MovePos[3] + $MovePos[1] )
    EndIf
EndFunc

:)

Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

Nice, to bad it doesn't move in 'real time', ie. The window changes position after you release the mouse button.

Edit: Also, in your example you might want to make the 'Child' windows... child windows... eg.

$Parent = GUICreate ( "Parent", 600, 400, -1, -1, $WS_SIZEBOX + $WS_SYSMENU )
GUICreate ( "First Child",400,80,350,300,-1,-1,$Parent )
GUICreate ( "Second Child", 80, 200-1,-1,$Parent )
GUICreate ( "Third Child", 80, 200-1,-1,$Parent )
GUICreate ( "Forth Child", 400, 80-1,-1,$Parent )

So you only have 'one' window that appears in the taskbar and task manager etc. Just a suggestion.

Edited by Burrup

qq

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...