創(chuàng)建樹視圖(TreeView)控件.
GUICtrlCreateTreeView ( 左距, 頂距 [, 寬度 [, 高度 [,
樣式 [, 擴展樣式]]]] )
左距 | 控件左側(cè)的位置. 若此值為 -1, 則根據(jù) GUICoordMode 的設(shè)置計算左側(cè)位置. |
頂距 | 控件上方的位置. 若此值為 -1, 則根據(jù) GUICoordMode 的設(shè)置計算頂部位置. |
寬度 | [可選參數(shù)] 控件的寬度(默認使用先前的寬度). |
高度 | [可選參數(shù)] 控件的高度(默認使用先前的高度). |
樣式 | [可選參數(shù)] 控件的樣式. 查看附錄 GUI 控件樣式表. 默認樣式 (-1) : $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS 強制樣式 : $WS_TABSTOP |
擴展樣式 | [可選參數(shù)] 控件的擴展樣式. 查看附錄 擴展樣式表. |
成功: | 返回控件標(biāo)識符(控件ID). |
失敗: | 返回 0. |
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
Example()
Func Example()
Local
$treeview,
$generalitem ,
$displayitem ,
$aboutitem ,
$compitem
Local
$startlabel,
$aboutlabel,
$compinfo
Local
$togglebutton,
$infobutton,
$statebutton,
$cancelbutton
Local
$msg, $item, $hItem , $text
GUICreate("我的樹視圖 GUI", 350, 215)
$treeview = GUICtrlCreateTreeView(6,
6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP,
$TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$generalitem = GUICtrlCreateTreeViewItem
("常規(guī)", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$displayitem = GUICtrlCreateTreeViewItem
("顯示器", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$aboutitem = GUICtrlCreateTreeViewItem
("關(guān)于...", $generalitem )
$compitem = GUICtrlCreateTreeViewItem
("計算機", $generalitem )
GUICtrlCreateTreeViewItem ("用戶",
$generalitem )
GUICtrlCreateTreeViewItem ("分辨率",
$displayitem )
GUICtrlCreateTreeViewItem ("其它",
$displayitem )
$startlabel = GUICtrlCreateLabel("樹視圖演示", 190, 90, 100, 20)
$aboutlabel = GUICtrlCreateLabel("這個小腳本演示如何使用 TreeView 控件.",
190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE) ;
初始化隱藏 "關(guān)于" 標(biāo)記的文本
$compinfo = GUICtrlCreateLabel("名稱:" & @TAB & @ComputerName &
@LF &
"系統(tǒng):" &
@TAB &
@OSVersion &
@LF &
"服務(wù)包:" &
@TAB &
@OSServicePack,
120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE) ;
初始化隱藏 "計算機" 信息標(biāo)記的文本
GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
$togglebutton = GUICtrlCreateButton("切換 &T", 35,
185, 70, 20)
$infobutton = GUICtrlCreateButton("信息 &I", 105,
185, 70, 20)
$statebutton = GUICtrlCreateButton("Col./Exp.", 175,
185, 70, 20)
$cancelbutton = GUICtrlCreateButton("取消 &C", 245,
185, 70, 20)
GUICtrlSetState($generalitem , BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; 展開 "常規(guī)" 項目并顯示為粗體文字
GUICtrlSetState($displayitem , BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; 展開 "顯示器" 項目并顯示為粗體文字
GUISetState()
While
1
$msg = GUIGetMsg()
Select
Case $msg
= $cancelbutton
Or $msg
= $GUI_EVENT_CLOSE
ExitLoop
Case $msg
= $togglebutton
; 切換粗體文字
If BitAND(GUICtrlRead($generalitem ), $GUI_DEFBUTTON) Then
GUICtrlSetState($generalitem , 0)
GUICtrlSetState($displayitem , 0)
Else
GUICtrlSetState($generalitem , $GUI_DEFBUTTON)
GUICtrlSetState($displayitem , $GUI_DEFBUTTON)
EndIf
Case $msg
= $infobutton
$item = GUICtrlRead($treeview) ; 獲取當(dāng)前選中 TreeView 項目的控件
ID
If $item = 0 Then
MsgBox(64, "樹視圖演示", "目前沒有選定任何項目")
Else
$text
= GUICtrlRead($item, 1) ; 獲取
TreeView 的項目文字
If $text == "" Then
MsgBox(16, "錯誤", "檢索項目相關(guān)信息時出錯 ")
Else
MsgBox(64, "樹視圖演示", "當(dāng)前選定項目: " & $text) ;
$advmsg[0] 包含項目文本, $advmsg[1] 包含項目狀態(tài)值
EndIf
EndIf
Case $msg
= $statebutton
$item = GUICtrlRead($treeview)
If $item > 0 Then
$hItem
=
GUICtrlGetHandle($item)
GUICtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem )
EndIf
; 下列項目會隱藏其它標(biāo)記文本(第1和第2個參數(shù)),
并顯示原有標(biāo)記文本(第三和第四個參數(shù))
Case $msg
= $generalitem
GUIChangeItemss($aboutlabel, $compinfo, $startlabel, $startlabel)
Case $msg
= $aboutitem
GUICtrlSetState($compinfo, $GUI_HIDE)
GUIChangeItemss($startlabel, $startlabel, $aboutlabel, $aboutlabel)
Case $msg
= $compitem
GUIChangeItemss($startlabel, $aboutlabel, $compinfo, $compinfo)
EndSelect
WEnd
GUIDelete()
EndFunc ;==>Example
Func GUIChangeItemss($hidestart, $hideend, $showstart, $showend)
Local
$idx
For
$idx = $hidestart To $hideend
GUICtrlSetState($idx, $GUI_HIDE)
Next
For
$idx = $showstart To $showend
GUICtrlSetState($idx, $GUI_SHOW)
Next
EndFunc ;==>GUIChangeItemss
provider with jb51.net (unicode) |