Jump to content

GUICreate & WinMove


Capel
 Share

Recommended Posts

I have created a simple form and put some buttons on it. One of the buttons resizes the form using the WinMove function. When I click the button, it moves all the buttons down by 23 in the Y direction. Why does it do this and how can I avoid it? I don't want to have to reposition all the controls on my form when I resize it...

Link to comment
Share on other sites

Link to comment
Share on other sites

Add the following line:

GUICtrlSetResizing($Button1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))

Thanks Yashied, this fixed the button moving around, but explain why the form height goes to 0 when i click the button a second time.

WinMove("Form2", "", 302, 218, 413, 36)

The form was created with a height of 36, but it seems like WinMove is not accounting for the height of the title bar.

Link to comment
Share on other sites

Thanks Yashied, this fixed the button moving around, but explain why the form height goes to 0 when i click the button a second time.

WinMove("Form2", "", 302, 218, 413, 36)

The form was created with a height of 36, but it seems like WinMove is not accounting for the height of the title bar.

When you change the size of the window by WinMove() function you missed the title and borders.

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

Global $dW = 2 * _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
Global $dH = 2 * _WinAPI_GetSystemMetrics($SM_CXDLGFRAME) + _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $blOptionOut = False

$Form2 = GUICreate("Form2", 413, 36, 302, 218)
$Button1 = GUICtrlCreateButton("Button1", 4, 4, 77, 25)
GUICtrlSetResizing($Button1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            resize()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func resize()
    $Pos = WinGetPos($Form2)
    If $blOptionOut Then
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 36 + $dH)
        $blOptionOut = False
    Else
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 197 + $dH)
        $blOptionOut = True
    EndIf
EndFunc   ;==>resize

EDIT: Code

Edited by Yashied
Link to comment
Share on other sites

When you change the size of the window by WinMove() function you missed the title and borders.

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

Global $dW = 2 * _WinAPI_GetSystemMetrics($SM_CXDLGFRAME)
Global $dH = 2 * _WinAPI_GetSystemMetrics($SM_CXDLGFRAME) + _WinAPI_GetSystemMetrics($SM_CYCAPTION)
Global $blOptionOut = False

$Form2 = GUICreate("Form2", 413, 36, 302, 218)
$Button1 = GUICtrlCreateButton("Button1", 4, 4, 77, 25)
GUICtrlSetResizing($Button1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button1
            resize()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func resize()
    $Pos = WinGetPos($Form2)
    If $blOptionOut Then
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 36 + $dH)
        $blOptionOut = False
    Else
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 197 + $dH)
        $blOptionOut = True
    EndIf
EndFunc   ;==>resize

EDIT: Code

So here is another strange thing. If I add the following line of code in the resize() function:

ControlMove("", "", $Button1, 4, 4, 35, 25) in order to change the width of the button.

Func resize()
    $Pos = WinGetPos($Form2)
    If $blOptionOut Then
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 36 + $dH)
        $blOptionOut = False
    Else
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 197 + $dH)
        ControlMove("", "", $Button1, 4, 4, 35, 25)
        $blOptionOut = True
    EndIf
EndFunc

Why does it reset the width of the button when I toggle it even though I have not told AutoIT to do this? The WinMove obviously resets the width of the button back to the original width! I want the width to stay smaller after I press it once...

Link to comment
Share on other sites

Hi, use GUICtrlSetResizing() on the control after resizing it

Func resize()
    $Pos = WinGetPos($Form2)
    If $blOptionOut Then
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 36 + $dH)
        $blOptionOut = False
    Else
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 197 + $dH)
        ControlMove($Form2, "", $Button1, 4, 4, 35, 25)
        GUICtrlSetResizing($Button1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKSIZE))
        $blOptionOut = True
    EndIf
EndFunc

Cheers

Link to comment
Share on other sites

Capel and Smashly, what's wrong with GUICtrlSetPos() ?

Func resize()
    $Pos = WinGetPos($Form2)
    If $blOptionOut Then
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 36 + $dH)
        $blOptionOut = False
    Else
        ConsoleWrite('!' & @CR)
        WinMove($Form2, "", $Pos[0], $Pos[1], 413 + $dW, 197 + $dH)
        GUICtrlSetPos($Button1, 4, 4, 35, 25)
;        ControlMove("", "", $Button1, 4, 4, 35, 25)
        $blOptionOut = True
    EndIf
EndFunc   ;==>resize
Link to comment
Share on other sites

What is the difference between the two other than how you reference the control?

GUICtrlSetPos() works with AutoIt controls only and designed for it.

Do I still need to call GUICtrlSetResizing after every WinMove using GUICtrlSetPos?

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