Jump to content

Problem with text scaling multiple GUI


Daemante2018
 Share

Recommended Posts

I have an interesting issue. I used a function of @Melba23's and it works great to scale the text when one of my GUI are resized. The interesting part is that when resizing "Second GUI" the text in the "About" GUI ALSO resizes. Not sure what the problem is or how to isolate the function to only "Second GUI".

This is the function I borrowed from Melba23:

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam
    If $hWnd = $SecondG Then
        ; Calculate required font size
        Local $aGUI_Size = WinGetClientSize($SecondG)
        $iFontSize = Int(2 * (.25 + (8 * $aGUI_Size[0] / $iGUIInitSize))) / 2
        ; Reset font size for all controls on main GUI
        For $i = 0 To $iLast_Control
            GUICtrlSetFont($i, $iFontSize)
        Next
    EndIf
EndFunc   ;==>_WM_SIZE

Here is the full code:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <GUIEdit.au3>
#include <ComboConstants.au3>
#include <TreeViewConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <GUIListBox.au3>
#include <GUIComboBox.au3>

$MainGUI = GUICreate("Main GUI", 337, 21, -1, 7, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$File = GUICtrlCreateMenu("&File")
$Exit = GUICtrlCreateMenuItem("Exit", $File)
$Menu = GUICtrlCreateMenu("&Menu")
$SecondGUI = GUICtrlCreateMenuItem("Second GUI", $Menu)
$Help = GUICtrlCreateMenu("&Help")
$About = GUICtrlCreateMenuItem("About", $Help)
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xB4B4B4)
$DummyLabel = GUICtrlCreateLabel("", 32, 112, 4, 4)
Dim $MainGUI_AccelTable[2][2] = [["^!f", $File], ["^!m", $Menu]]
GUISetAccelerators($MainGUI_AccelTable)
GUISetState(@SW_SHOW)

$About1 = GUICreate("About", 246, 288, -1, -1, $WS_SYSMENU, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUICtrlSetResizing(-1, 0)
$Version = GUICtrlCreateLabel("Version 1.0", 175, 266, 57, 17)
$Dev = GUICtrlCreateLabel("Developed by SantaClaus", 23, 191, 200, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$CA = GUICtrlCreateLabel("www.google.ca", 22, 216, 200, 20)
GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0078D7)
GUICtrlSetCursor(-1, 0)
$COM = GUICtrlCreateLabel("www.google.com", 31, 235, 179, 20)
GUICtrlSetFont(-1, 10, 800, 4, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0078D7)
GUICtrlSetCursor(-1, 0)

; Set resize mode for controls
Opt("GUIResizeMode", $GUI_DOCKAUTO)
Local $iGUIInitSize = 343
$SecondG = GUICreate("Second GUI", $iGUIInitSize, 611, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xFFFFFF)
$SELECTOPTION = GUICtrlCreateCombo("Select OPTION", 8, 16, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Option1|Options2")
GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif")
GUICtrlSetCursor(-1, 0)
$OPTIONLIST = GUICtrlCreateList("", 8, 64, 325, 524, BitOR($LBS_NOSEL, $WS_VSCROLL))
GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif")
$iLast_Control = GUICtrlCreateDummy()
GUISetState(@SW_HIDE)
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")

_GUITWO()

While 1
    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $MainGUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    ;WinKill("About")
                    Exit
                Case $Exit
                    Exit
                Case $About
                    GUISetState(@SW_DISABLE, $MainGUI)
                    _QGAbout($About1)
                    GUISetState(@SW_ENABLE, $MainGUI)
                Case $SecondGUI
                    _GUITWO()
            EndSwitch
        Case $SecondG
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $SecondG)
            EndSwitch
    EndSwitch
WEnd
Func _QGAbout($AboutGUI)
    GUISetState(@SW_SHOW, $AboutGUI)
    While 1
        $nMsg = GUIGetMsg(1)
        If $nMsg[1] = $AboutGUI Then
            Switch $nMsg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_HIDE, $AboutGUI)
                    ExitLoop
                Case $CA
                    ShellExecute("www.google.ca")
                Case $COM
                    ShellExecute("www.google.com")
            EndSwitch
        EndIf
    WEnd
EndFunc   ;==>_QGAbout
Func _GUITWO()
    GUISetState(@SW_SHOW, $SecondG)
EndFunc   ;==>_GUITWO

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam
    If $hWnd = $SecondG Then
        ; Calculate required font size
        Local $aGUI_Size = WinGetClientSize($SecondG)
        $iFontSize = Int(2 * (.25 + (8 * $aGUI_Size[0] / $iGUIInitSize))) / 2
        ; Reset font size for all controls on main GUI
        For $i = 0 To $iLast_Control
            GUICtrlSetFont($i, $iFontSize)
        Next
    EndIf
EndFunc   ;==>_WM_SIZE

If you run the script and then open the "Help" menu, open the "About" GUI and then resize "Second GUI" you will see what happens. 

This also still happens whether or not the "About" GUI is open. It will resize the text regardless.

Example GUI issue.au3

Edited by Daemante2018
Link to comment
Share on other sites

It seems like all controls are resized

For $i = 0 To $iLast_Control
            GUICtrlSetFont($i, $iFontSize)
        Next

Maybe the best option would be to filter the results for the control resizing.

If this is doing what i think it does, all controls are being resized atm, so if you had a label in the main gui i think that one would also be resized.

I have to do some tests when i get home. how, where is this value set? $iLast_Control

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

It is a dummy control:

; Set resize mode for controls
Opt("GUIResizeMode", $GUI_DOCKAUTO)
Local $iGUIInitSize = 343
$SecondG = GUICreate("Second GUI", $iGUIInitSize, 611, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xFFFFFF)
$SELECTOPTION = GUICtrlCreateCombo("Select OPTION", 8, 16, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Option1|Options2")
GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif")
GUICtrlSetCursor(-1, 0)
$OPTIONLIST = GUICtrlCreateList("", 8, 64, 325, 524, BitOR($LBS_NOSEL, $WS_VSCROLL))
GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif")
$iLast_Control = GUICtrlCreateDummy() <-----------------------------------
GUISetState(@SW_HIDE)
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")

That line was actually part of the function in the post I found. Part of Melbas suggestion/code.

https://www.autoitscript.com/forum/topic/191286-automatically-resize-font/

Function doesn't work without that line and the For, Next statement.

Edited by Daemante2018
Link to comment
Share on other sites

  • Moderators

Daemante2018,

Quote

when resizing "Second GUI" the text in the "About" GUI ALSO resizes

This happens because the WM_SIZE handler is currently coded to change the font in every control that has been created up to the  $iLast_Control dummy. So resizing any GUI in the script will cause every control up to that point in the script to undergo a font change.

What you need to do is to limit the controls to change to those within the resizeable GUI - like this:

; Set resize mode for controls
Opt("GUIResizeMode", $GUI_DOCKAUTO)
Local $iGUIInitSize = 343
$SecondG = GUICreate("Second GUI", $iGUIInitSize, 611, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
GUISetFont(12, 400, 0, "MS Sans Serif")
GUISetBkColor(0xFFFFFF)
$iFirstControl = GUICtrlCreateDummy() ; Start of control list <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$SELECTOPTION = GUICtrlCreateCombo("Select OPTION", 8, 16, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Option1|Options2")
GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif")
GUICtrlSetCursor(-1, 0)
$OPTIONLIST = GUICtrlCreateList("", 8, 64, 325, 524, BitOR($LBS_NOSEL, $WS_VSCROLL))
GUICtrlSetFont(-1, 12, 0, 0, "MS Sans Serif")
$iLast_Control = GUICtrlCreateDummy() ; End of control list <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetState(@SW_HIDE)
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")

and then change the handler code as follows:

; Reset font size for all controls on main GUI
For $i = $iFirstControl To $iLast_Control
    GUICtrlSetFont($i, $iFontSize)
Next

Now only the controls in the Second GUI will have their font adjusted.

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

Exactly, that's what i meant when i said "filter the results for the control resizing."

@Melba23: So does it work like in sequence in the script? That's how it knows where to start and stop?

I assume it could be done through the ID's of each control no? If they're in sequence.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

  • Moderators

careca & anyone else reading,

I have explained the "numbering" of AutoIt ControlIDs many times - here is a good example which should make it all clear.

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

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