本帖最后由 kinghu318 于 2012-8-2 15:38 编辑 #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
;Opt('MustDeclareVars', 1)
$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work
Global $hTreeView, $hItem[11]
_Main()
Func _Main()
Local $GUI
Local $iStyle = BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES, $WS_HSCROLL, $TVS_NONEVENHEIGHT)
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 300)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 1 To Random(2, 10, 1)
$hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x))
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR, $hWndTreeview;, $iIDFrom
$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
; $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $TVN_SELCHANGEDW
;MsgBox(0, "", "jr")
For $x = 1 To 10
If _GUICtrlTreeView_GetSelected($hTreeView, $hItem[$x]) Then
If _GUICtrlTreeView_GetChecked($hTreeView, $hItem[$x]) Then
_GUICtrlTreeView_SetChecked($hTreeView, $hItem[$x], False)
Else
_GUICtrlTreeView_SetChecked($hTreeView, $hItem[$x])
EndIf
EndIf
Next
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
这是我在论坛找的,我也是想通过WM_NOTIFY这种方式进行treeview的操作,但是这个是判断_GUICtrlTreeView_GetSelected选中,发生改变的时候能进行正常选中和勾选复选框,但是点击同一个就无法进行修改,我想当点击文本或者复选框的时候进行修改,复选框进行改变,同时文本选中状态,请牛人帮忙修改修改,或者有什么好的方法,希望大家帮忙,非常感谢!!!!! |