TreeView macht Probleme

  • Hallo nochmal!

    Passend zu dem noch offenen Threat weiter unten (oder oben, wenn jemand antwortet ;) ) hier eine weitere Frage:

    Dieser Code hier:

    [autoit]

    Global $GUI_left_treeview = GUICtrlCreateTreeView(10, 50, 180, @DesktopHeight - 364, 8247, 512)
    GUICtrlSetResizing(-1, 352)
    GUICtrlSetBkColor(-1, 0xFFFF00)
    Global $GUI_left_treeview_new_make = GUICtrlCreateTreeViewItem("Test", $GUI_left_treeview)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetCursor(-1, 0)

    [/autoit]


    Macht Probleme: Alles was ich auf ein Item beziehe (SetFont, oder SetCursor) funktioniert nicht. Beziehe ich es auf das TreeView, wird es für alle Elemente übernommen. Habe ich einen falschen Style gesetzt?

    Einen schönen Abend und ein schönes Wochenende noch!

    Einmal editiert, zuletzt von MatthiasG. (16. November 2009 um 07:36)

  • Hallo nochmal!

    Ich habe das jetzt erstellen können, aber wie steuere ich die überhaupt an? Ich habe ja nur einen Handle, die GUICtrlSet...-Funktionen nehmen aber nur Controlids an. Was tun?

    • Offizieller Beitrag

    Bekommst du ja:
    als Rückgabe von
    - _GUICtrlTreeView_Add oder _GUICtrlTreeView_AddChild
    - _GUICtrlTreeView_FindItem
    - _GUICtrlTreeView_GetSelection
    :whistling:

    Aber falls du GUICtrlSetFont, ...SetBkCol nutzen möchtest: Diese sind, wie schon gesagt NICHT für die Item zuständig, sondern nur für das Control (das TreeView).

  • Ja, aber ich möchte doch nur einzelne Elemente anpassen. Im Beispiel klappt das auch (GUICtrlCreateListView_Item o.ä.)

    • Offizieller Beitrag

    Ach, hatte ich jetzt nicht dran gedacht, da ich es kaum anwende: GUICtrlCreateTreeViewItem gibt die ID des Item zurück. Wenn du also damit deine Item erstellst, kannst du die ID's in einem Array auffangen und somit auch die Font und Colorfunktionen nutzen.

  • Entschuldige die späte Antwort, ich war eine Zeit lang krank... Nein, es war keine Schweinegrippe. Also keine Angst, ihr könnt den Bildschirm gefahrlos berühren :P

    Hier der Code:

    [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit][autoit][/autoit][autoit]

    Global $GUI_Gui = GUICreate("TreeView - TestGUI", @DesktopWidth - 300, @DesktopHeight - 100, -1, -1, -2133917184, 0x02000000)
    GUISetOnEvent(-3, "_GUI_Event_Close")
    GUISetBkColor(0xFFFFFF)
    GUIRegisterMsg(36, "_GUI_MY_WM_GETMINMAXINFO")

    [/autoit][autoit][/autoit][autoit]

    Global $GUI_left_treeview = GUICtrlCreateTreeView(10, 40, 180, @DesktopHeight - 354, 8247, 512)
    GUICtrlSetResizing(-1, 354)
    GUICtrlSetBkColor(-1, 0xFFFF00)

    [/autoit][autoit][/autoit][autoit]

    GUICtrlCreateLabel("", 0, 0, 200, @DesktopHeight - 100)
    GUICtrlSetBkColor(-1, 0xFFFF00)
    GUICtrlSetResizing(-1, 256)

    [/autoit][autoit][/autoit][autoit]

    Global $GUI_left_treeview_new_make = GUICtrlCreateTreeViewItem("Testeintrag #1", $GUI_left_treeview)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetCursor(-1, 0)
    Global $GUI_left_treeview_new_import = GUICtrlCreateTreeViewItem("Testeintrag #2", $GUI_left_treeview)
    Global $GUI_left_treeview_new_download = GUICtrlCreateTreeViewItem("Testeintrag #3", $GUI_left_treeview)

    [/autoit][autoit][/autoit][autoit]

    GUISetState(@SW_SHOW, $GUI_Gui)

    [/autoit][autoit][/autoit][autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func _GUI_Event_Close()
    Exit
    EndFunc ;==>_GUI_Event_Close

    [/autoit][autoit][/autoit][autoit]

    Func _GUI_MY_WM_GETMINMAXINFO($hWnd, $msg, $wParam, $lParam)
    If $hWnd = $GUI_Gui Then
    Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($minmaxinfo, 7, 700) ; min X
    DllStructSetData($minmaxinfo, 8, 500) ; min Y
    EndIf
    EndFunc ;==>_GUI_MY_WM_GETMINMAXINFO

    [/autoit]

    Vorher extra aufgeräumt, wer mich kennt, kennt auch meinen normalen Code ;)

  • Hi, so wie es aussieht, wird zwar eine ID vergeben, allerdings kann man diese ID nicht mit GUICtrlSetFont() verwenden. GUICtrlSetFont() generiert bei Verwendung einen Fehler (code 0)

    • Offizieller Beitrag

    Na dann bleibt nur der etwas aufwändigere Weg über selbst zeichnen. :D
    Allerdings kann ich noch nicht sagen, ob CUSTOMDRAW auch für TreeView möglich ist, habe ich noch nie probiert. Wäre dann analog zu meiner ListView-Format UDF.

    Edit: Ja, gibt es auch für TreeView. Ich gucke mal, dass ich ein kleines Bsp. machen kann.

  • Seltsam, im Beispiel von GUICtrlListView funktioniert es doch?

    Naja, würde mich auf jedem Fall über ein Beispiel freuen :rolleyes:

    • Offizieller Beitrag

    Damit als NEU erscheint, ausnahmsweise ein Doppelpost.

    Hier die Lösung um Text- und Hintergrundfarbe für jedes Item separat zu setzen. Font ist aufwändiger, mache ich vielleicht später noch.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StructureConstants.au3>
    #include <TreeViewConstants.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    Global $GUI_Gui = GUICreate("TreeView - TestGUI", @DesktopWidth - 300, @DesktopHeight - 100)
    GUISetOnEvent(-3, "_GUI_Event_Close")
    GUISetBkColor(0xFFFFFF)

    [/autoit] [autoit][/autoit] [autoit]

    Global $TV = GUICtrlCreateTreeView(10, 40, 180, @DesktopHeight - 354, _
    BitOR(Default,$TVS_TRACKSELECT,$TVS_FULLROWSELECT), $WS_EX_CLIENTEDGE)
    Global $hTV = GUICtrlGetHandle($TV)

    [/autoit] [autoit][/autoit] [autoit]

    Global $aTVI[6]
    For $i = 0 To 5
    $aTVI[$i] = GUICtrlGetHandle(GUICtrlCreateTreeViewItem("Testeintrag #" & $i+1, $TV))
    Next
    Global $aColor[3][3] ; [$i][0]=hWnd, [$i][1]=txtCol, [$i][2]=bkCol
    $aColor[0][0] = $aTVI[1]
    $aColor[0][1] = 0xffffff
    $aColor[0][2] = 0xffff00

    [/autoit] [autoit][/autoit] [autoit]

    $aColor[1][0] = $aTVI[3]
    $aColor[1][1] = 0x000000
    $aColor[1][2] = 0x0000ff

    [/autoit] [autoit][/autoit] [autoit]

    $aColor[2][0] = $aTVI[5]
    $aColor[2][1] = 0x0000ff
    $aColor[2][2] = 0xffff00

    [/autoit] [autoit][/autoit] [autoit]

    Global $currWindow = WinGetHandle($GUI_Gui)
    Global $txtColor, $bkColor

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW, $GUI_Gui)
    GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY_TREEVIEW')
    _WinAPI_RedrawWindow($currWindow)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUI_Event_Close()
    Exit
    EndFunc ;==>_GUI_Event_Close

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY_TREEVIEW($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iCode, $tNMHDR, $tItemSpec
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    [/autoit] [autoit][/autoit] [autoit]

    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    If $hWndFrom <> $hTV Then Return $GUI_RUNDEFMSG

    [/autoit] [autoit][/autoit] [autoit]

    $iCode = DllStructGetData($tNMHDR, "Code")
    If $iCode = $NM_CUSTOMDRAW Then
    Local $iDrawStage, $iItem, $tCustDraw = DllStructCreate($tagNMTVCUSTOMDRAW, $lParam)
    $iDrawStage = DllStructGetData($tCustDraw, 'DrawStage')
    If $iDrawStage = $CDDS_ITEMPREPAINT Then
    $tItemSpec = DllStructCreate('dword', DllStructGetPtr($tCustDraw, 'ItemSpec'))
    $iItem = DllStructGetData($tItemSpec, 1)
    For $i = 0 To UBound($aColor) -1
    If $iItem = $aColor[$i][0] Then
    DllStructSetData($tCustDraw, 'ClrText', RGB2BGR($aColor[$i][1]))
    DllStructSetData($tCustDraw, 'ClrTextBk', RGB2BGR($aColor[$i][2]))
    Return $CDRF_NEWFONT
    EndIf
    Next
    EndIf
    EndIf
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY_TREEVIEW

    [/autoit] [autoit][/autoit] [autoit]

    Func RGB2BGR($iColor)
    Local $sH = Hex($iColor,6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH,3,2) & StringLeft($sH, 2)
    EndFunc ;==>RGB2BGR

    [/autoit]
  • Hallo nochmal,

    erstmal danke für das Beispiel, werde es mir nach der Schule genau anschauen.

    Das mit dem TreeView meinte ich auch:

    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <TreeViewConstants.au3>
    #include <StaticConstants.au3>

    [/autoit][autoit][/autoit][autoit]

    Opt('MustDeclareVars', 1)

    [/autoit][autoit][/autoit][autoit]

    Example()

    [/autoit][autoit][/autoit][autoit]

    Func Example()
    Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
    Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel, $compinfo
    Local $togglebutton, $infobutton, $statebutton, $cancelbutton
    Local $msg, $item, $hItem, $text

    GUICreate("My GUI with treeview", 350, 215)

    [/autoit][autoit][/autoit][autoit]

    $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
    $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
    $useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
    $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
    $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)

    [/autoit][autoit][/autoit][autoit]

    $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
    $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
    GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "aboutlabel"-text during initialization
    $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
    GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "compinfo"-text during initialization

    [/autoit][autoit][/autoit][autoit]

    GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
    $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
    $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
    $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
    $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

    [/autoit][autoit][/autoit][autoit]

    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
    GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold

    [/autoit][autoit][/autoit][autoit]

    GUISetState()
    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
    ExitLoop

    [/autoit][autoit][/autoit][autoit]

    Case $msg = $togglebutton ; Toggle the bold painting
    If BitAND(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then
    GUICtrlSetState($generalitem, 0)
    GUICtrlSetState($displayitem, 0)
    Else
    GUICtrlSetState($generalitem, $GUI_DEFBUTTON)
    GUICtrlSetState($displayitem, $GUI_DEFBUTTON)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    Case $msg = $infobutton
    $item = GUICtrlRead($treeview) ; Get the controlID of the current selected treeview item
    If $item = 0 Then
    MsgBox(64, "TreeView Demo", "No item currently selected")
    Else
    $text = GUICtrlRead($item, 1) ; Get the text of the treeview item
    If $text == "" Then
    MsgBox(16, "Error", "Error while retrieving infos about item")
    Else
    MsgBox(64, "TreeView Demo", "Current item selected is: " & $text) ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item
    EndIf
    EndIf

    [/autoit][autoit][/autoit][autoit]

    Case $msg = $statebutton
    $item = GUICtrlRead($treeview)
    If $item > 0 Then
    $hItem = GUICtrlGetHandle($item)
    GUICtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
    Case $msg = $generalitem
    GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)

    [/autoit][autoit][/autoit][autoit]

    Case $msg = $aboutitem
    GUICtrlSetState($compinfo, $GUI_HIDE)
    GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)

    [/autoit][autoit][/autoit][autoit]

    Case $msg = $compitem
    GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
    EndSelect
    WEnd

    [/autoit][autoit][/autoit][autoit]

    GUIDelete()
    EndFunc ;==>Example

    [/autoit][autoit][/autoit][autoit]

    Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx

    [/autoit][autoit][/autoit][autoit]

    For $idx = $hidestart To $hideend
    GUICtrlSetState($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
    GUICtrlSetState($idx, $GUI_SHOW)
    Next
    EndFunc ;==>GUIChangeItems

    [/autoit]

    Das ist das Beispiel aus der Hilfe, und es läuft (wird aber auch nur die Farbe verändert)...

    Edit: Achso, funktioniert nur über

    [autoit]

    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))

    [/autoit]

    , das fettmachen!
    Dann vergiss das mit dem Font! Funktioniert dann ja auch so :D

    Danke für die Mühe allerseits, besonders an BugFix (mal wieder ;) )! :thumbup: