Jump to content

Resize GUI & controls font


Recommended Posts

Hi everybody :)
The purpose of this post is to indicate how simple it is to change your "too small" Gui for a bigger one, resizing (or not) the associated controls font.

1) SampleControls.au3
The original example is found in AutoIt package (subfolder ..\Example\GUI) and displays its GUI like this :

SampleControls.png.5a84a106440cd3e2a89e1f99ca447f35.png

2) "SampleControls (resizable Gui).au3" [ based on SampleControls.au3 ]
If you want to enlarge the Gui because it appears too small depending on your screen resolution, here are the changes to apply, where the Gui is resizable but the control fonts are unchanged :

; Added
; -----
#include <StaticConstants.au3>  ; center the label control
#include <WindowsConstants.au3> ; $WS_OVERLAPPEDWINDOW

Opt("GUIResizeMode", $GUI_DOCKAUTO) ;0 = (default) keep default control resizing , <1024 = any type of resizing 

; Modified
; --------
; GUICreate("Sample GUI", 400, 400)
GUICreate("Sample GUI", 400, 400, -1, -1, $WS_OVERLAPPEDWINDOW)

; GUICtrlCreateLabel("Green" & @CRLF & "Label", 350, 165, 40, 40)
GUICtrlCreateLabel("Label", 350, 165, 40, 40, BitOr($SS_CENTERIMAGE, $SS_CENTER))

SampleControls(resizableGui).png.fef7c54cb7eae3b85271b32be681a224.png

3) "SampleControls (resizable Gui & fonts).au3" [ based on "SampleControls (resizable Gui).au3" ]
If you want to enlarge the Gui AND resize the controls font so they appear bigger, here are the changes to apply :

; Added
; -----
Global $hGUI, $iGUIInitSizeW = 400, $iLast_DummyControl
$iLast_DummyControl = GUICtrlCreateDummy() ; just before GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam

    If $hWnd = $hGUI Then
        Local Static $iFontSize_Old = 0
        Local $iParentW = BitAND($lParam, 0xFFFF) ; low word (new width of the client area)
        ; Local $iParentH = BitShift($lParam, 16) ; high word (new height of the client area)

        Local $iFontSize = Int(2 * (.5 + (8 * $iParentW / $iGUIInitSizeW))) / 2

        If $iFontSize_Old <> $iFontSize Then
            For $i = 3 To $iLast_DummyControl - 1 ; 1st control in GUI is always 3
                GUICtrlSetFont($i, $iFontSize)
            Next
            $iFontSize_Old = $iFontSize
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

; Modified
; --------
; GUICreate("Sample GUI", 400, 400, -1, -1, $WS_OVERLAPPEDWINDOW)
$hGUI = GUICreate("Sample GUI", $iGUIInitSizeW, 400, -1, -1, $WS_OVERLAPPEDWINDOW)

SampleControls(resizableGuifonts)1.png.ca910e92d95991e7024e85f8c6b4cbf7.png

Below, a bolder font appears when more resizing is applied to the GUI :

SampleControls(resizableGuifonts)2.png.212f5cb032e18c1b51457208fbe44a11.png

I just tried all this on a personal script and the results looked fine, hope it will be same for you.
Big thanks to @Melba23 for his script, found here

Mods, I don't know where this post should be placed on the Forum. Please move it if you think its place isn't the appropriate one, thanks.

Edited by pixelsearch
added 4th pic
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...