Jump to content
Sign in to follow this  

How to retrieve Fontsize and Weight?

Recommended Posts



just a short question:

Is it possible to get the GuiCtrlCreateLabel Font Attributes?

i.e.: I have a GuiCtrlCreateLabel that i have formated with GuiCtrlSetFont. My question is, is it possible to "readout" the give Fontsize, and Weight later in a script?

thx for you help



Share this post

Link to post
Share on other sites

Not that I know of, and frankly I don't see the point. If you're setting it with GUICtrlSetFont() then you already know the size and weight. Because you set it. Just store it in an array and use when needed.

Share this post

Link to post
Share on other sites

Something like this?

#Include <Array.au3>
#Include <FontConstants.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

GUICreate('MyGUI', 300, 200)
$Label = GUICtrlCreateLabel('Simple Text', 20, 40, 100, 22)
GUICtrlSetFont(-1, 12, 700, 2 + 4, 'Tahoma')

$aFont = GUICtrlGetFont($Label)


Until GUIGetMsg() = -3


[0] - Size
[1] - Weight
[2] - Attribute
[3] - Name
[4] - Quality


Func GUICtrlGetFont($CtrlID)

    Local $hWnd = GUICtrlGetHandle($CtrlID)

    If Not $hWnd Then
        Return 0

    Local $Ret, $hDC, $hFont, $tFont
    Local $aFont = 0

    $hDC = _WinAPI_GetDC($hWnd)
    $hFont = _SendMessage($hWnd, $WM_GETFONT)
    $tFont = DllStructCreate($tagLOGFONT)
    $Ret = DllCall('gdi32.dll', 'int', 'GetObjectW', 'ptr', $hFont, 'int', DllStructGetSize($tFont), 'ptr', DllStructGetPtr($tFont))
    If (Not @error) And ($Ret[0]) Then
        Dim $aFont[5] = [0]
        $aFont[0] = -Round(DllStructGetData($tFont, 'Height') / _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY) * 72, 1)
        $aFont[1] = DllStructGetData($tFont, 'Weight')
        $aFont[2] = BitOR(2 * (DllStructGetData($tFont, 'Italic') <> 0), 4 * (DllStructGetData($tFont, 'Underline') <> 0), 8 * (DllStructGetData($tFont, 'Strikeout') <> 0))
        $aFont[3] = DllStructGetData($tFont, 'FaceName')
        $aFont[4] = DllStructGetData($tFont, 'Quality')
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $aFont
EndFunc   ;==>GUICtrlGetFont
Edited by Yashied

Share this post

Link to post
Share on other sites

@Yashied: Yes! - That's it, but i am to dump to get this into my code. so could you assist a little bit? :blink:

the following code is just my training place (my personal proof of possibility). if you hover over the "link" BIG HOVER you'll see, why i need to have the fontsize and weight. with notepad++ (well i use scite for programming) in line 75 (GUICtrlSetFont($lastControlID, 8.5)) i need to have the fontsize and weight from the control that the mouse was coming from. my problem here is, that on initialstart the gui crashes (if i inserted your function and call it at (not shown here!) line 74) because the backpic is also a control.

the totally project aim is to build something like the windows 7 systemcontrolcenter with links in different sizes.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#Include <Misc.au3>

$gui = GUICreate ("TestGUI", 384, 384, -1, -1, -1, $WS_EX_TOPMOST)
GUISetBkColor (0xABCEDF, $gui)
$bckpicState = GUICtrlCreatePic (@ScriptDir & "\LogonScreenPE30.bmp", 0, 0, 384, 384)

                            GUICtrlSetState ($bckpicState, $GUI_DISABLE)
$test0 = _Hyperlinklabel("Hallo Welt", 10, 11, 256, 16, 8.5, 400)
GUICtrlSetBkColor ($test0, 0xAAAAAA)
$test1 = _Hyperlinklabel("Hallo Ihr", 10, 27, 256, 16, 8.5, 400)
GUICtrlSetBkColor ($test1, 0xCCCCCC)
$test2 = _Hyperlinklabel("Hallo DuDA", 10, 43, 256, 16, 8.5, 400)
GUICtrlSetBkColor ($test2, 0xEEEEEE)
$test3 = _Hyperlinklabel("BIG HOVER", 10, 128, 256, 22, 12, 800)
GUICtrlSetBkColor ($test2, 0xEEEEEE)



While 1
    $msg = GUIGetMsg()
    $aCursorInfo = GUIGetCursorInfo()

        Case $msg = $GUI_EVENT_CLOSE
        Case $msg = $test0
            MsgBox (0, "", "0")
        Case $msg = $test1
            MsgBox (0, "", "1")
        Case $msg = $test2
            MsgBox (0, "", "2")
        Case $msg = _IsPressed("0D")


    If Not @error Then
        ToolTip ($aCursorInfo[4] & " " & $lastControlID & @CR & GUICtrlRead ($lastControlID))
            Case $aCursorInfo[4] = $test0
                _Hyperlinkactive($test0, 12, 800)
            Case $aCursorInfo[4] = $test1
                _Hyperlinkactive($test1, 9, 800)
            Case $aCursorInfo[4] = $test2
                _Hyperlinkactive($test2, 9, 800)
            Case $aCursorInfo[4] = $test3
                _Hyperlinkactive($test3, 12, 400)
            Case $aCursorInfo[4] = $bckpicState
                _Hyperlinkactive("NoHoverSmall", 8.5, 400)

Func _Hyperlinklabel($htext, $hposX, $hposY, $hwidth, $hhight, $hsize, $hweight)
    $label = GUICtrlCreateLabel ($htext, $hposX, $hposY, $hwidth, $hhight, $SS_CENTER)
    GUICtrlSetFont($label, $hsize, $hweight, 0)
    Return $label

Func _Hyperlinkactive($controlID, $hfontsize, $hfontwight)
        Case $linkact=False
            GUICtrlSetFont($controlID, $hfontsize, $hfontwight, 4)
            GUICtrlSetCursor($controlID, 0)
        Case $controlID <> $lastControlID
            GUICtrlSetFont($lastControlID, 8.5)
            $lastControlID = $controlID
        Case $controlID = "NoHoverSmall"
            GUICtrlSetFont($lastControlID, $hfontsize, $hfontwight)
            $lastControlID = $controlID

thx. for you help.

pic is in zip archive!




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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.