水木子 发表于 2010-2-12 23:03 http://www.autoitx.com/images/common/back.gif#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>
#include <GUIListBox.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, $List1
_Main()
Func _Main()
Global $hItem, $hImage, $iImage, $hTreeView,$nMsg,$dll
Global $GUI, $hItem,$Child0,$Child1,$Child2,$Child3,$Child4,$Child5,$Child6,$Child7,$hItem0,$hItem1
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$GUI = GUICreate("(UDF Created) TreeView Create", 400, 540)
$hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
$List1 = GUICtrlCreateList("", 2, 277, 394, 268)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlTreeView_BeginUpdate($hTreeView)
$hItem0 = _GUICtrlTreeView_Add($hTreeView, 0, "soft1", 1, 1)
$Child0=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",0), 1, 1)
$Child1=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",1), 1, 1)
$Child2=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",2), 1, 1)
$Child3=_GUICtrlTreeView_AddChild($hTreeView,$hItem0,StringFormat("%02d : Random string",3), 1, 1)
$hItem1 = _GUICtrlTreeView_Add($hTreeView, 0, "soft2", 1, 1)
$Child4=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",4), 1, 1)
$Child5=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",5), 1, 1)
$Child6=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",6), 1, 1)
$Child7=_GUICtrlTreeView_AddChild($hTreeView,$hItem1,StringFormat("%02d : Random string",7), 1, 1)
_GUICtrlTreeView_EndUpdate($hTreeView)
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
$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 $NM_CLICK
For $i = 0 To 7
If _GUICtrlTreeView_GetChecked($hTreeView,Eval("Child"&$i)) Then
_GUICtrlListBox_InsertString($List1,'准备安装:'&StringFormat("%02d : Random string",$i),$i)
Else
_GUICtrlListBox_DeleteString($List1, $i)
EndIf
Next
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY你给我的例子我只能改成这样了,如何让已加到GUICtrlCreateList的数据不再重复添加,和判断没有选择时在GUICtrlCreateList删除相应项? 本帖最后由 水木子 于 2010-2-20 13:59 编辑
TreeView To List 有点乱,将就着看吧!#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Global $sa, $txit
$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$hGUI = GUICreate("_GUICtrlTreeView To _GUICtrlListBox", 500, 300)
$TreeView1 = GUICtrlCreateTreeView(2, 2, 200, 282, $iStyle, $WS_EX_CLIENTEDGE)
$hListBox1 = GUICtrlCreateList("", 208, 2, 290, 288)
GUISetState(@SW_SHOW)
$Item1 = GUICtrlCreateTreeViewItem('软件分类1', $TreeView1)
$Item2 = GUICtrlCreateTreeViewItem('软件分类2', $TreeView1)
For $Item = 1 To 5
GUICtrlCreateTreeViewItem('软件1-' & $Item, $Item1)
GUICtrlCreateTreeViewItem('软件2-' & $Item, $Item2)
Next
While 1
$all = _GUICtrlTreeView_GetCount($TreeView1)
For $i = 1 To $all + 5
$Check = _GUICtrlTreeView_GetChecked($TreeView1, $i)
If $Check = True Then
$txit &= _GUICtrlTreeView_GetText($TreeView1, $i) & '|'
EndIf
Next
If $txit <> $sa Then
$z = 1
GUICtrlSetData($hListBox1, '')
$che = StringSplit($txit, '|')
For $x = 2 To $che
GUICtrlSetData($hListBox1, StringFormat("[%02d]", $z) & ' 准备安装 ' & $che[$x - 1])
$z += 1
Next
$sa = $txit
EndIf
$txit = ''
$nMsg = GUIGetMsg()
Switch $nMsg
Case - 3
Exit
EndSwitch
WEnd 回复 17# 水木子 # $all = _GUICtrlTreeView_GetCount($TreeView1)
# For $i = 1 To $all + 5
# $Check = _GUICtrlTreeView_GetChecked($TreeView1, $i)
# If $Check = True Then
# $txit &= _GUICtrlTreeView_GetText($TreeView1, $i) & '|'
# EndIf
# Next为什么要$all+5呢?
另外$i是项目句柄吗? 学习了,标记后用。 代码很好,收下了 会报错哟,, 回复 17# 水木子
收下了,多谢啦!
页:
1
[2]