本帖最后由 cashiba 于 2018-8-28 14:19 编辑
原来如此,还以为函数用得不对。
今天第一次用_GUICtrlTreeView_Create函数,看例子后修改了一下(如下),试试获取当前点击的树项文本,结果总是不对。以为是树图的句柄和id的问题......
A大有空帮看看,问题出在哪里呢?
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Global $g_hTreeView
Example()
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 创建) TreeView", 400, 300)
$g_hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlTreeView_BeginUpdate($g_hTreeView)
For $x = 1 To Random(2, 10, 1)
$hItem = _GUICtrlTreeView_Add($g_hTreeView, 0, StringFormat("[%02d] 新主项", $x))
For $y = 1 To Random(2, 10, 1)
_GUICtrlTreeView_AddChild($g_hTreeView, $hItem, StringFormat("[%02d] 新子项", $y))
Next
Next
_GUICtrlTreeView_EndUpdate($g_hTreeView)
; 循环到用户退出.
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
Local $iItem = GUICtrlRead($hWndTreeview)
Local $sItem = _GUICtrlTreeView_GetText($hWndTreeview, GUICtrlGetHandle($iItem))
ConsoleWrite('1、$iItem=' & $iItem & ',$sItem=' & $sItem & @CRLF & @CRLF)
Case $TVN_SELCHANGEDW
Local $iItem = GUICtrlRead($hWndTreeview)
Local $sItem = _GUICtrlTreeView_GetText($hWndTreeview, GUICtrlGetHandle($iItem))
ConsoleWrite('2、$iItem=' & $iItem & ',$sItem=' & $sItem & @CRLF & @CRLF)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
|