基 礎(chǔ) 函 數(shù) 參 考
ControlTreeView
發(fā)送命令到 TreeView32 控件.
參 數(shù)
標(biāo)題 |
目標(biāo)窗口標(biāo)題. |
文本 |
目標(biāo)窗口文本. |
控件ID |
控件標(biāo)識(shí)符. 相關(guān)說明見 Controls. |
命令 |
發(fā)送到控件的命令 (見下文). |
選項(xiàng)1 |
[可選參數(shù)] 某些命令需要的附加參數(shù). |
選項(xiàng)2 |
[可選參數(shù)] 某些命令需要的附加參數(shù). |
返 回 值
返回結(jié)果取決于命令, 如下表所列. 若發(fā)生錯(cuò)誤(如命令或窗口/控件無效), 則 @error = 1.
命令, 選項(xiàng)1, 選項(xiàng)2
|
結(jié)果
|
"Check", "項(xiàng)目" |
選中項(xiàng)目 (如果項(xiàng)目支持選擇). |
"Collapse", "項(xiàng)目" |
折疊項(xiàng)目,使其隱藏子項(xiàng)目. |
"Exists", "項(xiàng)目" |
如果項(xiàng)目存在則返回 1, 否則返回 0. |
"Expand", "項(xiàng)目" |
展開項(xiàng)目, 使其顯示子項(xiàng)目. |
"GetItemCount", "項(xiàng)目" |
返回所選項(xiàng)目的子項(xiàng)目數(shù)量. |
"GetSelected" [, 索引] |
返回當(dāng)前所選項(xiàng)目的文本參考 (如果"索引"設(shè)置為 1, 將返回所選項(xiàng)目的索引參考). |
"GetText", "項(xiàng)目" |
返回項(xiàng)目文本. |
"IsChecked" |
返回項(xiàng)目狀態(tài). 1:選中, 0:未選中, -1:沒有復(fù)選框. |
"Select", "項(xiàng)目" |
選取項(xiàng)目. |
"Uncheck", "項(xiàng)目" |
項(xiàng)目非選中 (如果項(xiàng)目支持選擇). |
"項(xiàng)目" 參數(shù)是字符串型參數(shù), 對(duì)于特定的 TreeVie 項(xiàng)目, 使用文本和索引組合. 索引基于 0 開始計(jì)算. 如下例:
主項(xiàng)1
----> 主項(xiàng)1的子項(xiàng)1
----> 主項(xiàng)1的子項(xiàng)2
----> 主項(xiàng)1的子項(xiàng)3
----> ----> 主項(xiàng)1的子項(xiàng)1的子項(xiàng)1
主項(xiàng)2
主項(xiàng)3
每一 "層次" 之間使用" | "分隔. 索引前面則帶 # 符號(hào). 例如:
項(xiàng)目
|
項(xiàng)目引用參考
|
主項(xiàng)2 |
"主項(xiàng)2" 或 "#1" |
主項(xiàng)1的子項(xiàng)2 |
"主項(xiàng)1|主項(xiàng)1的子項(xiàng)2" 或 "#0|#1" |
主項(xiàng)1的子項(xiàng)1的子項(xiàng)1 |
"主項(xiàng)1|主項(xiàng)1的子項(xiàng)3|主項(xiàng)1的子項(xiàng)1的子項(xiàng)1" 或 "#0|#2|#0" |
引用參考可以是一個(gè)混合表達(dá)式,就像 "主項(xiàng)1|#1".
備 注
在 64 位 Windows 系統(tǒng)上運(yùn)行 32 位的 AutoIt 時(shí),部分命令可能無效, 此時(shí)請(qǐng)使用 64 位 AutoIt
版本.
相 關(guān) 函 數(shù)
ControlCommand
函 數(shù) 示 例
; 作者:
Zedna
#include <GUIConstantsEx.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
Local $gui
= GUICreate("發(fā)送命令到 Treeview 測(cè)試",
212, 212)
Local $treeview
= GUICtrlCreateTreeView(6,
6, 200, 160, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
Local $h_tree
= ControlGetHandle($gui, "", $treeview)
Local $root
= GUICtrlCreateTreeViewItem("根項(xiàng)目",
$treeview)
GUICtrlCreateTreeViewItem("項(xiàng)目 1", $root)
GUICtrlCreateTreeViewItem("項(xiàng)目 2", $root)
GUICtrlCreateTreeViewItem("項(xiàng)目 3", $root)
Local $item4
= GUICtrlCreateTreeViewItem("項(xiàng)目 4", $root)
GUICtrlCreateTreeViewItem("子項(xiàng) 41", $item4)
GUICtrlCreateTreeViewItem("子項(xiàng) 42", $item4)
GUICtrlCreateTreeViewItem("項(xiàng)目 5", $root)
GUISetState(@SW_SHOW)
; 發(fā)送命令的一些例子
ControlTreeView($gui,
"", $h_tree, "Expand", "根項(xiàng)目")
ControlTreeView($gui,
"", $h_tree, "Exists", "根項(xiàng)目|項(xiàng)目 4")
ControlTreeView($gui,
"", $h_tree, "Check", "根項(xiàng)目|項(xiàng)目 4")
ControlTreeView($gui,
"", $h_tree, "Select", "根項(xiàng)目|項(xiàng)目 4")
ControlTreeView($gui,
"", $h_tree, "Expand", "根項(xiàng)目|項(xiàng)目 4")
While 1
Local
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
EndSelect
WEnd