设置项目的状态
#include <GuiTreeView.au3>
_GUICtrlTreeView_SetState($hWnd, $hItem [, $iState = 0 [, $iSetState = 0]])
$hWnd | 控件ID/句柄 |
$hItem | 项目句柄 |
$iState | [可选参数] 项目的状态,可以是一或多个下列值: $TVIS_SELECTED - 项目选中 $TVIS_CUT - 作为剪切和粘贴操作的一部分 $TVIS_DROPHILITED - 项目作为拖放目标 $TVIS_BOLD - 项目文本粗体 $TVIS_EXPANDED - 项目展开 $TVIS_EXPANDEDONCE - 项目的子项列表已展开至少一次 $TVIS_EXPANDPARTIAL - 项目为展开部分 |
$iSetState | [可选参数] 如为 True,项目设置状态, 如为 False,删除项目的状态 |
成功: | 返回 True |
失败: | 返回 False |
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
$Debug_TV = False ; 检查传递给函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作
_Main()
Func _Main()
Local $hItem[10], $hImage, $iImage, $iRand, $hTreeView
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
GUICreate("TreeView Set State", 400, 300)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, "shell32.dll", 110)
_GUIImageList_AddIcon($hImage, "shell32.dll", 131)
_GUIImageList_AddIcon($hImage, "shell32.dll", 165)
_GUIImageList_AddIcon($hImage, "shell32.dll", 168)
_GUIImageList_AddIcon($hImage, "shell32.dll", 137)
_GUIImageList_AddIcon($hImage, "shell32.dll", 146)
_GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 0 To 9
$iImage = Random(0, 5, 1)
$hItem[$x] = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x), $iImage, $iImage)
For $y = 1 To Random(2, 10, 1)
$iImage = Random(0, 5, 1)
_GUICtrlTreeView_AddChild($hTreeView, $hItem[$x], StringFormat("[%02d] New Child", $y), $iImage, $iImage)
Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
$iRand = Random(0, 9, 1)
_GUICtrlTreeView_SetState($hTreeView, $hItem[$iRand], $TVIS_CUT)
MsgBox(4160, "信息", StringFormat("State for Index %d? %s", $iRand, _GUICtrlTreeView_GetState($hTreeView, $hItem[$iRand])))
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main