einiger Fragen zu Treeview!!

  • Hi,
    Ich habe ein paar fragen zu treeview. Wie kann ich den einzelnen Items Icons geben? Wie man Icons gibt weis ich nur wenn ich das mache haben immer alle das selbe Icon ich will das jede gruppe ein eigenes hat.
    Wie kann ich ein Menü eröffnen wenn ich mit der rechten Maustaste auf ein Item drücke? ich will ein Menü in dem z.B. delete oder so steht.
    Und kann ich die ein einzelnen Items auch mit der Maus in eine andere TreeView gruppe ziehen?

    Und muss ich die icons unbedingt in ner dll abspeichern oder kann ich die auch als normals .ico laden oder so?
    Pls help me.

    Einmal editiert, zuletzt von hotwert (7. Februar 2010 um 22:26)

  • /push

    wie man einzelne Icons vergibt hab ich herausgefunden.

    Mich würde nur noch interessieren wie ich per rechter Maustaste ein Menü eröffnen kann bei den treeviewitems.
    Und ob ich die Items zwischen den Parentitems hinundher ziehen kann.

  • So wie ich das mausmenü mache hab ich schon gefunden :D

    Nur funzt das nicht so wie ich mir das denke.

    [autoit]

    $clientview[$test1] = GUICtrlCreateTreeViewItem($test1 & " " & $test2, $channelview[$cid])
    _GUICtrlTreeView_SetIcon($treeview1 ,$clientview[$test1], "hotwert.exe", 2)
    GUICtrlSetColor(-1, 0x000000)
    context1()
    Func context1()
    $kMenu1 = GUICtrlCreateContextMenu($clientview[$test1])
    $kick = GUICtrlCreateMenuItem("Kick",$kMenu1)
    $ban = GUICtrlCreateMenuItem("Ban",$kMenu1)
    EndFunc

    [/autoit]

    Das ganze steht immerhalb von case von der Gui

    [autoit]

    $nMsg = GUIGetMsg()
    Switch $nMsg

    [/autoit]

    sollte bekannt sein.^^
    Nur wenn ich das contextMenü erstelle wird z.B. $kick immer aufgerufen ohne das ich drücke.
    Das menü kann ich erst später erstellen weil die items ja sonst garnicht vorhanden sind im treeview.

    Ich hoffe jemand versteht so halbwegs was ich überhaupt will.^^
    Pls help ich sitz nun schon 3 stunden hier und finde keine Lösung ich hab schon so ziemlich alles durchprobiert was mir eingefallen ist.

  • Also ich hab einen button wenn ich den klicke wird der treeview aktuallisiert.

    hier ein beispiel script das ich schnell geschrieben habe.

    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ListBoxConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiTreeView.au3>
    dim $generalitem[9999]
    dim $childitem[9999]

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 633, 447, 193, 125)
    $update = GUICtrlCreateButton("update", 328, 56, 75, 25, 0)
    $TreeView1 = GUICtrlCreateTreeView(24, 24, 265, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    case $update
    _GuiCtrlTreeView_DeleteAll($treeview1)
    $rnd = random(0,100,1)
    for $i = 1 to $rnd step 1
    $rnd1 = random(1,10000)
    $rnd2 = random(1,1000)
    $generalitem[$i] = GUICtrlCreateTreeViewItem($rnd2, $treeview1)
    $childitem[$i] = GUICtrlCreateTreeViewItem($rnd1, $generalitem[$i])

    $kMenu1 = GUICtrlCreateContextMenu($generalitem[$i])
    GUICtrlCreateMenuItem("exit",$kMenu1)
    GUIctrlSetOnEvent(-1, "test")

    Next
    EndSwitch
    WEnd

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

    func test()
    Exit
    endfunc

    [/autoit]


    Nun will ich zu jeden einzelnen item ein eigenes Contextmenü erschaffen was grundsätzlich ja mal möglich ist.
    Allerdings kann ich das Contextmenü nicht in der GUI verankern weil die items vom treeview noch nicht erstellt sind.

    Ich hoffe es ist nun ein bisschen verständlicher^^

  • Moin,

    ich habe da mal etwas zusammengepatcht und es funktioniert sogar ... :):D

    Du musst es dir halt noch etwas anpassen ...

    Spoiler anzeigen
    [autoit]


    #include <GuiConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <GuiImageList.au3>
    #include <WindowsConstants.au3>

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

    Opt('MustDeclareVars', 1)

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

    ;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    Global Const $TVN_RBUTTONUP = -5
    ;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

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

    Global $hTreeView, $OptionsDummy, _
    $OptionsCommon, $OptionsContext, _
    $OptionsExit, $OptionsFile

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

    $Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

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

    Global $hImage, $hStateImage

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

    _Main()

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

    Func _Main()

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

    Local $hItem[10], $hChildItem[30], $iYItem = 0, $iYRand, $iXRand
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

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

    GUICreate("TreeView Hit Test Item", 400, 300)

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

    ;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    CreateTVPopupMenu( )
    ;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

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

    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    _GUICtrlTreeView_SetUnicodeFormat($hTreeView, False)
    GUISetState()

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

    _CreateNormalImageList()
    _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)

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

    _CreateStateImageList()
    _GUICtrlTreeView_SetStateImageList($hTreeView, $hStateImage)

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

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 0 To 9
    $hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x), 4, 5)
    _GUICtrlTreeView_SetStateImageIndex($hTreeView, $hItem[$x], 1)
    For $y = 1 To 3
    $hChildItem[$iYItem] = _GUICtrlTreeView_AddChild($hTreeView, $hItem[$x], StringFormat("[%02d] New Child", $y), 0, 3)
    _GUICtrlTreeView_SetStateImageIndex($hTreeView, $hChildItem[$iYItem], 1)
    $iYItem += 1
    Next
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

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

    _GUICtrlTreeView_SelectItem($hTreeView, $hItem[0])
    _GUICtrlTreeView_SetStateImageIndex($hTreeView, $hItem[0], 2)

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

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

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

    Func _CreateNormalImageList()
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 110)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 131)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 168)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 146)
    EndFunc ;==>_CreateNormalImageList

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

    Func _CreateStateImageList()
    $hStateImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hStateImage, "shell32.dll", 3)
    _GUIImageList_AddIcon($hStateImage, "shell32.dll", 4)
    EndFunc ;==>_CreateStateImageList

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

    ;««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    Func WM_NOTIFY($hwnd, $message, $wParam, $lParam)

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

    Local $nmhdr = DllStructCreate("hwnd hwndFrom;ptr idFrom;int code", $lParam)
    Local $idFrom = DllStructGetData($nmhdr, "idFrom")

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

    Switch ($idFrom)

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

    Case $hTreeView

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

    Switch (DllStructGetData($nmhdr, "code"))

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

    Case $TVN_RBUTTONUP
    ShowMenu($hwnd, $idFrom, $OptionsContext)
    EndSwitch
    EndSwitch

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

    Return $GUI_RUNDEFMSG

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

    EndFunc

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

    Func CreateTVPopupMenu( )

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

    ; At first create a dummy control for the options and a contextmenu for it
    $OptionsDummy = GUICtrlCreateDummy( )
    $OptionsContext = GUICtrlCreateContextMenu($OptionsDummy)
    $OptionsCommon = GUICtrlCreateMenuItem("Common", $OptionsContext)
    $OptionsFile = GUICtrlCreateMenuItem("File", $OptionsContext)
    GUICtrlCreateMenuItem("", $OptionsContext) ;----------------
    $OptionsExit = GUICtrlCreateMenuItem("Exit", $OptionsContext)

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

    EndFunc

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

    ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
    Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
    EndFunc ;==>TrackPopupMenu

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

    ; Show a menu in a given GUI window which belongs to a given GUI ctrl
    Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos
    Local $hMenu = GUICtrlGetHandle($nContextID)

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

    $arPos = MouseGetPos( )

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

    If (IsArray ($arPos)) Then
    TrackPopupMenu($hWnd, $hMenu, $arPos[0], $arPos[1])
    Else
    Return False
    EndIf

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

    Return True

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

    EndFunc ;==>ShowMenu

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

    ;«««««««««««««««««««««««««««««««« End of File «««««««««««««««««««««««««««««««««

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

    Gruß
    Greenhorn


  • hmm aber dein ContextMenü geht ja über die ganze Gui meins sollte nur für einzelne items gelten.


    hier siehst du das parentitem und childitem ein anderes contextmenü haben.
    Das Contextmenü wird ja auch bei bei parent und childitem angezeigt nur wenn ich draufkicke passiert nichts.

    Trotzdem thx für dein script. Das mit den Images kann ich sicher mal verwenden.^^

    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ListBoxConstants.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GuiTreeView.au3>
    dim $generalitem[9999]
    dim $childitem[9999]

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 633, 447, 193, 125)
    $update = GUICtrlCreateButton("update", 328, 56, 75, 25, 0)
    $TreeView1 = GUICtrlCreateTreeView(24, 24, 265, 289)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    case $update
    _GuiCtrlTreeView_DeleteAll($treeview1)
    $rnd = random(0,100,1)
    for $i = 1 to $rnd step 1
    $rnd1 = random(1,10000)
    $rnd2 = random(1,1000)
    $generalitem[$i] = GUICtrlCreateTreeViewItem($rnd2, $treeview1)
    $childitem[$i] = GUICtrlCreateTreeViewItem($rnd1, $generalitem[$i])

    $kMenu1 = GUICtrlCreateContextMenu($generalitem[$i])
    GUICtrlCreateMenuItem("exit",$kMenu1)
    GUIctrlSetOnEvent(-1, "test")

    $kMenu2 = GUICtrlCreateContextMenu($childitem[$i])
    GUICtrlCreateMenuItem("test",$kMenu2)
    GUIctrlSetOnEvent(-1, "test1")

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


    Next
    EndSwitch
    WEnd

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

    func test()
    Exit
    endfunc

    [/autoit]

    und so sieht das aus bei mir:

    Ein Teamspeak admin programm
    Bei den channels will ich ein contextmenü mit mit Channeledit usw.
    Bei den Usern soll Kick, Ban usw. stehen.

    [Blockierte Grafik: http://img237.imageshack.us/img237/7080/18339083.jpg]

    Einmal editiert, zuletzt von hotwert (8. Februar 2010 um 21:34)