Jump to content

Font Ignore Windows Display Settings


Recommended Posts

In my code, I'm using GUICtrlCreateLabel to create a label and GUICtrlSetFont to set the font. Example...

$SELlbl = GUICtrlCreateLabel("Hello World", 8, 8, 286, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

This works in my GUI unless display settings are changed in Windows 7 from 100% to 125-150%. Then the text is blown up and is misaligned with my GUI. 

Is there a simple way to ignore the display setting and force the font size?

Link to post
Share on other sites

Dpi awarnes 

Look in my signature. 

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 for 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-03-02

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By argumentum
      This was born in a help topic but then I thought I'd be a good UDF to have.
      The difference between _ChooseFont() and this _ChooseFontEx() , is that it adds:
        The use of keyword "Default", as default value.
        Hide parts of the font choosing GUI
        Uses the proper default color if no color is declared (default)
      I tested this UDF to work with AutoIt from v3.2.12.1 and the current v3.3.16.1, so it should work in every version.
      This also copied the Dll calls from other UDFs to this one, to give it independence from otherwise needed additional includes. 
      The Example:
      #include <_ChooseFontEx.au3> #include <Array.au3> ; for the example Example() Func Example() Local $hParent = GUICreate("Test GUI", 300, 300, @DesktopWidth / 3) For $i = 1 To 7 GUICtrlCreateLabel("label " & $i, 10, $i * 25) Next GUISetState() Sleep(1000) ; used "Arial" as it is found from WinXP to Win11 Local $aFont = _ChooseFont("Arial", 8, 0, 0, False, False, False, $hParent) _ArrayDisplay($aFont, "Example original") $aFont = _ChooseFontEx("Arial", 8, Default, Default, Default, Default, Default, $hParent) _ArrayDisplay($aFont, "Example # 1") $aFont = _ChooseFontEx("Arial", 8, Default, 600, Default, Default, Default, $hParent, 63, "Please choose a font:") _ArrayDisplay($aFont, "Example # 2") Sleep(1000) EndFunc ;==>Example The UDF:
      #include-once ; if you're gonna use it as UDF #include <Misc.au3> ; for _ChooseFont() Global $__ChooseFontEx_Hook_WH_CBT = 5, $__ChooseFontEx_Hook_hProc = 0, $__ChooseFontEx_Hook_hHook = 0, _ $__ChooseFontEx_Hook_iHideThese = 3, $__ChooseFontEx_Hook_sNewWinTitle = "", $__ChooseFontEx_Hook_wParamKept = 0 ; #FUNCTION# ==================================================================================================================== ; Name...........: _ChooseFontEx ; Description ...: Creates a Font dialog box that enables the user to choose attributes for a logical font. ; Syntax.........: _ChooseFont([$sFontName = "Courier New"[, $iPointSize = 10[, $iColorRef = 0[, $iFontWeight = 0[, $iItalic = False[, $iUnderline = False[, $iStrikethru = False[, $hWndOwner = 0[, $iHideThese = 7[, $sNewWinTitle = ""]]]]]]]]]]) ; Parameters ....: $sFontName - Default font name ; $iPointSize - Pointsize of font ; $iColorRef - COLORREF rgbColors ; $iFontWeight - Font Weight ; $iItalic - Italic ; $iUnderline - Underline ; $iStrikethru - Optional: Strikethru ; $hWndOwnder - Handle to the window that owns the dialog box ; $iHideThese - Bitwise: Default is 3 ( SysLink and Script ) ; 1: hide SysLink ; 2: hide Script ; 4: hide Color ( if 4 and 8 , also the GroupBox "Effects" will be hidden ) ; 8: hide underline & strikeout ; 16: hide "Font style" ; 32: hide "Font size" ; $sNewWinTitle - Change the WinTitle ; Return values .: Success - Array in the following format: ; |[0] - contains the number of elements ; |[1] - attributes = BitOr of italic:2, undeline:4, strikeout:8 ; |[2] - fontname ; |[3] - font size = point size ; |[4] - font weight = = 0-1000 ; |[5] - COLORREF rgbColors ; |[6] - Hex BGR Color ; |[7] - Hex RGB Color ; Failure - -1 ; Author ........: argumentum ; https://www.autoitscript.com/forum/topic/209809-_choosefontex/ ; Modified.......: ; Remarks .......: Default keyword friendly. Dark Mode friendly. ; Related .......: _ChooseFont() ; Link ..........; ; Example .......; Yes ; =============================================================================================================================== Func _ChooseFontEx($sFontName = "Courier New", $iPointSize = 10, $iFontColorRef = Default, $iFontWeight = 0, _ $bItalic = False, $bUnderline = False, $bStrikethru = False, $hWndOwner = 0, $iHideThese = 3, $sNewWinTitle = "") Local $aRet, $iErr, $iExt, $COLOR_BTNTEXT = 18 If $iPointSize = Default Then $iPointSize = 10 ; Default as a parameter is not in the Misc.au3 UDF. Added here for convenience. If $iFontColorRef = Default Then $iFontColorRef = 0 $aRet = DllCall("user32.dll", "INT", "GetSysColor", "int", $COLOR_BTNTEXT) ; I use a dark theme, so 0x000000 is not my default. If Not @error Then $iFontColorRef = $aRet[0] EndIf If $iFontWeight = Default Then $iFontWeight = 0 If $bItalic = Default Then $bItalic = False If $bUnderline = Default Then $bUnderline = False If $bStrikethru = Default Then $bStrikethru = False If $hWndOwner = Default Then $hWndOwner = 0 If $iHideThese = Default Then $iHideThese = 3 ; hide SysLink + hide Script If $sNewWinTitle = Default Then $sNewWinTitle = "" __ChooseFontEx_Hook("StartIt", $iHideThese, $sNewWinTitle) ; logic moved to this func to keep hook variables as local $aRet = _ChooseFont($sFontName, $iPointSize, $iFontColorRef, $iFontWeight, $bItalic, $bUnderline, $bStrikethru, $hWndOwner) $iErr = @error $iExt = @extended __ChooseFontEx_Hook("EndIt", "", "") Return SetError($iErr, $iExt, $aRet) EndFunc ;==>_ChooseFontEx ; #FUNCTION# ==================================================================================================================== ; Name...........: __ChooseFontEx_Hook ; Description ...: Helper function for _ChooseFontEx() ; Remarks .......: For Internal Use Only ; =============================================================================================================================== Func __ChooseFontEx_Hook($nCode, $wParam, $lParam) ; Tested in XP, 10 and 11 ;Local Static $__ChooseFontEx_Hook_WH_CBT = 5, $__ChooseFontEx_Hook_hProc = 0, _ ; moved to "Global" to make it 3.2.12.1 compatible ; $__ChooseFontEx_Hook_hHook = 0, $__ChooseFontEx_Hook_iHideThese = 3, $__ChooseFontEx_Hook_sNewWinTitle = "", $__ChooseFontEx_Hook_wParamKept = 0 Local $aRet Switch $nCode Case "StartIt" $__ChooseFontEx_Hook_sNewWinTitle = $lParam If $wParam < 0 Or $wParam > 63 Or $wParam = Default Then $__ChooseFontEx_Hook_iHideThese = 3 Else $__ChooseFontEx_Hook_iHideThese = Int($wParam) EndIf $__ChooseFontEx_Hook_hProc = DllCallbackRegister("__ChooseFontEx_Hook", "int", "int;int;int") Local $hThreadId = DllCall("kernel32.dll", "dword", "GetCurrentThreadId") If Not @error Then $aRet = DllCall("user32.dll", "handle", "SetWindowsHookEx", "int", $__ChooseFontEx_Hook_WH_CBT, _ "ptr", DllCallbackGetPtr($__ChooseFontEx_Hook_hProc), "handle", 0, "dword", $hThreadId[0]) If Not @error Then $__ChooseFontEx_Hook_hHook = $aRet[0] EndIf Return Case "EndIt" DllCall("user32.dll", "bool", "UnhookWindowsHookEx", "handle", $__ChooseFontEx_Hook_hHook) ;If @error Then ConsoleWrite('! @error ' & @ScriptLineNumber & @CRLF) DllCallbackFree($__ChooseFontEx_Hook_hProc) $__ChooseFontEx_Hook_hHook = 0 $__ChooseFontEx_Hook_hProc = 0 Return EndSwitch ; $nCode = 3 ( 1st control created in the canvas is the window, hance "wParamKept = $wParam" ) If $nCode = 3 And $__ChooseFontEx_Hook_wParamKept = 0 Then $__ChooseFontEx_Hook_wParamKept = $wParam If $nCode = 9 And $__ChooseFontEx_Hook_wParamKept = 1 Then $__ChooseFontEx_Hook_wParamKept = 0 If $nCode = 5 And $__ChooseFontEx_Hook_wParamKept = $wParam Then $__ChooseFontEx_Hook_wParamKept = 1 Local $hWnd = HWnd($wParam) If BitAND($__ChooseFontEx_Hook_iHideThese, 1) Then ControlHide($hWnd, "", "SysLink1") ; <A>Show more fonts</A> If BitAND($__ChooseFontEx_Hook_iHideThese, 2) Then ControlHide($hWnd, "", "Static7") ; Script: ControlHide($hWnd, "", "ComboBox5") ; Script comboBox EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 4) Then ControlHide($hWnd, "", "Static4") ; Color: ControlHide($hWnd, "", "ComboBox4") ; Color comboBox EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 8) Then ControlHide($hWnd, "", "Button2") ; Strikeout: ControlHide($hWnd, "", "Button3") ; Underline: EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 16) Then ; Font style: ControlHide($hWnd, "", "Static2") ControlHide($hWnd, "", "ComboBox2") EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 32) Then ; Size: ControlHide($hWnd, "", "Static3") ControlHide($hWnd, "", "ComboBox3") EndIf If BitAND($__ChooseFontEx_Hook_iHideThese, 4) And BitAND($__ChooseFontEx_Hook_iHideThese, 8) Then ControlHide($hWnd, "", "Button1") ; Effects: If $__ChooseFontEx_Hook_sNewWinTitle <> "" Then WinSetTitle($hWnd, "", $__ChooseFontEx_Hook_sNewWinTitle) EndIf $aRet = DllCall("user32.dll", "lresult", "CallNextHookEx", "handle", $__ChooseFontEx_Hook_hHook, "int", $nCode, "wparam", $wParam, "lparam", $lParam) If Not @error Then Return $aRet[0] Return 0 EndFunc ;==>__ChooseFontEx_Hook #cs #include <Array.au3> ; for the example Example() Func Example() Local $hParent = GUICreate("Test GUI", 300, 300, @DesktopWidth / 3) For $i = 1 To 7 GUICtrlCreateLabel("label " & $i, 10, $i * 25) Next GUISetState() Sleep(1000) Local $aFont = _ChooseFontEx("Segoe UI", 8, Default, Default, Default, Default, Default, $hParent) _ArrayDisplay($aFont, "Example # 1") $aFont = _ChooseFontEx("Segoe UI", 8, Default, 600, Default, Default, Default, $hParent, 63, "Please choose a font:") _ArrayDisplay($aFont, "Example # 2") Sleep(1000) EndFunc ;==>Example #ce Talking to myself: I don't know if start annoying the MVPs into modifying the default ChooseFont() to include these features in it is well worth it. It should be but I don't wanna push the code uphill ...hmmm. They may just do it if they see this expansion as favorable. At least the default color should be implemented. idk.
      If you're using this thing, please do leave a like, as to get an idea if is really useful or just not that useful. Thank you.
    • By BlueSkyMemory
      While Scite doesn't support high dpi, I open it in compatibility settings. But it brings another problem:My au3 app automatically enables high dpi, causing gui disorder.
      I've tried #AutoIt3Wrapper_Res_HiDpi=N but it doesn't work. I'd appreciate it if you could offer some help. Thanks.
    • By mLipok
      In the display settings, in the advanced settings on the General tab is more or less the setting:    The translation from GOOGLE: "If the resolution makes items are too small to achieve visual comfort, you can to offset this effect increase the resolution dpi. To change only the font size, click Cancel and go to the Appearance tab."    EDIT: Here there is a possibility to choose: Default size 96 dpi  Big size 120 dpi    When I Change this option to 120 dpi, this causes display problems with elements such as Button. The problem is manifested by the fact that the text does not fit within the limits set by the size of the button.  Of course, if you set 96 dpi, the text looks normal.    Does anyone know a solution to this problem.    I note that the solution like this:  GUICtrlSetResizing(-1, $GUI_DOCKALL) unfortunately does not help.
       
        mLipok
    • By paw
      I use SetSoundDevice to control my audio devices but the UI was either
       
      blurry like this:
      or unusable like this:

      so I made this horrible thing to add scaling to the GUI:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_HiDpi=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/sf /sv /rm #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> ;~ _convertGUI("") If $CmdLine[0] <> 0 Then _convertGUI($CmdLine[1]) Func _convertGUI($sFilePath) If $sFilePath <> "" Then Local $aArray = FileReadToArray($sFilePath) Else ;TEST DATA Local $aArray[6] = ['$H_Res_Language = GUICtrlCreateProgress(5, 120, 210 + 25, 480, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; $CBS_DROPDOWNLIST)', _ 'Local $h_Ok = GUICtrlCreateButton("Ok", 72, 224, 81, 33, 0)', _ 'GUICreate($Warning_TiTle, 700, 310, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)', _ 'GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)', _ '$H_FieldNameEdit = GUICtrlCreateEdit($INP_FieldNameEdit, 100,260+25, 500, 150 - 25) ;comment', 'Local $H_CANCEL = GUICtrlCreateGraphic("Cancel", 224, 224, 97, 33, 0)'] EndIf Local $hTimer = TimerInit(), $iGUIElementCount = 0, $sResult = "", $sFileName = "", $sDrive = "", $sDir = "", $sExtension = "" If @Compiled Then _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) $sFileName = StringRegExpReplace($sFilePath, "^.*\\", "") EndIf For $i = 0 To (UBound($aArray) - 1) If StringRegExp($aArray[$i], "GUICtrlCreate|GUICreate") Then $sResult = _splitComma($aArray[$i]) If Not @error Then $aArray[$i] = $sResult $iGUIElementCount += 1 EndIf Next ConsoleWrite("t = " & TimerDiff($hTimer) & " GUI elements = " & $iGUIElementCount & " lines = " & (UBound($aArray) - 1) & @CRLF) If $sFileName <> "" Then Local $hFile = FileOpen("edited." & $sFileName, 2) _FileWriteFromArray("edited." & $sFileName, $aArray) FileClose($hFile) EndIf Exit EndFunc ;==>_convertGUI Func _splitComma($sString) Local $sSplitResult = "", $sTrimmedR = "", $sTrimmedL = "" Local $aSplit = StringSplit($sString, ',') If Not @error Then $sTrimmedR = "" $sTrimmedL = "" For $j = 1 To $aSplit[0] If StringRegExp($aSplit[1], "(?:.GUICtrlCreateGraphic|GUICtrlCreateProgress|GUICtrlCreateSlider|GUICtrlCreateTab|GUICtrlCreateTreeView)") Then If $j = 1 Then While StringLeft($aSplit[$j], 1) <> '(' $sTrimmedL &= StringLeft($aSplit[$j], 1) $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) EndIf EndIf If $j = $aSplit[0] Then While StringRight($aSplit[$j], 1) <> ')' $sTrimmedR &= StringRight($aSplit[$j], 1) $aSplit[$j] = StringTrimRight($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimRight($aSplit[$j], 1) EndIf If StringRegExp($aSplit[$j], "[0-9]") And $aSplit[$j] <> -1 And $aSplit[$j] <> 0 And $aSplit[$j] <> 1 And Not StringInStr($aSplit[$j], ')') Then If StringRegExp($aSplit[$j], "\-|\+") Then ;put parenthesis around + or - $aSplit[$j] = '(' & $aSplit[$j] & ")*$g_DPI" Else $aSplit[$j] = $aSplit[$j] & "*$g_DPI" EndIf EndIf If $j < $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ',' ElseIf $j = $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ')' Else $sSplitResult &= $aSplit[$j] EndIf Next If $sTrimmedR <> "" Then $sSplitResult &= StringReverse($sTrimmedR) If $sTrimmedL <> "" Then $sSplitResult = $sTrimmedL & '(' & $sSplitResult Else SetError(1) Return EndIf ConsoleWrite($sSplitResult & @CRLF) Return $sSplitResult EndFunc ;==>_splitComma
      And now it looks good: 
      but it doesn't work on everything, for example the "GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)" (from the autoit3wrapper gui)
      because the comment contains a parenthesis and it would break completely if there were variables as parameters..
      Is there some kind of parser around that I could use instead or maybe someone who has already done something like this?
    • By TheDcoder
      Hello, it has been a long time since I have posted here
      I am working on an AutoIt project where I need to enable to user to interactively choose any point or coordinate on the screen... something like a big overlay where the user can click anywhere on the screen to select that point. @UEZ's screenshot tool may have something similar to what I need:
      I just checked the source code for the tool and I see that the Mark_Area function has a part in selecting the area to screenshot, I tried to figure out how it works but it is simply too complex and long...
      So I was wondering if there were any examples of interactively selecting points on a screen? Maybe an UDF that I can just use in my script to make the whole thing a matter of adding few lines
      Thank you for the replies in advance!
×
×
  • Create New...