Jump to content
Sign in to follow this  
ZetupEXE

How to retrieve Fontsize and Weight?

Recommended Posts

ZetupEXE

Hi,

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

cu.

Zetup-EXE

Share this post


Link to post
Share on other sites
AdmiralAlkex

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
Yashied

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')
GUISetState(@SW_SHOW)

$aFont = GUICtrlGetFont($Label)

_ArrayDisplay($aFont)

Do
Until GUIGetMsg() = -3

#cs

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

#ce

Func GUICtrlGetFont($CtrlID)

    Local $hWnd = GUICtrlGetHandle($CtrlID)

    If Not $hWnd Then
        Return 0
    EndIf

    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')
    EndIf
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $aFont
EndFunc   ;==>GUICtrlGetFont
Edited by Yashied

Share this post


Link to post
Share on other sites
ZetupEXE

@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)

GUISetState(@SW_SHOW)

$linkact=False
$lastControlID="None"

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

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


    EndSelect


    If Not @error Then
        ToolTip ($aCursorInfo[4] & " " & $lastControlID & @CR & GUICtrlRead ($lastControlID))
        Select
            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)
        EndSelect
    EndIf
WEnd

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
EndFunc

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

thx. for you help.

pic is in zip archive!

cu.

Zetup-EXE

LogonScreenPE30.7z

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.