Jump to content

Resizing a GUI


Recommended Posts

How would i go about making a GUI that resizes, but keeps the same ratio between width and height?

Say i have a GUI 200px/300px, then when its resized the ratio stays the same.

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Link to comment
Share on other sites

How would i go about making a GUI that resizes, but keeps the same ratio between width and height?

Say i have a GUI 200px/300px, then when its resized the ratio stays the same.

I think you want to use "GUIRegisterMsg($WM_SIZE, 'WM_SIZE')" which will run the function "WM_SIZE($hWnd, $Msg, $wParam, $lParam)" when your window is resized.

Inside that function you can re-resize the window to restore the ratio.

Link to comment
Share on other sites

  • Moderators

billthecreator,

I am feeling generous this morning: ;-)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; When window is resized, run this function
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

Global $iGUIWidth = 300, $iGUIHeight = 200, $fResized = False

$MainGUI = GUICreate("Prop Resize Example", $iGUIWidth, $iGUIHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetState(@SW_SHOW)

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
; Look for resize message
    If $fResized Then
    ; Check if new height is in proportion to width
        If $iGUIWidth / $iGUIHeight <> 300 / 200 Then
            $iGUIHeight = $iGUIWidth * 2 / 3
            WinMove($MainGUI, "", Default, Default, $iGUIWidth, $iGUIHeight)
        EndIf
    ; Reset flag
        $fResized = False
    EndIf
WEnd

Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    $iGUIWidth = BitAND($lParam, 0xFFFF)
    $iGUIHeight = BitShift($lParam, 16)
; Set flag
    $fResized = True
    Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_SIZE

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Id adjust that to the following:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; When window is resized, run this function
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

Global $iGUIWidth = 300, $iGUIHeight = 200, $hResizing = True, $vResizing = True

$MainGUI = GUICreate("Prop Resize Example", $iGUIWidth, $iGUIHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetState(@SW_SHOW)

While GUIGetMsg() <> -3
    If $vResizing Or $hResizing Then
        WinMove($MainGUI, "", Default, Default, $iGUIWidth, $iGUIHeight)
        $vResizing = False
        $hResizing = False
    EndIf
WEnd

Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    If $iGUIHeight <> BitShift($lParam, 16)+36 And ($hResizing = False) Then
        ;resizing vertical, adjust horizontal
        $vResizing = True
        $iGUIHeight = BitShift($lParam, 16)+36
        $iGUIWidth = Round(BitShift($lParam, 16)*1.5)+16
        ;WinMove($MainGUI, "", Default, Default, $iGUIWidth, $iGUIHeight)
        Return $GUI_RUNDEFMSG
    EndIf
    If $iGUIWidth <> BitAND($lParam, 0xFFFF)+16 And ($vResizing = False) Then
        ;resizing horizontal, adjust vertical
        $hResizing = True
        $iGUIWidth = BitAND($lParam, 0xFFFF)+16
        $iGUIHeight = Round(BitAND($lParam, 0xFFFF)/1.5)+36
        ;WinMove($MainGUI, "", Default, Default, $iGUIWidth, $iGUIHeight)
        Return $GUI_RUNDEFMSG
    EndIf
EndFunc  ;==>MY_WM_SIZE

The advantage is that it also works on vertical resizing. For instant updating you can uncomment the winmoves inside the funtion, but I wouldn't reccomend it. (the function should finish as fast as possible and it makes the gui jump all over the place.)

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