Sign in to follow this  
Followers 0
Capel

GUICreate & WinMove

14 posts in this topic

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

Share this post


Link to post
Share on other sites



code sample?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

quote name='ctyankeeinok' date='11 September 2009 - 12:51 PM' timestamp='1252687872' post='725830']

code sample?

Edited by Capel

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Thanks Yashied, that did it.

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

So do I need to call GUICtrlSetResizing for every control on the form after every WinMove?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Not really, but it also depends on what your after.

You'll need to experiment and see for your self.

Edited by smashly

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Yashied,

What is the difference between the two other than how you reference the control? Do I still need to call GUICtrlSetResizing after every WinMove using GUICtrlSetPos?

Share this post


Link to post
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.

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