Font Ignore Windows Display Settings

2 posts in this topic

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?

Share this post

Link to post
Share on other sites

Dpi awarnes 

Look in my signature. 

ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button:


Last update: 2016-12-23
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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 *

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


Share this post

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?

      Managed with a double If and double query like this:
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys  
    • LegitStack
      By LegitStack
      Been struggling with this one for a while. 
      when I do a _screencapture_capture call on a high resolution monitor (like my surface book) it gives me an image that has 2 problems:
      1. its in the wrong location on the screen
      2. it gives me a picture that is larger than the area of the screen I selected, though it only has the content of what I selected. 
      I was able to easily fix problem #1 by manually adjusting the x y coordinates to compensate for the amount of DPI scale I have.
      for instance if I'm 200% zoomed in the code looks like this:
      Local $bmp = _ScreenCapture_Capture("", $iX1*2, $iY1*2, $iX2*2, $iY2*2, false)  it's problem #2 that is the big problem. I'd like to attach a screen shot of what I'm talking about (see capture.png)

      Now I basically understand why this is happening. ScreenCapture grabs each pixel of the screen. This screen, being a high resolution, when its zoomed in adds up several pixels to make one on the screen. 
      This is a problem for me because I'm taking images of the screen and later looking for those exact images on the screen. if everything is blown up by an indeterminate amount (in my case 2x) then those images can't be found later on. 
      Does anyone know what I can do? 
      I tried resizing the images back down to no avail. 
      _GDIPlus_ImageResize and _GDIPlus_ImageScale don't work because they don't compress the pixels correctly. quality is lost. and the exact image isn't preserved, so I can't search for it later. (see capture1.png)

      Anyway, I'm about to give up, been on this problem for too long! does anyone know what I can do? Seems to me that the ideal solution would be to eventually have autoit add an argument to _screencapture_capture that lets you specify a DPI scale amount or something.  that can be pulled from the registry at HKEY_CURRENT_USER\control panel\desktop\windowmetrics\appliedDPI.
      But in the meantime, does anyone have any suggestions for how I can make my program compatible with 4k resolution monitors? I either need to take the screen capture like normal, then scale it down appropriately without losing quality, or I need to capture the screen in the first place like the human sees it. But I don't know how to do that either. 
      I'll post my relevant code here: (in my project I call ScreenCapture_DPI_Aware)
      #include <Security.au3> Func _GetAppliedDPI()   Local $aArrayOfData = _Security__LookupAccountName(@UserName)   If IsArray($aArrayOfData) Then   ;msgbox(64, "SID String = ", $aArrayOfData[0] & @CRLF)   ;msgbox(64, "Domain name = ", $aArrayOfData[1] & @CRLF)   ;msgbox(64, "SID type = ", _Security__SidTypeStr($aArrayOfData[2]) & @CRLF)     ;Local $AppliedDPI = RegRead("HKEY_USERS\" & $aArrayOfData[0] & "\Control Panel\Desktop\WindowMetrics", "AppliedDPI") Local $AppliedDPI = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics", "AppliedDPI")     return $AppliedDPI   EndIf EndFunc Func GetScale()   $applied = _GetAppliedDPI()   if $applied == "" then     return 1   else     return $applied / 96   EndIf EndFunc Func ScreenCapture_Capture_DPI_Aware($sBMP_Path, $iX1, $iY1, $iX2, $iY2, $bool)   $R = GetScale() ;Raito   Local $bmp = _ScreenCapture_Capture($sBMP_Path, $iX1*$R, $iY1*$R, $iX2*$R, $iY2*$R, $bool) ;Scaling didn't work: ;_ScaleImage($bmp, $sBMP_Path, abs($iX2 - $iX1), abs($iY2 - $iY1), $R)   ;return _ScreenCapture_Capture($sBMP_Path, $iX1*$R, $iY1*$R, $iX2*$R, $iY2*$R, $bool) EndFunc ;Func _ScaleImage($bmp, $outimage, $w, $h, $scale) ; _GDIPlus_Startup() ;Get the encoder of to save the resized image in the format you want. ; Local $Ext = StringUpper(StringMid($outimage, StringInStr($outimage, ".", 0, -1) + 1)) ; $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ; code found here : ; Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("png") ;create CLSID for a JPG image file type ; Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) ;convert CLSID GUID to binary form and returns $tagGUID structure ; Local $tParams = _GDIPlus_ParamInit(1) ;initialize an encoder parameter list and return $tagGDIPENCODERPARAMS structure ; Local $tData = DllStructCreate("int Quality") ;create struct to set JPG quality setting ; DllStructSetData($tData, "Quality", 100) ;quality 0-100 (0: lowest, 100: highest) ; Local $pData = DllStructGetPtr($tData) ;get pointer from quality struct ; _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) ;add a value to an encoder parameter list ; Local $gbmp = _GDIPlus_BitmapCreateFromHBITMAP($bmp) ; _WinAPI_DeleteObject($bmp) ; Local $gsbmp = _GDIPlus_ImageResize($gbmp, $w * $scale, $h * $scale) ;Local $ext = _GDIPlus_EncodersGetCLSID("PNG") ; _GDIPlus_ImageSaveToFileEx($gsbmp, $outimage, $sImgCLSID) ; _GDIPlus_BitmapDispose($gbmp) ; _GDIPlus_BitmapDispose($gsbmp) ; _GDIPlus_Shutdown() ;EndFunc
      Thanks for any help you can give me!!!
    • Trolleule
      By Trolleule
      i did some researchs how to set the font and the only way is to overwrite the subclass with WM_DRAWITEM. With WM_SETFONT i can only change the font for all tab pages, but i want to change the font for a specific page.
      So i have to set the $TCS_OWNERDRAWFIXED style to the tab control to send the WM_DRAWITEM message to the parent window. When i set this style, i can change the fonts, but sadly the tab looses the nice and simple "AutoIt style". I created two child guis, the first is the owner draw tab and the second the "Normal" tab.
      My questions is, how to create this special "AutoIt style"???
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <ColorConstants.au3> Global Const $ODT_TAB = 101 Global Const $ODS_SELECTED = 0x0001 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODS_FOCUS = 0x0010 $hStrikeOutDefaultFont = _WinAPI_CreateFont(14, 0, 0, 0, 400, False, False, True) ; see system apps module $hGUI = GUICreate("Draw Tab", 500, 600) ; Create child GUIs to hold tabs $hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) $hTab_0 = GUICtrlCreateTab(10, 10, 380, 180, $TCS_OWNERDRAWFIXED);BitOR($TCS_OWNERDRAWFIXED, $TCS_TOOLTIPS, $WS_TABSTOP, $WS_CLIPSIBLINGS)) $hTab_00 = GUICtrlCreateTabitem("00") GUICtrlCreateButton("00", 160, 90, 80, 30) $hTab_01 = GUICtrlCreateTabitem("01") GUICtrlCreateButton("01", 160, 90, 80, 30) GUICtrlCreateTabitem ("") GUISetState() $hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) $hTab_1 = GUICtrlCreateTab(10, 10, 380, 180) $hTab_10 = GUICtrlCreateTabitem("10") GUICtrlCreateButton("10", 160, 90, 80, 30) $hTab_11 = GUICtrlCreateTabitem("11") GUICtrlCreateButton("11", 160, 90, 80, 30) GUICtrlCreateTabitem ("") GUISetState() GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;~ GUIRegisterMsg($WM_SETFONT, "WM_SETFONT") ;~ GUICtrlSendMsg ( $hTab_1, $WM_SETFONT , $hStrikeOutDefaultFont, 1 ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_SETFONT($hWnd, $Msg, $wParam, $lParam) ConsoleWrite("$hWnd: " & $hWnd & " $Msg: " & $Msg & " $wParam: " & $wParam & " $lParam: " & $lParam & @CRLF) EndFunc Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $DRAWITEMSTRUCT $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam) If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID") Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID") Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction") Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState") Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm") Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC") If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG Local $iTextColor, $itmText $iTextColor = 0xFFFFFF Switch $itmID Case 0 $iBrushColor = 0x11AADD Case 1 $iBrushColor = 0xEEBB99 EndSwitch _WinAPI_SetBkMode($hDC, $TRANSPARENT) Local $iBrush = _WinAPI_CreateSolidBrush($iBrushColor) Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush) $g_tRECT = DllStructCreate($tagRect, DllStructGetPtr($DRAWITEMSTRUCT, "itmRect")) DllStructSetData($g_tRECT, "Left", DllStructGetData($g_tRECT, "Left")) DllStructSetData($g_tRECT, "Top", DllStructGetData($g_tRECT, "Top")) DllStructSetData($g_tRECT, "Right", DllStructGetData($g_tRECT, "Right")) DllStructSetData($g_tRECT, "Bottom", DllStructGetData($g_tRECT, "Bottom")+10) _WinAPI_FillRect ( $hDC, $g_tRECT, $iBrush ) _WinAPI_SetTextColor($hDC, $iTextColor) _WinAPI_DrawText($hDC, "Item " & $itmID, $g_tRECT, $DT_LEFT) _WinAPI_SelectObject($hDC, $iBrushOld) _WinAPI_DeleteObject($iBrush) Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Thanks in advance
    • kcvinu
      By kcvinu
      Hi all,
      I would like to know how to check if a specific font is installed in user's system. If it is not installed, my program needs to install the font. (Don't worry about the copy right of the font. it's free) I have got some points from google which directs me into _WinAPI_AddFontResourceEx function. But help file says that this function is only for current session.  And i also got the _WinAPI_EnumFontFamilies function too. But before trying any of these, i would like to hear from the masters. 
    • AmarokStudios
      By AmarokStudios
      Hello all! I'm trying to figure out how to display the contents of my Microsoft Outlooks inbox inside of an AutoIt GUI.
      So far, I've managed to embed it perfectly and the website looks fantastic, but whenever I click on a message in my inbox, I can't view it. I also can't create new messages or search my inbox. I figured this was probably an ActiveX or JavaScript incompatibility. Any ideas?
      Local $oIE = _IECreateEmbedded() $browserObj = GUICtrlCreateObj($oIE, 20, 60, 780, 580) _IENavigate($oIE, "")