KaFu Posted January 21, 2011 Posted January 21, 2011 (edited) Hiho Forum ,I wanted to implement Melba23s excellent into SMF, but noticed on a XP system that the font's he used did not match the default font exactly. On the German AutoIt.de board I found a solution by ProgAndy which was a very good start but not the final solution I was seeking for (ProgAndy, thanks for this input!). After reading many more postings on this topic from all over the net and after throughly studying MSDN I came to the conclusion the the values used for the font definition can not be reversed easily. The problem is a mechanism in Windows called "font mapper". The font mapper interprets the input values and selects a font setting which comes closed in matching to the request. The FontSize returned by the function is an approximation of the actual fontsize used for the control. The height of the font returned by GetObject is the height of the font's character cell or character in logical units. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in lfHeight. The result returned by the font mapper is not easily reversible. The FontSize calculated below is an approximation of the actual size used for the analyzed control, qualified enough to use in another call to the font mapper resulting in the same font size as the the original font. This means if you used 8.5 as the fontsize for the original control the function might return 8.67, but using the value for GuiCtrlSetFont() will result in the same font.Another interesting observation I made is that the font mapper even selects between different fonts, if the fontname is not explicitly set. There is a commented consolewrite() in the function, uncomment it and point the function to different GuiSetFont() settings without a fontname like GuiSetFont($cID, 8).The example provided below is using functions from Yashieds excellent the function itself only needs the two includes at top of the example.As I said, the result is an approximation... I tested the function on XP-32 and Win7-64 and could not find a non-matching approximation... but you'll never know. Tell me if you find differences with specific settings / fonts.Enjoy ...expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlGetFont ; Description ...: Gets the font of a GUI Control ; Syntax.........: _GUICtrlGetFont( [$hWnd] ) ; Parameters ....: $hWnd - [optional] ControlID or Handle of the control. Default is last created GUICtrl... (-1) ; ; Return values .: Success - Array[5] with options of font: ; [0] - FontSize (~ approximation) ; [1] - Font weight (400 = normal). ; [2] - italic:2 underlined:4 strike:8 char format (styles added together, 2+4 = italic and underlined). ; [3] - The name of the font to use. ; [4] - Font quality to select (PROOF_QUALITY=2 is default in AutoIt). ; ; Failure - Array[5] with empty fields, @error set to nonzero ; ; Author ........: KaFu, Prog@ndy ; ; Comments.......: The FontSize returned is an approximation of the actual fontsize used for the control. ; The height of the font returned by GetObject is the height of the font's character cell or character in logical units. ; The character height value (also known as the em height) is the character cell height value minus the internal-leading value. ; The font mapper interprets the value specified in lfHeight. The result returned by the font mapper is not easily reversible ; The FontSize calculated below is an approximation of the actual size used for the analyzed control, qualified enough to use ; in another call to the font mapper resulting in the same font size as the the original font. ; MSDN.. ........: Windows Font Mapping: http://msdn.microsoft.com/en-us/library/ms969909(loband).aspx ; =============================================================================================================================== Func _GUICtrlGetFont($hWnd = -1) Local $aReturn[5], $hObjOrg If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1, 0, $aReturn) Local $hFONT = _SendMessage($hWnd, $WM_GETFONT) If Not $hFONT Then Return SetError(2, 0, $aReturn) Local $hDC = _WinAPI_GetDC($hWnd) $hObjOrg = _WinAPI_SelectObject($hDC, $hFONT) Local $tFONT = DllStructCreate($tagLOGFONT) Local $aRet = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFONT, 'int', DllStructGetSize($tFONT), 'ptr', DllStructGetPtr($tFONT)) If @error Or $aRet[0] = 0 Then _WinAPI_SelectObject($hDC, $hObjOrg) _WinAPI_ReleaseDC($hWnd, $hDC) Return SetError(3, 0, $aReturn) EndIf ; Need to extract FontFacename separately => DllStructGetData($tFONT, 'FaceName') is only valid if FontFacename has been set explicitly! $aRet = DllCall("gdi32.dll", "int", "GetTextFaceW", "handle", $hDC, "int", 0, "ptr", 0) Local $nCount = $aRet[0] Local $tBuffer = DllStructCreate("wchar[" & $aRet[0] & "]") Local $pBuffer = DllStructGetPtr($tBuffer) $aRet = DllCall("Gdi32.dll", "int", "GetTextFaceW", "handle", $hDC, "int", $nCount, "ptr", $pBuffer) If @error Then _WinAPI_SelectObject($hDC, $hObjOrg) _WinAPI_ReleaseDC($hWnd, $hDC) Return SetError(4, 0, $aReturn) EndIf $aReturn[3] = DllStructGetData($tBuffer, 1) ; FontFacename $aReturn[0] = Round((-1 * DllStructGetData($tFONT, 'Height')) * 72 / _WinAPI_GetDeviceCaps($hDC, 90), 1) ; $LOGPIXELSY = 90 => DPI aware _WinAPI_SelectObject($hDC, $hObjOrg) _WinAPI_ReleaseDC($hWnd, $hDC) $aReturn[1] = DllStructGetData($tFONT, 'Weight') $aReturn[2] = 2 * (True = DllStructGetData($tFONT, 'Italic')) + 4 * (True = DllStructGetData($tFONT, 'Underline')) + 8 * (True = DllStructGetData($tFONT, 'StrikeOut')) $aReturn[4] = DllStructGetData($tFONT, 'Quality') Return $aReturn EndFunc ;==>_GUICtrlGetFont ;----------------------------------------------------------------- #region _GUICtrlGetFont - Test GUI #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> Global $FileList = _FileListToArray(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS), '*.ttf', 1) Global $FontList[UBound($FileList) - 1][2] For $i = 1 To $FileList[0] $FontList[$i - 1][0] = $FileList[$i] $FontList[$i - 1][1] = _WinAPI_GetFontResourceInfo($FileList[$i], 1) Next Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 0) $hGUI = GUICreate("_GUICtrlGetFont", 1000, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $c_Label_Reference = GUICtrlCreateLabel("The quick brown fox jumps over the lazy dog", 10, 10, 980, 90) $c_Label_Clone = GUICtrlCreateLabel("The quick brown fox jumps over the lazy dog", 10, 100, 980, 90) GUISetState() $sErrors = "" Global $aFontAttributtes[8] = [0, 2, 4, 6, 8, 10, 12, 14] For $iFontAttributte = 0 To UBound($aFontAttributtes) - 1 For $iFontQuality = 0 To 5 For $iFontWeight = 100 To 800 Step 100 For $i = 0 To UBound($FontList) - 1 $sFontname = $FontList[$i][1] $sFontfile = $FontList[$i][0] For $iFontSize = 2 To 48 Step 0.1 $iFontSize = Round($iFontSize, 1) WinSetTitle($hGUI, "", "_GUICtrlGetFont - " & $sFontfile & " - " & $sFontname & " - " & $iFontSize & " - " & $iFontWeight & " - " & $aFontAttributtes[$iFontAttributte] & " - " & $sFontname & " - " & $iFontQuality) GUICtrlSetFont($c_Label_Reference, $iFontSize, $iFontWeight, $aFontAttributtes[$iFontAttributte], $sFontname, $iFontQuality) $aFont_Get = _GUICtrlGetFont($c_Label_Reference) GUICtrlSetFont($c_Label_Clone, $aFont_Get[0], $aFont_Get[1], $aFont_Get[2], $aFont_Get[3], $aFont_Get[4]) $iFontSize_Reference = _GUICtrlGetFont_Height_EM($c_Label_Reference) $iFontSize_Clone = _GUICtrlGetFont_Height_EM($c_Label_Clone) If $iFontSize_Reference <> $iFontSize_Clone Then ConsoleWrite("! " & $iFontSize_Reference & @TAB & $iFontSize_Clone & @TAB & @TAB & @TAB & $iFontSize & @TAB & $iFontWeight & @TAB & $aFontAttributtes[$iFontAttributte] & @TAB & $sFontname & @TAB & $iFontQuality & @CRLF) $sErrors &= $iFontSize & @TAB & $iFontWeight & @TAB & $aFontAttributtes[$iFontAttributte] & @TAB & $sFontname & @TAB & $iFontQuality & @CRLF ClipPut($sErrors) MsgBox(48 + 262144, "_GUICtrlGetFont - ERROR", $iFontSize_Reference & @CRLF & $iFontSize_Clone & @CRLF & @CRLF & $iFontSize & @CRLF & $iFontWeight & @CRLF & $aFontAttributtes[$iFontAttributte] & @CRLF & $sFontname & @CRLF & $iFontQuality, 10, $hGUI) Else ;ConsoleWrite("+ " & $iFontSize_Reference & @TAB & $iFontSize_Clone & @TAB & @TAB & @TAB & $iFontSize & @TAB & $iFontWeight & @TAB & $aFontAttributtes[$iFontAttributte] & @TAB & $sFontname & @TAB & $iFontQuality & @CRLF) EndIf Next Next Next Next Next Func _GUICtrlGetFont_Height_EM($hWnd = -1) Local $hFONT If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) $hFONT = _SendMessage($hWnd, $WM_GETFONT) If Not $hFONT Then Return SetError(1, 0, 0) Local $tFONT = DllStructCreate($tagLOGFONT) Local $aReturn = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFONT, 'int', DllStructGetSize($tFONT), 'ptr', DllStructGetPtr($tFONT)) If @error Or $aReturn[0] = 0 Then Return SetError(2, 0, 0) Return Abs(DllStructGetData($tFONT, 'Height')) EndFunc ;==>_GUICtrlGetFont_Height_EM Func _Exit() Exit EndFunc ;==>_Exit #endregion _GUICtrlGetFont - Test GUI Edited January 23, 2011 by KaFu Gianni and Professor_Bernd 1 1 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)
guinness Posted January 22, 2011 Posted January 22, 2011 Excellent! I have been using this >> so far, but this is one for the Function Folder! UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Moderators Melba23 Posted January 22, 2011 Moderators Posted January 22, 2011 KaFu, Works without error on the installed fonts in my Vista 32 box. Nice work! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
wakillon Posted January 23, 2011 Posted January 23, 2011 Tested Succesfully with .ttf, .fon, .compositefont, .otf Font's types ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
KaFu Posted January 23, 2011 Author Posted January 23, 2011 Tested Succesfully with .ttf, .fon, .compositefont, .otf Font's types ! Excellent , thanks for that feedback wakillon, as I've only installed very few non-standard fonts ... 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)
Yashied Posted January 23, 2011 Posted January 23, 2011 (edited) 0.25 = Magic Number, don't ask... I think GUICtrlSetFont() rounds the font size to one decimal place. So it works without a magical numbers. $aReturn[0] = -Round((DllStructGetData($tFONT, 'Height') / _WinAPI_GetDeviceCaps($hDC, 90)) * 72, 1) Edited January 23, 2011 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
KaFu Posted January 23, 2011 Author Posted January 23, 2011 (edited) I think GUICtrlSetFont() rounds the font size to one decimal place. So it works without a magical numbers.I'm not quite sure but I think I introduced it because I had errors. It was 0.1 first (working without flaws) but then I increased it to 0.25 (better on the safe side then sorry ) because the erroneous results were all a little lower then the original settings. But 0.1 would make more sense as a rounding margin, if you say it rounds to one decimal place, because the result returned by GUICtrlSetFont() is also rounded.Edit: In fact due to the nature of the font mapper as I understand it, 0.2 would be the number.OrgSize :8.5 => Font-Mapper => Real FontSize = 8.6Result: 8.41 => Font-Mapper => 8.4 (with a different resulting font if 8.5 is the "transition-border").Edit2: In fact above scenario speaks more for 0.1 ... Edited January 23, 2011 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)
funkey Posted January 23, 2011 Posted January 23, 2011 Great work KaFu! I like it very much! I have looked for something like that many times. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
Yashied Posted January 23, 2011 Posted January 23, 2011 @KaFu A simple test. expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlGetFont ; Description ...: Gets the font of a GUI Control ; Syntax.........: _GUICtrlGetFont( [$hWnd] ) ; Parameters ....: $hWnd - [optional] ControlID or Handle of the control. Default is last created GUICtrl... (-1) ; ; Return values .: Success - Array[5] with options of font: ; [0] - FontSize (~ approximation) ; [1] - Font weight (400 = normal). ; [2] - italic:2 underlined:4 strike:8 char format (styles added together, 2+4 = italic and underlined). ; [3] - The name of the font to use. ; [4] - Font quality to select (PROOF_QUALITY=2 is default in AutoIt). ; ; Failure - Array[5] with empty fields, @error set to nonzero ; ; Author ........: KaFu, Prog@ndy ; ; Comments.......: The FontSize returned is an approximation of the actual fontsize used for the control. ; The height of the font returned by GetObject is the height of the font's character cell or character in logical units. ; The character height value (also known as the em height) is the character cell height value minus the internal-leading value. ; The font mapper interprets the value specified in lfHeight. The result returned by the font mapper is not easily reversible ; The FontSize calculated below is an approximation of the actual size used for the analyzed control, qualified enough to use ; in another call to the font mapper resulting in the same font size as the the original font. ; MSDN.. ........: Windows Font Mapping: http://msdn.microsoft.com/en-us/library/ms969909(loband).aspx ; =============================================================================================================================== Func _GUICtrlGetFont($hWnd = -1) Local $aReturn[5], $hObjOrg If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1, 0, $aReturn) Local $hFONT = _SendMessage($hWnd, $WM_GETFONT) If Not $hFONT Then Return SetError(2, 0, $aReturn) Local $hDC = _WinAPI_GetDC($hWnd) $hObjOrg = _WinAPI_SelectObject($hDC, $hFONT) Local $tFONT = DllStructCreate($tagLOGFONT) Local $aRet = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFONT, 'int', DllStructGetSize($tFONT), 'ptr', DllStructGetPtr($tFONT)) If @error Or $aRet[0] = 0 Then _WinAPI_SelectObject($hDC, $hObjOrg) _WinAPI_ReleaseDC($hWnd, $hDC) Return SetError(3, 0, $aReturn) EndIf ; Need to extract FontFacename separately => DllStructGetData($tFONT, 'FaceName') is only valid if FontFacename has been set explicitly! $aRet = DllCall("gdi32.dll", "int", "GetTextFaceW", "handle", $hDC, "int", 0, "ptr", 0) Local $nCount = $aRet[0] Local $tBuffer = DllStructCreate("wchar[" & $aRet[0] & "]") Local $pBuffer = DllStructGetPtr($tBuffer) $aRet = DllCall("Gdi32.dll", "int", "GetTextFaceW", "handle", $hDC, "int", $nCount, "ptr", $pBuffer) If @error Then _WinAPI_SelectObject($hDC, $hObjOrg) _WinAPI_ReleaseDC($hWnd, $hDC) Return SetError(4, 0, $aReturn) EndIf $aReturn[3] = DllStructGetData($tBuffer, 1) ; FontFacename $aReturn[0] = Round(((-1 * DllStructGetData($tFONT, 'Height')) * 72 / _WinAPI_GetDeviceCaps($hDC, 90)), 1) ; $LOGPIXELSY = 90 => DPI aware ; 0.25 = Magic Number, don't ask... _WinAPI_SelectObject($hDC, $hObjOrg) _WinAPI_ReleaseDC($hWnd, $hDC) $aReturn[1] = DllStructGetData($tFONT, 'Weight') $aReturn[2] = 2 * (True = DllStructGetData($tFONT, 'Italic')) + 4 * (True = DllStructGetData($tFONT, 'Underline')) + 8 * (True = DllStructGetData($tFONT, 'StrikeOut')) $aReturn[4] = DllStructGetData($tFONT, 'Quality') Return $aReturn EndFunc ;==>_GUICtrlGetFont ;----------------------------------------------------------------- #region _GUICtrlGetFont - Test GUI #include <Array.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> Global $FileList = _FileListToArray(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS), '*.ttf', 1) Global $FontList[UBound($FileList) - 1][2] For $i = 1 To $FileList[0] $FontList[$i - 1][0] = $FileList[$i] $FontList[$i - 1][1] = _WinAPI_GetFontResourceInfo($FileList[$i], 1) Next Opt("GUIOnEventMode", 1) Opt("GUICloseOnESC", 0) $hGUI = GUICreate("_GUICtrlGetFont", 1000, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $c_Label_Reference = GUICtrlCreateLabel("The quick brown fox jumps over the lazy dog", 10, 10, 980, 90) $c_Label_Clone = GUICtrlCreateLabel("The quick brown fox jumps over the lazy dog", 10, 100, 980, 90) GUISetState() $sErrors = "" Global $aFontAttributtes[8] = [0, 2, 4, 6, 8, 10, 12, 14] For $iFontAttributte = 0 To UBound($aFontAttributtes) - 1 For $iFontQuality = 0 To 5 For $iFontWeight = 100 To 800 Step 100 For $i = 0 To UBound($FontList) - 1 $sFontname = $FontList[$i][1] $sFontfile = $FontList[$i][0] For $iFontSize = 0.1 To 48 Step 0.001 $iFontSize = Round($iFontSize, 8) WinSetTitle($hGUI, "", "_GUICtrlGetFont - " & $sFontfile & " - " & $sFontname & " - " & $iFontSize & " - " & $iFontWeight & " - " & $aFontAttributtes[$iFontAttributte] & " - " & $sFontname & " - " & $iFontQuality) GUICtrlSetFont($c_Label_Reference, $iFontSize, $iFontWeight, $aFontAttributtes[$iFontAttributte], $sFontname, $iFontQuality) $aFont_Get = _GUICtrlGetFont($c_Label_Reference) GUICtrlSetFont($c_Label_Clone, $aFont_Get[0], $aFont_Get[1], $aFont_Get[2], $aFont_Get[3], $aFont_Get[4]) $iFontSize_Reference = _GUICtrlGetFont_Height_EM($c_Label_Reference) $iFontSize_Clone = _GUICtrlGetFont_Height_EM($c_Label_Clone) If $iFontSize_Reference <> $iFontSize_Clone Then ConsoleWrite("! " & $iFontSize_Reference & @TAB & $iFontSize_Clone & @TAB & @TAB & @TAB & $iFontSize & @TAB & $iFontWeight & @TAB & $aFontAttributtes[$iFontAttributte] & @TAB & $sFontname & @TAB & $iFontQuality & @CRLF) $sErrors &= $iFontSize & @TAB & $iFontWeight & @TAB & $aFontAttributtes[$iFontAttributte] & @TAB & $sFontname & @TAB & $iFontQuality & @CRLF ClipPut($sErrors) MsgBox(48 + 262144, "_GUICtrlGetFont - ERROR", $iFontSize_Reference & @CRLF & $iFontSize_Clone & @CRLF & @CRLF & $iFontSize & @CRLF & $iFontWeight & @CRLF & $aFontAttributtes[$iFontAttributte] & @CRLF & $sFontname & @CRLF & $iFontQuality, 10, $hGUI) Else ConsoleWrite($iFontSize_Reference & @TAB & $iFontSize & @TAB & $aFont_Get[0] & @CRLF) EndIf Next Next Next Next Next Func _GUICtrlGetFont_Height_EM($hWnd = -1) Local $hFONT If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) $hFONT = _SendMessage($hWnd, $WM_GETFONT) If Not $hFONT Then Return SetError(1, 0, 0) Local $tFONT = DllStructCreate($tagLOGFONT) Local $aReturn = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFONT, 'int', DllStructGetSize($tFONT), 'ptr', DllStructGetPtr($tFONT)) If @error Or $aReturn[0] = 0 Then Return SetError(2, 0, 0) Return Abs(DllStructGetData($tFONT, 'Height')) EndFunc ;==>_GUICtrlGetFont_Height_EM Func _Exit() Exit EndFunc ;==>_Exit #endregion _GUICtrlGetFont - Test GUI My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
KaFu Posted January 23, 2011 Author Posted January 23, 2011 (edited) Convinced ... might have introduced it as some other bugs were still in the code. Edited January 23, 2011 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)
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