Sign in to follow this  
Followers 0
Glyph

[resolved] Problem setting font with _GUICtrlTreeView_Create

3 posts in this topic

#1 ·  Posted (edited)

http://www.autoitscript.com/forum/index.php?showtopic=44286&st=0&p=330369&hl=treeview%20font&fromsearch=1&#entry330369

So close, but not quite there. That's the same problem I am having!

I've tried GUICtrlSetFont with no success. Changing the whole treeview font is my problem.

$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 10, 120, 322)
GUICtrlSetFont($hTreeView, 7, 200, Default, "Courier")

 _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 1 To Random(2, 10, 1)
        $hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
        For $y = 1 To Random(2, 10, 1)
            _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
        Next
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

I appreciate any help, thanks.

Edited by Glyph

tolle indicium

Share this post


Link to post
Share on other sites



#include <GUITreeView.au3>
#include <WindowsConstants.au3>

$GUI = GUICreate('Test', 420, 420)
;$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 10, 120, 322)
$TreeView = GUICtrlCreateTreeView(10, 10, 400, 400, -1, $WS_EX_CLIENTEDGE)
$hTreeView = GUICtrlGetHandle($TreeView)
;GUICtrlSetFont(_WinAPI_GetDlgCtrlID($hTreeView), 7, 200, Default, "Courier")
GUICtrlSetFont($TreeView, 7, 200, Default, "Courier")

 _GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 1 To Random(2, 10, 1)
    $hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
    For $y = 1 To Random(2, 10, 1)
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
    Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)

GUISetState()
Do
Until GUIGetMsg() = -3

_GUICtrlTreeView_Destroy($hTreeView)
GUIDelete()
Exit

It won't work this way without creating the control using the native functions, i.e. GUICtrlCreate*. You can use the _WinAPI_SetFont() function with a font object to change the window font:

#include <FontConstants.au3>
#include <GUITreeView.au3>
#include <WindowsConstants.au3>

$hFont = _WinAPI_CreateFont(10, _
        10, _
        0, _
        0, _
        $FW_NORMAL, _
        False, _
        False, _
        False, _
        $DEFAULT_CHARSET, _
        $OUT_OUTLINE_PRECIS, _
        $CLIP_DEFAULT_PRECIS, _
        $DEFAULT_QUALITY, _
        $DEFAULT_PITCH, _
        'Courier')


$GUI = GUICreate('Test', 420, 420)
$hTreeView = _GUICtrlTreeView_Create($GUI, 10, 10, 400, 400)

If $hFont Then _WinAPI_SetFont($hTreeView, $hFont)

_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 1 To Random(2, 10, 1)
    $hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
    For $y = 1 To Random(2, 10, 1)
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
    Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)

GUISetState()
Do
Until GUIGetMsg() = -3

_GUICtrlTreeView_Destroy($hTreeView)
If $hFont Then _WinAPI_DeleteObject($hFont)
GUIDelete()
Exit

Share this post


Link to post
Share on other sites

That's exactly what I was looking for, thank you.


tolle indicium

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  
Followers 0