Jump to content

Window size versus text font size ?


guiguy
 Share

Go to solution Solved by guiguy,

Recommended Posts

I am struggling to figure out how to size a window to a particular text font so it will scale correctly across differing displays.

What are the units for the window width and height used by GUICreate? are they pixels?

For example, I want to size the height of a window for a 12 point font.
Function _WinAPI_TwipsPerPixelX() tells me my display has 15 twips per pixel.
(A twip is 1/1440 of and inch and is also 1/20 of a point)
So 12 points X 20 twips/point X 1/15 pixels/twip = 16 pixels

If I create a window 16 (pixels) high the text is chopped off.
I actually have to use a height of 40 to get decent looking text.

Using function _WinAPI_GetTextMetrics() I find the height of the 12 point font is 12, it has an ascender height of 9 and a descender height of 3.
Assuming those units are all in points summing up gives 23 points.
23 points X 20 twips/point X 1/15 pixels/twip = 30.67 pixels.

If I create a window 31 high the text is still chopped off - it needs a height of 40.

What is going on here?

-- guiguy --

Link to comment
Share on other sites

Do you mean - you want to write DPI Aware app ?

Look in my sign maybe this is what you need.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

You do not need to follow all my signatures entry just Writing DPI Awareness App - workaround

Edit:

unless you just want to ;)

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

You might also want to take a look at Melba23's StringSize UDF

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

mLipok -
Thanks for the information.
This tells me how to write an app so the GUI will scale properly across different displays.
Great stuff!

BrewManNH -
Thanks for the pointer to Melba23's StringSize UDF.
This gave me the clue to what I was looking for.

StringSize gives me numbers similar to my own calculations, still leaving me with a mystery.
I am using the numbers to size an Input Control (GUICtrlCreateInput) with an associated Up/Down control (GUICtrlCreateUpdown).
It looks like the Input Control reduces the actual input area by an unknown margin.
The Up/Down control reduces the input area width by an additional amount.
I had not expected this.  >_<
Shouldn't something like this be mentioned in the help files?
I am distressed at having to resort to trial and error to find the proper sizes for GUI elements.
I'm a newbie, so maybe I'm overlooking something?

Thanks again to mLipok and BrewManNH for their responses.  :thumbsup:
 

-- guiguy --

Link to comment
Share on other sites

  • Moderators

guiguy,

My StringSize UDF usually gives you return values sufficiently large to cope with the small margins inside controls. And of course UpDowns reduce the size of the input in which they are located, just as scrollbars reduce the usable size of controls in which they appear, but that is a Windows "feature".

Please post some code showing what you are trying to do - then we can see if we can develop a suitable algorithm to help you. Without code we are reduced to offering simple advice - with it we can perhaps provide some concrete solutions.

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

Sure thing Melba23.
Here is an example that shows the issue.
NOTE: This requires the StringSize UDF in the run directory !!

It displays a sequence of windows:
1. This shows an input control sized exactly to the text height and width, with no up/down control attached.
You can see there is effectively no input area.
Press Continue.

2. This window shows an input control sized to the text height but with an additional margin added to the width.
Again the input area is clipped.
Press Continue.

3. This window shows an input control sized with an additional margin added to both the width and height.
Now the input area is usable.
Press Continue.

4. This shows an input control with an up/down control attached.
It is sized with the same additional margins as the previous window.
The input area is clipped by the up/down control.
Press Continue.

5. This shows an input control with the up/down control attached.
The width margin has been increased and now the input area is fully functional.
Press Exit
 

#comments-start
###########################################################
# Example of Input Control clipping the input area
###########################################################
#comments-end
#include "StringSize.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Const $Root_Width = 500
Const $Root_Height = 300

Const $Font_Size = 12
Const $Font_Weight = 400
Const $Font_Attr = 0
Const $Font_Name = "Arial"
Const $FONT_QUAL_CLEARTYPE = 5

Const $Input_Left = 200
Const $Input_Top = 150
Const $Input_Style = $WS_SIZEBOX
Const $Input_Ex_Style = $WS_EX_OVERLAPPEDWINDOW

Const $Btn_Width = 100
Const $Btn_Left = Int(($Root_Width - $Btn_Width) / 2)
Const $Btn_Hght = 50
Const $Btn_Top  = $Root_Height - $Btn_Hght - 10

Const $InputText = "99"
Const $AppTitle = "Example of Input Control clipping"

Global $Waiting = true
Global $Input_HNDL
Global $Up_Dn_HNDL

#comments-start
#----------------------------------------------------------
# Main Routine
#----------------------------------------------------------
#comments-end

; Create a root window
$Root_HNDL = GUICreate($AppTitle, _
    $Root_Width, $Root_Height, -1, -1, -1, -1)
CheckForError($Root_HNDL, "Error creating the root GUI window")

; Set the font
$Rtn = GUISetFont($Font_Size, $Font_Weight, $Font_Attr, _
    $Font_Name, $Root_HNDL, $FONT_QUAL_CLEARTYPE)
CheckForError($Rtn, "Error setting the root GUI font attributes")

; Calculate the size of the text string
Local $tSize = _StringSize($InputText, $Font_Size, $Font_Weight, $Font_Attr, $Font_Name)
CheckForError($tSize, "StringSize error "& String(@error))
Global $Font_Height = $tSize[1]
Global $Str_Width = $tSize[2]

; Display the text size
$Info_HNDL = GUICtrlCreateLabel( _
    "Text =[" & $InputText & "], height = " & String($Font_Height) & _
    ", width = " & String($Str_Width), 20, 20, 400, 60)
CheckForError($Info_HNDL, "Error creating the root GUI label")

; Add a label to the root window
$Label_HNDL = GUICtrlCreateLabel("Root Label", 20, 60, 400, 60)
CheckForError($Label_HNDL, "Error creating the root GUI label")

; Add a button to the root window
Global $Pause_HNDL = GUICtrlCreateButton("Pause", $Btn_Left, $Btn_Top, _
    $Btn_Width, $Btn_Hght)
CheckForError($Pause_HNDL, "Error creating the button")

; Add the button callback
$Rtn = GUICtrlSetOnEvent($Pause_HNDL, "ProcessButton")
CheckForError($Rtn, "Error setting the button callback")
    
; System events callback
$Rtn = GUISetOnEvent($GUI_EVENT_CLOSE, "ProcessSysEvent", $Root_HNDL)
CheckForError($Rtn, "Error setting the system event callback")

; Show first example
$heightMargin = 0
$widthMargin  = 0
$upDown = False
$title = "Input Control with no Up/Down and no margins"
$Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title)
Pause("Continue")

; Show second example
$heightMargin = 0
$widthMargin  = 20
$upDown = False
$title = "Input Control with no Up/Down and height margin = " & _
    String($heightMargin) & _
    ", width margin = " & String($widthMargin)
$Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title)
Pause("Continue")

; Show third example
$heightMargin = 20
$widthMargin  = 20
$upDown = False
$title = "Input Control with no Up/Down and height margin = " & _
    String($heightMargin) & _
    ", width margin = " & String($widthMargin)
$Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title)
Pause("Continue")

; Show fourth example
$heightMargin = 20
$widthMargin  = 20
$upDown = True
$title = "Input Control with Up/Down and height margin = " & _
    String($heightMargin) & _
    ", width margin = " & String($widthMargin)
$Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title)
Pause("Continue")

; Show fifth example
$heightMargin = 20
$widthMargin  = 45
$upDown = True
$title = "Input Control with Up/Down and height margin = " & _
    String($heightMargin) & _
    ", width margin = " & String($widthMargin)
$Rtn = MakeGUI($heightMargin, $widthMargin, $upDown, $title)
Pause("Exit")

#comments-start
#----------------------------------------------------------
# Func MakeGUI
#----------------------------------------------------------
# Makes an Input Control
#----------------------------------------------------------
#comments-end
Func MakeGUI($Hmargin, $Wmargin, $UpDnFlag, $msg)
    ; Set the label text
    $Rtn = GUICtrlSetData($Label_HNDL, $msg)
    CheckForError($Rtn, "Error setting the root GUI label")
    
    ; Add the input control to the root window
    $Input_HNDL = GUICtrlCreateInput($InputText, $Input_Left, _
        $Input_Top, $Str_Width + $Wmargin, _
        $Font_Height + $Hmargin, $Input_Style, $Input_Ex_Style)
    CheckForError($Input_HNDL, "Error creating the hours input GUI")
    
    ; Add the Up/Down Control if requested
    if ($UpDnFlag = true) then
        $Up_Dn_HNDL = GUICtrlCreateUpdown($Input_HNDL)
        CheckForError($Up_Dn_HNDL, "Error creating the up/down control")
    else
        $Up_Dn_HNDL = 0
    endif
    
    ; Display the GUI
    $Rtn = GUISetState(@SW_SHOW, $Root_HNDL)
    CheckForError($Rtn, "Error showing the GUI")
EndFunc  ;MakeGUI

#comments-start
#----------------------------------------------------------
# Func ProcessButton
#----------------------------------------------------------
# Called when the button is pressed
#----------------------------------------------------------
#comments-end
Func ProcessButton()
    ; Flag we are done waitng
    $Waiting = false
EndFunc

#comments-start
#----------------------------------------------------------
# Func ProcessSysEvent
#----------------------------------------------------------
# Processes a click on the root GUI button.
#----------------------------------------------------------
#comments-end
Func ProcessSysEvent()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            $Waiting = false
            Exit 0
        Case Else
            ; Null
    EndSelect
endFunc   ; ProcessSysEvent

#comments-start
#----------------------------------------------------------
# Func Pause
#----------------------------------------------------------
# Exits application with a message and an exit return code
#----------------------------------------------------------
#comments-end
Func Pause($Pmsg)
    ; Set the button label
    $Rtn = GUICtrlSetData($Pause_HNDL, $Pmsg)
    CheckForError($Rtn, "Error setting the button label")
    
    ; Now wait for the button to be pressed
    AutoItSetOption("GUIOnEventMode", 1) ; Enable event mode
    CheckSysError(@error, "Error enabling event mode")
    
    $Waiting = true
    while ($Waiting = true)
        sleep(100)
    Wend
    AutoItSetOption("GUIOnEventMode", 0) ; Disable event mode
    CheckSysError(@error, "Error disabling event mode")
    
    ; Hide the GUI
    $Rtn = GUISetState(@SW_HIDE, $Root_HNDL)
    CheckForError($Rtn, "Error showing the GUI")
    
    ; Tear down the Input Control GUI
    $Rtn = GUICtrlDelete($Input_HNDL)
    CheckForError($Rtn, "Error deleting the input control")
    if ($Up_Dn_HNDL <> 0) then
        $Rtn = GUICtrlDelete($Up_Dn_HNDL)
        CheckForError($Rtn, "Error deleting the up/down control")
    Endif
EndFunc  ;Pause

#comments-start
#----------------------------------------------------------
# Func Abort
#----------------------------------------------------------
# Exits application with a message and an exit return code
#----------------------------------------------------------
#comments-end

Func Abort($Msg = "Aborting...", $Rtn = -1)
    Const $MSGBOX_STOPSIGN     = 0x10

    MsgBox(BitOR(0, $MSGBOX_STOPSIGN), $AppTitle, _
        $Msg & ", aborting...")
    Exit $Rtn
EndFunc

#comments-start
#----------------------------------------------------------
# Func CheckForError
#----------------------------------------------------------
# Tests the provided return code for error, and aborts with 
# a message if there is one.
# Error => code is zero
#----------------------------------------------------------
#comments-end
Func CheckForError($code, $msg)
    if $code = 0 then
        Abort($msg)
    endif
EndFunc  ;CheckForError

#comments-start
#----------------------------------------------------------
# Func CheckSysError
#----------------------------------------------------------
# Tests the provided return code for system error, and
# aborts with a message if there is one.
# Error => code is non-zero
#----------------------------------------------------------
#comments-end
Func CheckSysError($code, $msg)
    if $code <> 0 then
        Abort($msg)
    endif
EndFunc   ; CheckSysError

The margins above had to be determined by trial and error.
They vary depending on the combination of style and extended style used in the GUICtrlCreateInput call.

I don't think you need to change the StringSize algorithm, I just need to know by how much the input area width and height is reduced.
I hate having to determine these by trial and error.

Thanks for your interest in this issue.

-- guiguy --

Link to comment
Share on other sites

  • Moderators

guiguy,

That is far too complicated for a simple coder like me. And why are you applying $WS_SIZEBOX& $WS_EX_OVERLAPPEDWINDOW styles to an inputbox?

Here is a simpler script which shows how to measure the width of an UpDown and the internal borders of a control. When I apply those factors the inputs are suitably sized when I test - are they for you?

#include <GUIConstantsEx.au3>
#include <StringSize.au3>
#include <WinAPI.au3>
#include <EditConstants.au3>

Global $sText = "99"

Global $aSizes[] = [8, 12, 18, 24, 36, 48]

Global $aControls[4]

; Get width of system scrollbar - updowns are the same width
Global $iScroll_Width = _WinAPI_GetSystemMetrics(2) ; SM_CXVSCROLL
ConsoleWrite("Scroll width: " & $iScroll_Width & @CRLF)
; Get width of control frame
Global $iBorder = _WinAPI_GetSystemMetrics(7) ; SM_CXFIXEDFRAME
ConsoleWrite("Border width: " & $iBorder & @CRLF)

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

; Create a button to take focus
$cButton = GUICtrlCreateButton("Looks pretty good to me!", 10, 200, 200, 30)
GUICtrlSetFont($cButton, 8, 400, 0, "")
GUICtrlSetState($cButton, $GUI_FOCUS)

GUISetState()

For $i = 0 To UBound($aSizes) - 1

    Global $iFont_Size = $aSizes[$i], $iFont_Weight = 400, $iFont_Attrib = 0, $sFont_Name = "Arial"
    ConsoleWrite("Font Size: " & $aSizes[$i] & @CRLF)

    ; Set GUI default font
    GUISetFont($iFont_Size, $iFont_Weight, $iFont_Attrib, $sFont_Name)

    ; Check size of string at this size
    $aSize = _StringSize($sText, $iFont_Size, $iFont_Weight, $iFont_Attrib, $sFont_Name)
    $iStr_W = $aSize[2]
    $iStr_H = $aSize[3]
    ConsoleWrite("Text size: " & $iStr_W & " - " & $iStr_H & @CRLF)

    ; Create a basic input with border offsets
    $aControls[0] = GUICtrlCreateInput($sText, 10, 10, $iStr_W + ($iBorder * 2), $iStr_H, -1)

    ; Create an input with an updown and allow for the reduction in width (and its own borders!)
    $aControls[1] = GUICtrlCreateInput($sText, 10, 100, $iStr_W + ($iBorder * 4) + $iScroll_Width, $iStr_H, -1)
    $aControls[2] = GUICtrlCreateUpdown(-1)

    ; Create a label to show StringSize works for labels
    $aControls[3] = GUICtrlCreateLabel($sText, 10, 300, $iStr_W, $iStr_H)
    GUICtrlSetBkColor(-1, 0xFFCCCC)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $cButton
                ExitLoop
        EndSwitch
    WEnd

    ; Delete controls
    For $j = 0 To 3
        GUICtrlDelete($aControls[$j])
    Next

Next
What I find interesting is that for certain middling font sizes the text starts quite well inset into the input and playing with the justification seems to make no difference to this. Obviously a Windows "feature!

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

  • Solution

Ahhh, you are indeed wise Melba23.
Thank you for revealing the secret of _WinAPI_GetSystemMetrics   :)

I was playing around with different styles because I wanted a nice looking decoration around the input control.
$WS_SIZEBOX looked really good to me, but of course it lets the user resize the control.
$WS_EX_OVERLAPPEDWINDOW is a reasonable alternative.

Your script does give suitably sized controls as I see it.
Thank you for your input and help.
 

-- guiguy --

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