Jump to content

GUI Snap to GUI Help


Recommended Posts

OK I have looked threw the Help File not finding anything. When I run my script my main GUI opens I have a button when pushed runs another script and my second GUI opens is there away to make this GUI window automatically snap to the bottom of the main GUI window.

So it looks like this.

Posted Image

Edited by Justforfun
Link to comment
Share on other sites

1. WinGetHandle() to ID the first window.

2. WinGetPos() to get position and size of first window.

3. WinMove() to move second window to the correct position.

4. Use a loop or an AdLibRegister() function to repeat the process, if required.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Something like this.

#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>

$hOpt = 0

$hForm = GUICreate('MyGUI', 400, 400, 600, 100, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$Button = GUICtrlCreateButton('Options', 165, 366, 70, 23)
GUIRegisterMsg($WM_ACTIVATE, 'WM_ACTIVATE')
GUIRegisterMsg($WM_MOVE, 'WM_MOVE')
GUISetState()

While 1
    $Msg = GUIGetMsg(1)
    Switch $Msg[0]
        Case -3
            Switch $Msg[1]
                Case $hForm
                    Exit
                Case $hOpt
                    GUICtrlSetState($Button, $GUI_ENABLE)
                    GUIDelete($hOpt)
                    $hOpt = 0
            EndSwitch
        Case $Button
            If Not $hOpt Then
                $Pos = WinGetPos($hForm)
                $hOpt = GUICreate('Options', 400, 100, $Pos[0], $Pos[1] + 436, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
                GUISetState(@SW_SHOWNOACTIVATE, $hOpt)
                GUICtrlSetState($Button, $GUI_DISABLE)
            EndIf
    EndSwitch
WEnd

Func WM_ACTIVATE($hWnd, $iMsg, $wParam, $lParam)
    Switch BitAND($wParam, 0xFFFF)
        Case 1, 2
            Switch $hWnd
                Case 0

                Case $hForm
                    If $hOpt Then
                        WinSetOnTop($hOpt, '', 1)
                        WinSetOnTop($hOpt, '', 0)
                    EndIf
                Case $hOpt
                    WinSetOnTop($hForm, '', 1)
                    WinSetOnTop($hForm, '', 0)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_ACTIVATE

Func WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
    $X = BitAND($lParam, 0xFFFF)
    If $X > 0x7FFF Then
        $X -= 0x10000
    EndIf
    $Y = BitShift($lParam, 16)
    If $Y > 0x7FFF Then
        $Y -= 0x10000
    EndIf
    Switch $hWnd
        Case 0

        Case $hForm
            If $hOpt Then
                WinMove($hOpt, '', $X - 3, $Y + 407)
            EndIf
        Case $hOpt
            WinMove($hForm, '', $X - 3, $Y - 465)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOVE

EDIT: Code

Edited by Yashied
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...