是这样子吗?
#include <TreeViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiTreeView.au3>
#Region
$Form1 = GUICreate("Form1", 600, 400, -1, -1)
$TreeView = GUICtrlCreateTreeView(6, 6, 150, 386, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, 0x8000)) ;去掉横向滑块
$TreeViewItem1 = GUICtrlCreateTreeViewItem("项目1", $TreeView)
$TreeViewItem2 = GUICtrlCreateTreeViewItem("项目2", $TreeView)
$TreeViewItem3 = GUICtrlCreateTreeViewItem("项目3", $TreeView)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;捕捉窗口控件交互时事件
#EndRegion
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ;捕捉窗口控件交互时事件
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
Local $hWndTreeView = $TreeView
If Not IsHWnd($TreeView) Then $hWndTreeView = GUICtrlGetHandle($TreeView)
$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 ; 鼠标左键单击
Local $mPos = _WinAPI_GetMousePos(True, $hWndTreeView)
Local $mText = _GUICtrlTreeView_HitTestItem($hWndTreeView, DllStructGetData($mPos, "X"), DllStructGetData($mPos, "Y"))
Local $iPos = _GUICtrlTreeView_HitTest($hWndTreeView, DllStructGetData($mPos, "X"), DllStructGetData($mPos, "Y"))
Local $cText = _GUICtrlTreeView_GetText($hWndTreeView, $mText) ;获得当前坐标项目文本
MsgBox(0, 0, "单击了" & $cText)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
|