Код:
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#Include <GuiTreeView.au3>
$hForm = GUICreate("TreeView Example", 630, 830, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetBkColor(0xECE9D8)
$Dummy=GUICtrlCreateDummy()
$hTV = _GUICtrlTreeView_Create($hForm,10, 10, 610, 790, BitOR _
($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_SHOWSELALWAYS, $TVS_DISABLEDRAGDROP))
_GUICtrlTreeView_SetBkColor($hTV,0xCECECE)
PathTree($hTV, @ScriptDir)
$But=GUICtrlCreateButton ( "Test", 580, 810, 40, 20)
GUIRegisterMsg($WM_NOTIFY, 'WM__NOTIFY')
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $But
Case $Dummy
$Read=GUICtrlRead($Dummy)
ConsoleWrite ("$Read= " & $Read & @LF)
$aParam=StringSplit($Read, ",")
$hTV=$aParam[1]
$hItem=$aParam[2]
ConsoleWrite ("$hTV = " &$hTV& @LF)
ConsoleWrite ("$hItem = " & $hItem & @LF)
$sItemText=_GUICtrlTreeView_GetText($hTV, $hItem)
ConsoleWrite ("$sItemText = " &$sItemText& @LF)
EndSwitch
WEnd
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
$h_NM_ClickedItemTV=_TV_GetItemHandle($hWndFrom)
ConsoleWrite ("$hWndFrom= " & $hWndFrom & @LF)
ConsoleWrite ("$h_NM_ClickedItemTV= " & $h_NM_ClickedItemTV & @LF)
GUICtrlSendToDummy($Dummy, $hWndFrom & "," & $h_NM_ClickedItemTV)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _TV_GetItemHandle($hTV)
$tPoint = _WinAPI_GetMousePos(1, $hTV)
$tTVHTI = _GUICtrlTreeView_HitTestEx($hTV, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2))
$hItem = DllStructGetData($tTVHTI, 'Item')
Return $hItem
EndFunc
Func PathTree($hTV, $sPath)
$aTree=StringSplit ( $sPath, "\" )
If @error Then Return 0
$hItemTV=''
For $i=1 To UBound($aTree)-1
$hItemTV=_GUICtrlTreeView_AddChild($hTV, $hItemTV, $aTree[$i])
Next
_GUICtrlTreeView_Expand($hTV)
EndFunc
Попытка с использованием ф-ии StringSplit
находит элементы вроде правильно,
но не позволяет использовать найденный дескриптор $hTV
$sItemText=_GUICtrlTreeView_GetText($hTV, $hItem); $sItemText="" ???????