Jump to content

How to make GUI proportionally larger?


qwert
 Share

Recommended Posts

I have a GUI that uses graphical buttons on a graphic background. Is there a standard function or setting that will allow the user to resize the entire window, while maintaining the aspect ratio of the graphics and the relative positions of the buttons on the graphic? In other words, they could grab the edge of the window and enlarge it -- and everything would just get "proportionally larger".

(I'm fairly new to AutoIt, so please bear with me while I get a handle on how to accomplish this.)

Thanks in advance for any advice.

Link to comment
Share on other sites

Thanks, Emiel. The sizing works, but that's the smaller half of the problem:

and everything would just get "proportionally larger"

I also need:

1) for the background image to get larger (to fill the window) and

2) the graphic buttons on top of the image to move and resize accordingly.

Is there any hope of that?

Link to comment
Share on other sites

Thanks, Emiel. The sizing works, but that's the smaller half of the problem:

I also need:

1) for the background image to get larger (to fill the window) and

2) the graphic buttons on top of the image to move and resize accordingly.

Is there any hope of that?

Have you checked out GUICtrlSetResizing() ?
Link to comment
Share on other sites

  • 2 weeks later...

---Original post removed: better solution found---

With a little reference information from http://www.autoitscript.com/forum/index.ph...rt=#entry472003, I found this works quite well:

#include <GUIConstants.au3>
Global $GUISize[2]=[550,300]

$Parent = GUICreate("My Proportional GUI", $GUISize[0], $GUISize[1], -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX)
GUICtrlCreateButton("I'm a button!",100,100,200,100)
GUICtrlSetResizing(-1,1)

GUISetState()

GUIRegisterMsg(0x24,"StayProportional")
Func StayProportional($hWnd, $Msg, $wParam, $lParam)
    If $hWnd <> $Parent Then Return
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
    Local $_pos=WinGetPos(WinGetTitle($Parent))
    DllStructSetData($minmaxinfo,8,$_pos[2]*($GUISize[1]/$GUISize[0]))
    DllStructSetData($minmaxinfo,10,$_pos[2]*($GUISize[1]/$GUISize[0]))
    Return 0
EndFunc

Do
    sleep(15)
Until GUIGetMsg() = -3
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

I found this works quite well ...

What a good solution! Thanks again for looking at my scripts.

The only improvement I need now is to combine this with my bitmap background -- and have the bitmap resize as well. I'll spend time on that over this weekend.

Link to comment
Share on other sites

What a good solution! Thanks again for looking at my scripts.

The only improvement I need now is to combine this with my bitmap background -- and have the bitmap resize as well. I'll spend time on that over this weekend.

I'm no longer in a place I can test scripts, but it seems to me you should be able to put the GUICtrlSetResizing(-1,1) line directly after you create the background (maybe even before you disable it), and it would resize as well...

Give it a shot, let me know. I'll stay tuned.

"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

you should be able to put the GUICtrlSetResizing(-1,1) line directly after you create the background

That worked!

The very last enhancement I need is to do away with the parent frame and be able to resize by grabbing the edge of the bitmap. The only reason I think it's even possible is because I have a PNG image version that's able to drag left and right by grabbing its edge. Experimentation will hopefully reveal a method.

Thanks again for your help.

Link to comment
Share on other sites

---Original post removed: better solution found---

With a little reference information from http://www.autoitscript.com/forum/index.ph...rt=#entry472003, I found this works quite well:

#include <GUIConstants.au3>
Global $GUISize[2]=[550,300]

$Parent = GUICreate("My Proportional GUI", $GUISize[0], $GUISize[1], -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX)
GUICtrlCreateButton("I'm a button!",100,100,200,100)
GUICtrlSetResizing(-1,1)

GUISetState()

GUIRegisterMsg(0x24,"StayProportional")
Func StayProportional($hWnd, $Msg, $wParam, $lParam)
    If $hWnd <> $Parent Then Return
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int",$lParam)
    Local $_pos=WinGetPos(WinGetTitle($Parent))
    DllStructSetData($minmaxinfo,8,$_pos[2]*($GUISize[1]/$GUISize[0]))
    DllStructSetData($minmaxinfo,10,$_pos[2]*($GUISize[1]/$GUISize[0]))
    Return 0
EndFunc

Do
    sleep(15)
Until GUIGetMsg() = -3
Thats good, I didn't realize that would work. The way you've done it you can only resize by dragging the width. I played with this and found it's a bit more difficult to make it work from dragging the height as well, but here's a way that works.

#include <GUIConstants.au3>
Global $GUISize[2] = [550, 300]
Global $k;if true set the width by ht else set ht by width
$wayset = False;we haven't decided which way were're resizing by
$Parent = GUICreate("My Proportional GUI", $GUISize[0], $GUISize[1], -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX)
GUICtrlCreateButton("I'm a button!", 100, 100, 200, 100)
GUICtrlSetResizing(-1, 1)
GUICtrlCreateButton("So am I!", 350, 100, 50, 100)
GUICtrlSetResizing(-1, 1)
Const $WM_EXITSIZEMOVE = 0x232
Const $WM_ENTERSIZEMOVE = 0x231

GUISetState()
Global $Pos1 = WinGetPos($Parent)
GUIRegisterMsg($WM_GETMINMAXINFO, "StayProportional")
GUIRegisterMsg($WM_EXITSIZEMOVE, "Setway")

Do
    Sleep(15)
Until GUIGetMsg() = -3


Func StayProportional($hWnd, $Msg, $wParam, $lParam)
    
    If $hWnd <> $Parent Then Return
    $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    Local $_pos = WinGetPos($Parent)
    If Not $wayset Then
        If $_pos[2] <> $Pos1[2] Then
            $k = False
            $wayset = True
        EndIf
    
        If $_pos[3] <> $Pos1[3] Then
            $k = True;we set the width according to the ht
            $wayset = True
        EndIf
    EndIf
    
    If Not $wayset Then;allow width and ht to change
        DllStructSetData($minmaxinfo, 8, 0)
        DllStructSetData($minmaxinfo, 10, @DesktopHeight)
        DllStructSetData($minmaxinfo, 7, 0)
        DllStructSetData($minmaxinfo, 9, @DesktopWidth)
    Else
        If $k Then;set wid
            DllStructSetData($minmaxinfo, 7, $_pos[3] * ($GUISize[0] / $GUISize[1]))
            DllStructSetData($minmaxinfo, 9, $_pos[3] * ($GUISize[0] / $GUISize[1]))
        Else
            DllStructSetData($minmaxinfo, 8, $_pos[2] * ($GUISize[1] / $GUISize[0]))
            DllStructSetData($minmaxinfo, 10, $_pos[2] * ($GUISize[1] / $GUISize[0]))
        EndIf
    EndIf
    Return 0
EndFunc  ;==>StayProportional


Func SetWay()
    $wayset = False
    $k = False
    $Pos1 = WinGetPos($Parent)
EndFunc  ;==>SetWay
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thats good, I didn't realize that would work. The way you've done it you can only resize by dragging the width. I played with this and found it's a bit more difficult to make it work from dragging the height as well, but here's a way that works.

:)

Really nice, martin! You've quite lost me, I'm afraid, as to when each of those registered funcs get called and how they interact...the only thing is that dragging by any corner other than the bottom-right can result in the window moving in a non-intuitive way. At first, I was just going to ask where one might throw a WinMove command into the mix so that the corner opposite to the one you've grabbed always remains stationary, but upon further playing, I realized that the odd window movement when dragging a corner is dependant on which direction the mouse is moved first in a corner dragging opertation. I've added WinSetTitle($Parent,"",$k&", "&$wayset) directly before the Return at the end of StayProportional() and found:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bottom-right corner drag: always works as expected

if the first drag movement is horizontal, $k is false, $wayset is true

if the first drag movement is vertical, $k is true, $wayset is true

top-right corner drag: sometimes works as expected

if the first drag movement is horizontal, $k is false, $wayset is true, and the window has a non-intuitive vertical movement

if the first drag movement is vertical, $k is true, $wayset is true, and it works as expected

bottom-left corner drag: sometimes works as expected

if the first drag movement is horizontal, $k is false, $wayset is true, and it works as expected

if the first drag movement is vertical, $k is true, $wayset is true, and the window has a non-intuitive horizontal movement

top-left corner drag: never works as expected

if the first drag movement is horizontal, $k is false, $wayset is true, and the window has a non-intuitive vertical movement

if the first drag movement is vertical, $k is true, $wayset is true, and the window has a non-intuitive horizontal movement

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can you think of any way to check for these conditions and WinMove() the GUI so that the opposite corner as you're dragging from remains stationary? The only thing I can think of is that $k needs to be set more frequently than merely at the beginning of the drag operation. However, when I added $Pos1 = WinGetPos($Parent) after the If statements in StayProportional() where $k is set, the behavior remained:'(. I just can't think of another way to do this; maybe this is as good as it gets.

"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

:)

Really nice, martin! You've quite lost me, I'm afraid, as to when each of those registered funcs get called and how they interact...the only thing is that dragging by any corner other than the bottom-right can result in the window moving in a non-intuitive way. At first, I was just going to ask where one might throw a WinMove command into the mix so that the corner opposite to the one you've grabbed always remains stationary, but upon further playing, I realized that the odd window movement when dragging a corner is dependant on which direction the mouse is moved first in a corner dragging opertation. I've added WinSetTitle($Parent,"",$k&", "&$wayset) directly before the Return at the end of StayProportional() and found:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bottom-right corner drag: always works as expected

if the first drag movement is horizontal, $k is false, $wayset is true

if the first drag movement is vertical, $k is true, $wayset is true

top-right corner drag: sometimes works as expected

if the first drag movement is horizontal, $k is false, $wayset is true, and the window has a non-intuitive vertical movement

if the first drag movement is vertical, $k is true, $wayset is true, and it works as expected

bottom-left corner drag: sometimes works as expected

if the first drag movement is horizontal, $k is false, $wayset is true, and it works as expected

if the first drag movement is vertical, $k is true, $wayset is true, and the window has a non-intuitive horizontal movement

top-left corner drag: never works as expected

if the first drag movement is horizontal, $k is false, $wayset is true, and the window has a non-intuitive vertical movement

if the first drag movement is vertical, $k is true, $wayset is true, and the window has a non-intuitive horizontal movement

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Can you think of any way to check for these conditions and WinMove() the GUI so that the opposite corner as you're dragging from remains stationary? The only thing I can think of is that $k needs to be set more frequently than merely at the beginning of the drag operation. However, when I added $Pos1 = WinGetPos($Parent) after the If statements in StayProportional() where $k is set, the behavior remained:'(. I just can't think of another way to do this; maybe this is as good as it gets.

You've tested it a lot more than I did! It doesn't work so well does it? I tried playing with it again but I'm afraid haven't made any improvement.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...