billthecreator Posted March 27, 2009 Share Posted March 27, 2009 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 More sharing options...
Tvern Posted March 28, 2009 Share Posted March 28, 2009 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 More sharing options...
Moderators Melba23 Posted March 28, 2009 Moderators Share Posted March 28, 2009 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tvern Posted March 28, 2009 Share Posted March 28, 2009 Id adjust that to the following: expandcollapse popup#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 More sharing options...
billthecreator Posted March 28, 2009 Author Share Posted March 28, 2009 Thank you all. that helped a lot. [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 More sharing options...
ResNullius Posted March 28, 2009 Share Posted March 28, 2009 For an automatic constant resizing, see martin's code here http://www.autoitscript.com/forum/index.ph...mp;#entry498990 and http://www.autoitscript.com/forum/index.ph...st&p=577048 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now