Jump to content

Best strategy for scaleable / maximize-able program ?


Recommended Posts

I often develop small helper apps for different customers, and they are happy. But from time to time  I am facing the problem that customers have a screen that is much bigger than others, and I am asked if my application is resizeable or can be maximized.

I have not yet walked down that path, and so my applications are always fixed-size.

What is the best strategy I should take for making an application resizeable ? I am guessing that the actual parameters for the GUI is simple, but what about making controls move around nicely, what about calculating font sizes, positions etc - do you (MVPs and other wizards out there) calculate position by percentage of window size ?

I would be happy to see some kind of conceptual application, does not have to do anything except perhaps show different controls.

Thanks.

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

  • Moderators

Myicq,

Look at GUICtrlSetResizing - Windows then does all (well most of) the work for you. Although you sometimes have to tweak a bit if you have controls which need to remain in perfect alignment (I needed a label with an UpDown Input on each side) - then ControlGetPos and ControlMove come in handy. Finally, if you want the font size of the controls to change as well, then you need to set up a $WM_SIZE handler to recognise the new size and reset the font accordingly. ;)

Let me know if you want more help on this - I have a couple of scripts that use these techniques very succcessfully. :)

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

M23 - it would be great to have such demo, if I could pry it from your treasure chest ? :)

Also to show effects of settings you can apply to objects on scaling, I assume settings on how they "glue" to different sides of a window ? (did not make experiments with this in AutoIT, but I did try something like this in Perl with Tcl/Tk)

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

  • Moderators

Myicq,

I thought you might ask - so here is one I created earlier! :D

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <UpDownConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>

$iFontSize = 8.5

; Set resize mode for controls
Opt("GUIResizeMode", $GUI_DOCKAUTO)

$hGUI = GUICreate("Resizer", 500, 400, Default, Default, BitOR($WS_SIZEBOX, $WS_SYSMENU))

GUICtrlCreateGroup(" One ", 10, 10, 230, 270)
GUICtrlCreateLabel("Group One", 30, 30, 190, 20)

GUICtrlCreateGroup(" Two ", 10, 290, 230, 80)
GUICtrlCreateLabel("Group Two", 30, 310, 190, 20)

GUICtrlCreateGroup(" Three ", 260, 10, 230, 360)
GUICtrlCreateLabel("Group Three", 280, 30, 190, 20)

GUICtrlCreateLabel("Hours Input", 20, 70, 60, 17)
$cInput_Hour = GUICtrlCreateInput("0", 80, 67, 19, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH)
Local $cUpDown_Hour = GUICtrlCreateUpdown($cInput_Hour, BitOR($UDS_WRAP, $UDS_ALIGNLEFT))
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH)
GUICtrlSetLimit($cUpDown_Hour, 9, 0)
$cInput_Min = GUICtrlCreateInput("0", 125, 67, 19, 20)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH)
Local $cUpDown_Min = GUICtrlCreateUpdown($cInput_Min, $UDS_WRAP)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH)
GUICtrlSetLimit($cUpDown_Min, 11, 0)
$cHours_Label = GUICtrlCreateLabel("0:00", 99, 68, 25, 18, BitOR($SS_CENTER, $SS_CENTERIMAGE))


$cButton_1 = GUICtrlCreateButton("Button 1", 280, 90, 190, 50)
$cButton_2 = GUICtrlCreateButton("Button 2", 280, 160, 190, 50)
$cButton_3 = GUICtrlCreateButton("Button 3", 280, 230, 190, 50)
$cButton_4 = GUICtrlCreateButton("Button 4", 280, 300, 190, 50)

; Set last control for font resizing
$iLast_Control = GUICtrlCreateDummy()

GUISetState()

GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)

    #forceref $iMsg, $wParam, $lParam

    If $hWnd = $hGUI Then
        ; Calculate required font size
        Local $aGUI_Size = WinGetClientSize($hGUI)
        $iFontSize = Int(2 * (.25 + (8 * $aGUI_Size[0] / 500))) / 2
        ; Reset font size for all controls on main GUI
        For $i = 0 To $iLast_Control
            GUICtrlSetFont($i, $iFontSize)
        Next
    EndIf

    ; Reset positions of the inputs, updowns and labels
    Local $aInputPos = ControlGetPos($hGUI, "", $cInput_Hour)
    Local $aLabelPos = ControlGetPos($hGUI, "", $cHours_Label)
    ControlMove($hGUI, "", $cHours_Label, $aInputPos[0] + $aInputPos[2], $aLabelPos[1])
    $aLabelPos = ControlGetPos($hGUI, "", $cHours_Label)
    ControlMove($hGUI, "", $cUpDown_Min, $aLabelPos[0] + $aLabelPos[2], $aInputPos[1])

EndFunc   ;==>_WM_SIZE

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    ; If it was an update message from the inputs
    If BitShift($wParam, 16) = $EN_CHANGE Then
        Switch BitAND($wParam, 0xFFFF)
            Case $cInput_Hour, $cInput_Min
                ; Set the label to the new total
                GUICtrlSetData($cHours_Label, GUICtrlRead($cInput_Hour) & ":" & StringFormat("%02i", 5 * GUICtrlRead($cInput_Min)))
        EndSwitch
    EndIf

EndFunc   ;==>_WM_COMMAND
In my original script I had the UpDown/Label controls in a separate fixed-size (dependant on main GUI size) child GUI so that I only had to play with their positions once as the child was created - which is why I did not mention the requirement for a handler in both cases earlier. I have now moved that code into the WM_SIZE handler so that it fires each time you resize the GUI. ;)

Please ask if you have any questions on the code. :)

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