Jump to content

Setting Minimum Size Of Resizable Gui


Recommended Posts

I could swear that I remembered that it used to be that a GUI which is resizable could not be resized smaller than the size you specified in the GUICreate() command. I'm not GREAT at searching, but I can't find the reference I thought I rememberd in the help file, or a change to that behavior in the helpfile's change log, nor any discussion in the forum...

maybe I'm going crazy :)

Well, regardless of if it used to be like that or not, I'm looking for a way to prevent the window from being resized any smaller than x by y (let's say 640x480). It just starts looking ugly at that point. I could check for the size and if it's smaller, resize it back to the minimum easily enough, but the user would still see it smaller (therefore ugly) while they were resizing, so I'd like to find a solution to have the GUI just not shrink past a certain point...any ideas?

Thanks for any help!

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

well.... no one else answered and i couldn't find a way either...so

this will do the trick

#include <GUIConstants.au3>

Opt("GUICoordMode", 2)
$GUI = GUICreate ("My InputBox",190,114,-1,-1,$WS_SIZEBOX+$WS_SYSMENU); start the definition
GUISetIcon ("Eiffel Tower.ico")

GUISetFont (8,-1,"Arial")

GUICtrlCreateLabel ("Prompt", 8,7)  ; add prompt info
GUICtrlSetResizing (-1,$GUI_DOCKLEFT+$GUI_DOCKTOP)

$nEdit = GUICtrlCreateInput ("Default", -1,3,175,20,$ES_PASSWORD); add the input area
GUICtrlSetState ($nEdit,$GUI_FOCUS)
GUICtrlSetResizing ($nEdit,$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)

$nOk = GUICtrlCreateButton ("OK",-1,3,75,24); add the button that will close the GUI
GUICtrlSetResizing ($nOk,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKHCENTER)

$nCancel = GUICtrlCreateButton ("Annuler", 25,-1); add the button that will close the GUI
GUICtrlSetResizing ($nCancel,$GUI_DOCKBOTTOM+$GUI_DOCKSIZE+$GUI_DOCKHCENTER)

GUISetState ()              ; to display the GUI

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    $size = WinGetPos($GUI)
    If $size[2] < 190 Or $size[3] < 114 Then
        WinMove($GUI, "", $size[0], $size[1], 190,114)
    EndIf
Wend

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

I appreciate the reply. :(

This is pretty much what I was saying I could do:

I could check for the size and if it's smaller, resize it back to the minimum easily enough, but the user would still see it smaller (therefore ugly) while they were resizing, so I'd like to find a solution to have the GUI just not shrink past a certain point

To clarify, my problem with this method is this: Run that script, then grab a corner and shrink the window. It goes all the way down to the Windows-specified minimum (120x30, I think), pushing input over label, letting the buttons run off the page, etc...and all in all not being a very nice-looking window. Granted, as soon as I let go of the mouse button it pops out to the original size, but I'd really like to find out how to get back to the old behavior of just not ever going smaller than the original size.

The great thing about the script you gave me though is that I figured while it was there I'd run it under an old version of AutoIt to make sure I wasn't making what I'm calling the 'old' behavior up. So I toggled the Public Release (3.1.1) and ran your script, and sure enough, I can't shrink it past the initial size of 190x114 at all, even with the four lines of code you added commented out. Maybe I'll go through some old releases and find out at which release that behavior changed...

In the meantime though, thanks for trying! :)

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

I could swear that I remembered that it used to be that a GUI which is resizable could not be resized smaller than the size you specified in the GUICreate() command. I'm not GREAT at searching, but I can't find the reference I thought I rememberd in the help file, or a change to that behavior in the helpfile's change log, nor any discussion in the forum...

maybe I'm going crazy :)

Well, regardless of if it used to be like that or not, I'm looking for a way to prevent the window from being resized any smaller than x by y (let's say 640x480). It just starts looking ugly at that point. I could check for the size and if it's smaller, resize it back to the minimum easily enough, but the user would still see it smaller (therefore ugly) while they were resizing, so I'd like to find a solution to have the GUI just not shrink past a certain point...any ideas?

Thanks for any help!

In the beta we remove the minimum size constraint. so now the GUI can be resized smaller than the original size. :(
Link to comment
Share on other sites

In the beta we remove the minimum size constraint. so now the GUI can be resized smaller than the original size. :(

And it looks like that changed in beta release 3.1.1.75, right? (I see the old behavior all the way up through .74, though the ChangeLog for .75 didn't mention it). Is there a possibility that we could get an AutoItSetOption() to control that behavior? Or tell me if there's a function I can write into my codes to get the same effect? Though I can see the use of being able to go smaller than the initial size, I liked the old behavior. It'd be nice to be able to choose. Sorry for sounding so whiny, I'm just curious :) .

BTW, thanks big-time for the clarification! :D

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

And it looks like that changed in beta release 3.1.1.75, right? (I see the old behavior all the way up through .74, though the ChangeLog for .75 didn't mention it). Is there a possibility that we could get an AutoItSetOption() to control that behavior? Or tell me if there's a function I can write into my codes to get the same effect? Though I can see the use of being able to go smaller than the initial size, I liked the old behavior. It'd be nice to be able to choose. Sorry for sounding so whiny, I'm just curious :) .

BTW, thanks big-time for the clarification! :D

You get a $GUI_EVENT_RESIZED that you can do something in.

You can use the WinMove to force the size you want depending your desiderata.

I hope that help your concern :(

Link to comment
Share on other sites

  • Moderators

You get a $GUI_EVENT_RESIZED that you can do something in.

You can use the WinMove to force the size you want depending your desiderata.

I hope that help your concern :)

If I remember correctly $GUI_EVENT_RESIZED doesn't return until after the resize is already done.
Link to comment
Share on other sites

Here is working script using WM_GETMINMAXINFO:

#include <GUIConstants.au3>
Const $WM_GETMINMAXINFO = 0x24

GUICreate("Test GUI",500,500,-1,-1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
    
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
    DllStructSetData($minmaxinfo,7,400); min X
    DllStructSetData($minmaxinfo,8,250); min Y
    Return 0
EndFunc

#cs
typedef struct {
    POINT ptReserved;
    POINT ptMaxSize;
    POINT ptMaxPosition;
    POINT ptMinTrackSize;
    POINT ptMaxTrackSize;
} MINMAXINFO;
#ce
Link to comment
Share on other sites

Const $WM_GETMINMAXINFO = 0x24
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
    DllStructSetData($minmaxinfo,7,400); min X
    DllStructSetData($minmaxinfo,8,250); min Y
    Return 0
EndFunc

Wow...I have NO idea what all this is (dll 's are WAY over my head :) ) but dropping this code anywhere in my script worked like a charm!

Housekeeping question - does this limit ALL the GUIs in any given script to the constraints you put forth in the DllStructSetData commands? Assuming yes, is there any way to limit the scope of the limit to a single GUI or to turn this on/off as different GUIs become active and/or to set different limits on different GUIs?

This was perfect for my current script...THANKS!!! :D:(:oops:

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Housekeeping question - does this limit ALL the GUIs in any given script to the constraints you put forth in the DllStructSetData commands? Assuming yes, is there any way to limit the scope of the limit to a single GUI or to turn this on/off as different GUIs become active and/or to set different limits on different GUIs?

You can use $hWnd parameter in MY_WM_GETMINMAXINFO() to distinguish between GUIs.

Link to comment
Share on other sites

You can use $hWnd parameter in MY_WM_GETMINMAXINFO() to distinguish between GUIs.

Something like...

Const $WM_GETMINMAXINFO = 0x24
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    If $hWnd=$MyGUIsName Then; the main GUI-limited to 640x480
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,640); min X
        DllStructSetData($minmaxinfo,8,480); min Y
        Return 0
    ElseIf $hWnd=$aSecondaryGUI Then; maybe a prompt GUI - something smaller (min 400x250)
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,400); min X
        DllStructSetData($minmaxinfo,8,250); min Y
        Return 0
    Else;other dialogs-"no" lower limit
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,1); min X
        DllStructSetData($minmaxinfo,8,1); min Y
        Return 0
    EndIf
EndFunc

?

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Decided I should really answer my own question - ran the following code:

#include <GUIConstants.au3>

Const $WM_GETMINMAXINFO = 0x24
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    If $hWnd=$MyGUIsName Then; the main GUI-limited to 640x480
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,640); min X
        DllStructSetData($minmaxinfo,8,480); min Y
        Return 0
    ElseIf $hWnd=$aSecondaryGUI Then; maybe a prompt GUI - something smaller (min 400x250)
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,400); min X
        DllStructSetData($minmaxinfo,8,250); min Y
        Return 0
    Else;other dialogs-"no" lower limit
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,1); min X
        DllStructSetData($minmaxinfo,8,1); min Y
        Return 0
    EndIf
EndFunc

$MyGUIsName=GUICreate("Test GUI 1",700,700,-1,-1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
$aSecondaryGUI=GUICreate("Test GUI 2",500,500,1,1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
GUICreate("Any other dialog",200,200,8000,800,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

and it worked like a charm!

Thanks SO much - that should quite take care of anything along these lines for me in the future!

Edit: Hadn't noticed that you'd already posted a reply to my "something like..." question - sorry for asking a question I could/should have just tried out and answered on my own.

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

@big_daddy: Thanks I like playing with AutoIt and Win32 API :)

@james3mg: Here is corrected/optimized your example for more than one GUI --> for "no limit" use just Return 0:

#include <GUIConstants.au3>

Const $WM_GETMINMAXINFO = 0x24
GUIRegisterMsg($WM_GETMINMAXINFO, "MY_WM_GETMINMAXINFO")
Func MY_WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam)
    If $hWnd=$MyGUIsName Then; the main GUI-limited to 640x480
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,640); min X
        DllStructSetData($minmaxinfo,8,480); min Y
        Return 0
    ElseIf $hWnd=$aSecondaryGUI Then; maybe a prompt GUI - something smaller (min 400x250)
        $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
        DllStructSetData($minmaxinfo,7,400); min X
        DllStructSetData($minmaxinfo,8,250); min Y
        Return 0
    Else;other dialogs-"no" lower limit
;~       $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
;~       DllStructSetData($minmaxinfo,7,1); min X
;~       DllStructSetData($minmaxinfo,8,1); min Y
        Return 0
    EndIf
EndFunc

$MyGUIsName=GUICreate("Test GUI 1",700,700,-1,-1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
$aSecondaryGUI=GUICreate("Test GUI 2",500,500,1,1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
GUICreate("Any other dialog",300,300,400,400,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))
GUISetState (@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

And there can used also max. limit:

DllStructSetData($minmaxinfo,9,600); max X
    DllStructSetData($minmaxinfo,10,700); max Y
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...