找回密码
 加入
搜索
查看: 2638|回复: 2

[GUI管理] [已解决]TreeViewItem如何才能点击文本就能改变checked状态?

[复制链接]
发表于 2011-5-1 13:52:04 | 显示全部楼层 |阅读模式
本帖最后由 nnlenx 于 2011-5-1 17:46 编辑

TreeViewItem如何才能点击文本就能改变checked状态?
就像点击Checkbox那样的效果。

搜索了半天,还是没有找到相关的资料。。。。。。
发表于 2011-5-1 17:31:21 | 显示全部楼层
本帖最后由 netegg 于 2011-5-1 17:41 编辑

回复 1# nnlenx
#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($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
        $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
                                        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

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
        ConsoleWrite( _
                        "!===========================================================" & @LF & _
                        "+======================================================" & @LF & _
                        "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
                        "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
 楼主| 发表于 2011-5-1 17:45:49 | 显示全部楼层
回复 2# netegg


谢谢给出的例子,效果不错。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-2 17:54 , Processed in 0.085739 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表