- Offizieller Beitrag
Hi,
hier mal ein Problem von mir. Ich erstelle ein TreeView und füge Einträge mit den UDF-Funktionen _GUICtrlTreeView_Add() und _GUICtrlTreeView_AddChild() hinzu. Da ich Icons zuordne, muß ich zwingend auf die UDF zugreifen.
Ich arbeite im OnEventMode und möchte bei Klick auf ein Item den Text des Items ausgeben. Bei Verwendung von GUICtrlCreateTreeViewItem() funktioniert das tadellos. Aber mit den UDF wird nicht die ID sondern das Handle zurückgegeben. Vermutlich läßt sich deshalb keine Funktion zuweisen.
Mein zweiter Versuch dann mit WM_NOTIFY. Das funktioniert zwar - aber mit einem Versatz von einem Klick. D.h. das jetzt angeklickte Item wird erst beim Folgeklick ausgewertet.
Hier mal das Skript, vielleicht habt ihr ja eine zündende Idee.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GuiOnEventMode", 1)
Global $gui, $hImage, $hTV, $aID_Sub[5], $ID_Table
[/autoit] [autoit][/autoit] [autoit]$gui = GUICreate('Test TreeView')
GUISetOnEvent($GUI_EVENT_CLOSE, '_end')
$hTV = GUICtrlCreateTreeView(10,10,300,350,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
$TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$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)
_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)
GUICtrlSetOnEvent($aID_Sub[$i-1], 'click_TV') ; does'nt work (because have no ID and handle instead ?)
For $j = 1 To 3
_GUICtrlTreeView_AddChild($hTV, $aID_Sub[$i-1], 'Sub_Sub' & $j, 2, 2)
Next
Next
_GUICtrlTreeView_EndUpdate($hTV)
_GUICtrlTreeView_Expand($hTV, $ID_Table)
GUISetState()
;~ GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ; by using WM_NOTIFY are strange results, are reading with an offset of 1 click!
While 1
Sleep(100)
WEnd
Func _end()
Exit
EndFunc
Func click_TV()
ConsoleWrite(_GUICtrlTreeView_GetText($hTV, _GUICtrlTreeView_GetSelection($hTV)) & @CRLF)
EndFunc
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)
$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
click_TV()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Edit: Habs jetzt zusätzlich ins EN-Forum gestellt http://www.autoitscript.com/forum/index.php?showtopic=88587&view=findpost&p=636501