TreeView

  • Hallo
    Ich hab mal wieder ein Frage
    Und zwar wollte ich wissen wie ich herausbekomme, wenn man in einer TreeView auf das + Zeihen drückt, also das ich das Erfahre und dann was ausführen kann
    Ich wollte dann gerne einfach die Item-ID, des angeklickten Items.
    Ich hab schon mal ein script gemacht^^

    Spoiler anzeigen
    [autoit]

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

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("TreeView", 633, 447, 193, 125)
    $TreeView1 = GUICtrlCreateTreeView(4, 4, 247, 433)
    $TreeView1_0 = GUICtrlCreateTreeViewItem("Test", $TreeView1)
    $TreeView1_1 = GUICtrlCreateTreeViewItem("Test", $TreeView1_0)
    $TreeView1_2 = GUICtrlCreateTreeViewItem("Test2", $TreeView1)
    $TreeView1_3 = GUICtrlCreateTreeViewItem("Test", $TreeView1_2)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    mfg. Jam00

    • Offizieller Beitrag

    Hier ein Bsp. - die gelesenen Werte werden als Fenstertitel gesetzt:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>

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

    Opt("MustDeclareVars", 1)
    Opt("GuiOnEventMode", 1)

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

    Global $gui, $hImage, $hTV, $aID_Sub[5], $ID_Table, $item

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

    $gui = GUICreate('Test TreeView')
    GUISetOnEvent($GUI_EVENT_CLOSE, '_end')
    $hTV = GUICtrlCreateTreeView(10,10,300,150,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
    $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    Global $WM_NOTIFY_DUMMY = GUICtrlCreateDummy()
    GUICtrlSetOnEvent($WM_NOTIFY_DUMMY,"click_TV")

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

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 98)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 96)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 36)
    _GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

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

    _GUICtrlTreeView_BeginUpdate($hTV)
    $ID_Table = _GUICtrlTreeView_Add($hTV, 0, 'Table', 0, 0)
    For $i = 1 To 5
    $aID_Sub[$i-1] = _GUICtrlTreeView_AddChild($hTV, $ID_Table, 'Sub' & $i, 1, 1)
    For $j = 1 To 3
    $item = _GUICtrlTreeView_AddChild($hTV, $aID_Sub[$i-1], 'Sub_Sub' & $j, 2, 2)
    Next
    Next
    _GUICtrlTreeView_EndUpdate($hTV)
    _GUICtrlTreeView_Expand($hTV, $ID_Table)

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

    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

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

    While 1
    Sleep(100)
    WEnd

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

    Func _end()
    Exit
    EndFunc

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

    Func click_TV()
    Local $hTVItem = _GUICtrlTreeView_GetSelection($hTV)
    Local $hParent = _GUICtrlTreeView_GetParentHandle($hTV, $hTVItem)
    Local $title = ''
    If $hParent Then $title = _GUICtrlTreeView_GetText($hTV,$hParent) & ' / '
    WinSetTitle($gui, '', $title & _GUICtrlTreeView_GetText($hTV,$hTVItem))
    EndFunc

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTV
    If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV)

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

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeview
    Switch $iCode
    Case $NM_CLICK
    GUICtrlSendToDummy($WM_NOTIFY_DUMMY)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
  • Okay, THX guck ich mir mal an, jetzt hab ich noch zwei Fragen:
    Was muss ich bei FileFindFirstFile für einen Suchkriterienstring eingeben, damit er mir nur Ortner anzeigt?
    Und wie bekomme ich die Icons vonn offenen Fenster? Das kann windows doch auch, z.B. in der Taskleiste

    EDIT:
    Bei deinem Beispiel, Meldet der doch immer wenn man auf die TreeView klickt, ich wollte das er es merkt wenn man ein Menü aufklappt

    mfg. Jam00

  • Wie so?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>

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

    Opt("MustDeclareVars", 1)
    Opt("GuiOnEventMode", 1)

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

    Global $gui, $hImage, $hTV, $aID_Sub[5], $ID_Table, $item

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

    $gui = GUICreate('Test TreeView')
    GUISetOnEvent($GUI_EVENT_CLOSE, '_end')
    $hTV = GUICtrlCreateTreeView(10,10,300,150,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
    $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    Global $WM_NOTIFY_DUMMY = GUICtrlCreateDummy()
    GUICtrlSetOnEvent($WM_NOTIFY_DUMMY,"click_TV")

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

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 98)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 96)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 36)
    _GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

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

    _GUICtrlTreeView_BeginUpdate($hTV)
    $ID_Table = _GUICtrlTreeView_Add($hTV, 0, 'Table', 0, 0)
    For $i = 1 To 5
    $aID_Sub[$i-1] = _GUICtrlTreeView_AddChild($hTV, $ID_Table, 'Sub' & $i, 1, 1)
    For $j = 1 To 3
    $item = _GUICtrlTreeView_AddChild($hTV, $aID_Sub[$i-1], 'Sub_Sub' & $j, 2, 2)
    Next
    Next
    _GUICtrlTreeView_EndUpdate($hTV)
    _GUICtrlTreeView_Expand($hTV, $ID_Table)

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

    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

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

    While 1
    Sleep(100)
    WEnd

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

    Func _end()
    Exit
    EndFunc

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

    Func click_TV()
    Local $hTVItem = _GUICtrlTreeView_GetSelection($hTV)
    Local $hParent = _GUICtrlTreeView_GetParentHandle($hTV, $hTVItem)
    Local $title = ''
    If $hParent Then $title = _GUICtrlTreeView_GetText($hTV,$hParent) & ' / '
    WinSetTitle($gui, '', $title & _GUICtrlTreeView_GetText($hTV,$hTVItem))
    EndFunc

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTV
    If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV)

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

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeview
    Switch $iCode
    Case $TVN_ITEMEXPANDING
    GUICtrlSendToDummy($WM_NOTIFY_DUMMY)
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]

    Dann geht aber Irgendwie garnix mehr

    mfg. Jam00

    • Offizieller Beitrag

    Was ist Expand?


    = Ausklappen

    Bsp.:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <TreeViewConstants.au3>
    #include <WindowsConstants.au3>
    #include <Array.au3>

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

    Opt("MustDeclareVars", 1)
    Opt("GuiOnEventMode", 1)

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

    Global $gui, $hImage, $hTV, $aID_Sub[5], $ID_Table, $item

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

    $gui = GUICreate('Test TreeView')
    GUISetOnEvent($GUI_EVENT_CLOSE, '_end')
    $hTV = GUICtrlCreateTreeView(10,10,300,150,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
    $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

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

    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 98)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 96)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 36)
    _GUICtrlTreeView_SetNormalImageList($hTV, $hImage)

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

    _GUICtrlTreeView_BeginUpdate($hTV)
    $ID_Table = _GUICtrlTreeView_Add($hTV, 0, 'Table', 0, 0)
    For $i = 1 To 5
    $aID_Sub[$i-1] = _GUICtrlTreeView_AddChild($hTV, $ID_Table, 'Sub' & $i, 1, 1)
    For $j = 1 To 3
    $item = _GUICtrlTreeView_AddChild($hTV, $aID_Sub[$i-1], 'Sub_Sub' & $j, 2, 2)
    Next
    Next
    _GUICtrlTreeView_EndUpdate($hTV)
    _GUICtrlTreeView_Expand($hTV, $ID_Table)

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

    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

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

    While 1
    Sleep(100)
    WEnd

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

    Func _end()
    Exit
    EndFunc

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

    Func _GetExpanded()
    Local $sExpanded = 'Ausgeklappt: '
    For $i = 0 To UBound($aID_Sub) -1
    If _GUICtrlTreeView_GetExpanded(GUICtrlGetHandle($hTV), $aID_Sub[$i]) Then _
    $sExpanded &= _GUICtrlTreeView_GetText(GUICtrlGetHandle($hTV), $aID_Sub[$i]) & ', '
    Next
    WinSetTitle($gui, '', StringTrimRight($sExpanded, 2))
    EndFunc

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
    $hWndTreeview = $hTV
    If Not IsHWnd($hTV) Then $hWndTreeview = GUICtrlGetHandle($hTV)

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

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeview
    Switch $iCode
    Case $TVN_ITEMEXPANDEDW
    _GetExpanded()
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]