- Offizieller Beitrag
Hi.
Ich will die Message $NM_CLICK und $NM_DBLCLK auswerten, habe dabei aber das Problem, das ich nicht weis, wie ich an das Item herankommen soll.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Global $g_hTreeView
[/autoit] [autoit][/autoit] [autoit]Example()
[/autoit] [autoit][/autoit] [autoit]Func Example()
Local $hGUI, $hItem
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$hGUI = GUICreate("(UDF Created) TreeView Create", 400, 300)
$g_hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
[/autoit] [autoit][/autoit] [autoit]_GUICtrlTreeView_BeginUpdate($g_hTreeView)
For $x = 1 To Random(2, 10, 1)
$hItem = _GUICtrlTreeView_Add($g_hTreeView, 0, StringFormat("[%02d] New Item", $x))
For $y = 1 To Random(2, 10, 1)
_GUICtrlTreeView_AddChild($g_hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
Next
Next
_GUICtrlTreeView_EndUpdate($g_hTreeView)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$hWndTreeview = $g_hTreeView
If Not IsHWnd($g_hTreeView) Then $hWndTreeview = GUICtrlGetHandle($g_hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
_DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
_DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode)
; Return 1 ; nonzero to not allow the default processing
Return 0 ; zero to allow the default processing
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
Eigentlich sollte in $tagNMHDR unter IDFrom die ITEMID stehen, aber es wird immer nur 10000 zurückgeliefert, egal welches Item man anklickt.
Hab jetzt versucht es mittels _GUICtrlTreeView_GetSelection hinzubekommen, funzt aber auch nicht, weil $NM_CLICK vor dem Wechsel des slektiertem Items abgefeuert wird.
Hat wer eine Idee?