Jump to content

_GUICtrlGetFont()


KaFu
 Share

Recommended Posts

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

#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 by KaFu
Link to comment
Share on other sites

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

KaFu,

Works without error on the installed fonts in my Vista 32 box. Nice work! :)

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

Link to comment
Share on other sites

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 by Yashied
Link to comment
Share on other sites

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

Result: 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 by KaFu
Link to comment
Share on other sites

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 to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

@KaFu

A simple test.

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