argumentum Posted May 26, 2022 Posted May 26, 2022 Exit CheckboxTest() Func CheckboxTest() GUICreate("Size of the square of the Checkbox", 400, 100) GUISetState() GUICtrlSetFont(GUICtrlCreateCheckbox("1", 10, 10, 80), 4) GUICtrlSetFont(GUICtrlCreateCheckbox("2", 100, 10, 100), 18) While 1 Switch GUIGetMsg() Case -3 GUIDelete() ExitLoop EndSwitch WEnd EndFunc I'd like to know the size of the square ( check mark ) of the control, not the size of the control.That goes towards getting the font size to use based on what the OS believes is a good visual size. That makes sense to me for getting a proper size font given the scale of the monitor. Thanks Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
KaFu Posted May 26, 2022 Posted May 26, 2022 The font size does not change the checkbox size for me, only if the control width is reduced, the checkbox becomes smaller for me. CheckboxTest() CheckboxTest2() Exit Func CheckboxTest() GUICreate("Size of the square of the Checkbox", 400, 100) GUISetState() GUICtrlSetFont(GUICtrlCreateCheckbox("1", 10, 10, 80), 4) GUICtrlSetFont(GUICtrlCreateCheckbox("2", 100, 10, 100), 18) While 1 Switch GUIGetMsg() Case -3 GUIDelete() ExitLoop EndSwitch WEnd EndFunc ;==>CheckboxTest Func CheckboxTest2() GUICreate("Size of the square of the Checkbox", 400, 100) GUISetState() GUICtrlSetFont(GUICtrlCreateCheckbox("1", 10, 10, 7), 1) GUICtrlSetFont(GUICtrlCreateCheckbox("2", 100, 10, 100), 29) While 1 Switch GUIGetMsg() Case -3 GUIDelete() ExitLoop EndSwitch WEnd EndFunc ;==>CheckboxTest2 _WinAPI_GetSystemMetrics(71) and _WinAPI_GetSystemMetrics(72) return x and y of "The width of the default menu check-mark bitmap, in pixels." (=15 for me), maybe that's the systems default, and if the width goes below this, the new checkbox size is the control width? OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Solution KaFu Posted May 26, 2022 Solution Posted May 26, 2022 (edited) Oh, seems related to font size somehow, this might lead the way: https://stackoverflow.com/a/20926332 Edited May 26, 2022 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
argumentum Posted May 26, 2022 Author Posted May 26, 2022 ...what a pain. I'm using _WinAPI_SetDPIAwareness() and WM_DPICHANGED to accommodate to scaling 1 to 3.5 and playing with 4 monitors in 2 PCs with ultrawide, 4k, 1920x1200 and a SteamDeck( that did not like for gaming ). All to make sure that the GUI is not blurry. I don't know what to settle on for font size. If you have a functional way to go about it, let me know. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted May 26, 2022 Author Posted May 26, 2022 ...the idea is that given that the ( API created ) title bar and the check mark are well sized for the display/monitor scale, getting that measurement would give me a clue of what size font to use. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted May 26, 2022 Author Posted May 26, 2022 How many pixels is a 12 point font? 16px Font size specifications may come in points or pixels where: 1 pixel (px) is usually assumed to be 1/96th of an inch. 1 point (pt) is assumed to be 1/72nd of an inch. Therefore 16px = 12pt ...maybe something like this would work ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
KaFu Posted May 26, 2022 Posted May 26, 2022 Is this of any help to you? expandcollapse popupGlobal $h_DLL_user32 = DllOpen("user32.dll") Global $h_DLL_GDI32 = DllOpen("gdi32.dll") GUICreate("Test") Global $__i_SetFont_DPI_Ratio = _SetFont_GetDPI() ; for _SetFont_Ctrl() & _SetFont_hWnd() $__i_SetFont_DPI_Ratio = $__i_SetFont_DPI_Ratio[2] GUICreate("Size of the square of the Checkbox", 400, 100) GUISetState() GUICtrlCreateCheckbox("1", 10, 10, 80) _SetFont_Ctrl(-1, 4) GUICtrlCreateCheckbox("2", 100, 10, 100) _SetFont_Ctrl(-1, 18) While 1 Switch GUIGetMsg() Case -3 GUIDelete() ExitLoop EndSwitch WEnd Func _SetFont_Ctrl($icontrolID = -1, $iSize = 8.5, $iweight = 400, $iattribute = 0, $sfontname = Default, $iQuality = 2) If IsKeyword($sfontname) Then Local $a_SetFont_GetDefault = _SetFont_GetDefault() $sfontname = $a_SetFont_GetDefault[3] EndIf #cs If Not IsDeclared("__i_SetFont_DPI_Ratio") Then Global $__i_SetFont_DPI_Ratio = _SetFont_GetDPI() $__i_SetFont_DPI_Ratio = $__i_SetFont_DPI_Ratio[2] ConsoleWrite("$__i_SetFont_DPI_Ratio " & $__i_SetFont_DPI_Ratio & @CRLF) EndIf #ce GUICtrlSetFont($icontrolID, $iSize / $__i_SetFont_DPI_Ratio, $iweight, $iattribute, $sfontname, $iQuality) EndFunc ;==>_SetFont_Ctrl Func _SetFont_hWnd($iSize = 8.5, $iweight = 400, $iattribute = 0, $sfontname = Default, $hWnd = Default, $iQuality = 2) If Not IsHWnd($hWnd) Then $hWnd = GUISwitch(0) GUISwitch($hWnd) EndIf If IsKeyword($sfontname) Then Local $a_SetFont_GetDefault = _SetFont_GetDefault() $sfontname = $a_SetFont_GetDefault[3] EndIf #cs If Not IsDeclared("__i_SetFont_DPI_Ratio") Then Global $__i_SetFont_DPI_Ratio = _SetFont_GetDPI() $__i_SetFont_DPI_Ratio = $__i_SetFont_DPI_Ratio[2] EndIf #ce GUISetFont($iSize / $__i_SetFont_DPI_Ratio, $iweight, $iattribute, $sfontname, $hWnd, $iQuality) EndFunc ;==>_SetFont_hWnd ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _SetFont_GetDefault ; Description ...: Determines Windows default MsgBox font size and name ; Syntax.........: _SetFont_GetDefault() ; Return values .: Success - Array holding determined font data ; : Failure - Array holding default values ; Array elements - [0] = Size, [1] = Weight, [2] = Style, [3] = Name, [4] = Quality ; Author ........: KaFu ; =============================================================================================================================== Func _SetFont_GetDefault() ; Fill array with standard default data Local $aDefFontData[5] = [8.5, 400, 0, "Tahoma", 2] ; Get AutoIt GUI handle Local $hWnd = WinGetHandle(AutoItWinGetTitle()) ; Open Theme DLL Local $hThemeDLL = DllOpen("uxtheme.dll") ; Get default theme handle Local $hTheme = DllCall($hThemeDLL, 'ptr', 'OpenThemeData', 'hwnd', $hWnd, 'wstr', "Static") If @error Then Return $aDefFontData $hTheme = $hTheme[0] ; Create LOGFONT structure => http://msdn.microsoft.com/en-us/library/dd145037(VS.85).aspx Local $tFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;wchar[32]") Local $pFont = DllStructGetPtr($tFONT) ; Get MsgBox font from theme DllCall($hThemeDLL, 'long', 'GetThemeSysFont', 'HANDLE', $hTheme, 'int', 805, 'ptr', $pFont) ; TMT_MSGBOXFONT If @error Then Return $aDefFontData ; Get default DC Local $hDC = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd) If @error Then Return $aDefFontData $hDC = $hDC[0] ; Get font vertical size Local $iPixel_Y = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hDC, "int", 90) ; LOGPIXELSY If Not @error Then $iPixel_Y = $iPixel_Y[0] $aDefFontData[0] = Int(2 * (.25 - DllStructGetData($tFONT, 1) * 72 / $iPixel_Y)) / 2 EndIf ; Close DC DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "handle", $hDC) ; Extract font data from LOGFONT structure $aDefFontData[3] = DllStructGetData($tFONT, 14) $aDefFontData[1] = DllStructGetData($tFONT, 5) $aDefFontData[4] = DllStructGetData($tFONT, 12) If DllStructGetData($tFONT, 6) Then $aDefFontData[2] += 2 If DllStructGetData($tFONT, 7) Then $aDefFontData[2] += 4 If DllStructGetData($tFONT, 8) Then $aDefFontData[2] += 8 Return $aDefFontData EndFunc ;==>_SetFont_GetDefault ;; GetDPI.au3 ;; ;; Get the current DPI (dots per inch) setting, and the ratio ;; between it and approximately 96 DPI. ;; ;; Author: Phillip123Adams ;; Posted: August, 17, 2005, originally developed 10/17/2004, ;; AutoIT 3.1.1.67 (but earlier v3.1.1 versions with DLLCall should work). ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;~ ;; Example ;~ #include<guiconstants.au3> ;~ ;; ;~ ;; Get the current DPI. ;~ $a1 = _SetFont_GetDPI() ;~ $iDPI = $a1[1] ;~ $iDPIRat = $a1[2] ;~ ;; ;~ ;; Design the GUI to show how to apply the DPI adjustment. ;~ GUICreate("Applying DPI to GUI's", 250 * $iDPIRat, 120 * $iDPIRat) ;~ $lbl = GUICtrlCreateLabel("The current DPI value is " & $iDPI &@lf& "Ratio to 96 is " & $iDPIRat &@lf&@lf& "Call function _SetFont_GetDPI. Then multiply all GUI dimensions by the returned value divided by approximately 96.0.", 10 * $iDPIRat, 5 * $iDPIRat, 220 * $iDPIRat, 80 * $iDPIRat) ;~ $btnClose = GUICtrlCreateButton("Close", 105 * $iDPIRat, 90 * $iDPIRat, 40 * $iDPIRat, 20 * $iDPIRat) ;~ GUISetState() ;~ ;; ;~ while 1 ;~ $iMsg = GUIGetMsg() ;~ If $iMsg = $GUI_EVENT_CLOSE or $iMsg = $btnClose then ExitLoop ;~ WEnd ;~ Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _SetFont_GetDPI() ;; Get the current DPI (dots per inch) setting, and the ratio between it and ;; approximately 96 DPI. ;; ;; Retrun a 1D array of dimension 3. Indices zero is the dimension of the array ;; minus one. Indices 1 = the current DPI (an integer). Indices 2 is the ratio ;; should be applied to all GUI dimensions to make the GUI automatically adjust ;; to suit the various DPI settings. ;; ;; Author: Phillip123Adams ;; Posted: August, 17, 2005, originally developed 6/04/2004, ;; AutoIT 3.1.1.67 (but earlier v3.1.1 versions with DLLCall should work). ;; ;; Note: The dll calls are based upon code from the AutoIt3 forum from a post ;; by this-is-me on Nov 23 2004, 10:29 AM under topic "@Larry, Help!" Thanks ;; to this-is-me and Larry. Prior to that, I was obtaining the current DPI ;; from the Registry: ;; $iDPI = RegRead("HKCU\Control Panel\Desktop\WindowMetrics", "AppliedDPI") ;; Local $a1[3] Local $iDPI, $iDPIRat, $Logpixelsy = 90, $hWnd = 0 Local $hDC = DllCall($h_DLL_user32, "long", "GetDC", "long", $hWnd) Local $aRet = DllCall($h_DLL_GDI32, "long", "GetDeviceCaps", "long", $hDC[0], "long", $Logpixelsy) ; Local $hDC = DllCall($h_DLL_user32, "long", "ReleaseDC", "long", $hWnd, "long", $hDC) DllCall($h_DLL_user32, "long", "ReleaseDC", "long", $hWnd, "long", $hDC) $iDPI = $aRet[0] ;; Set a ratio for the GUI dimensions based upon the current DPI value. Select Case $iDPI = 0 $iDPI = 96 $iDPIRat = 94 Case $iDPI < 84 $iDPIRat = $iDPI / 105 Case $iDPI < 121 $iDPIRat = $iDPI / 96 Case $iDPI < 145 $iDPIRat = $iDPI / 95 Case Else $iDPIRat = $iDPI / 94 EndSelect $a1[0] = 2 $a1[1] = $iDPI $a1[2] = $iDPIRat ;; Return the array Return $a1 EndFunc ;==>_SetFont_GetDPI OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
argumentum Posted May 26, 2022 Author Posted May 26, 2022 (edited) not really because of the DPIawareness ( otherwise it'd look brurry ) but the "$aDefFontData[0] = Int(2 * (.25 - DllStructGetData($tFONT, 1) * 72 / $iPixel_Y)) / 2" part may give a hint of the" px <> pt " translation that even tho not theoretically perfect may just get it out of the way for now. Will see. I should post the DPIawareness code ( I took from @UEZ ) just add: #include "_SetDPIAwareness.au3" _WinAPI_SetDPIAwareness() to the top of a script. _SetDPIAwareness.zip Edit: https://github.com/tringi/win32-dpi is a good reference but well above my knowing. Edited May 26, 2022 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
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