Must AutoIt
Сообщения: 3054
Благодарности: 1009
|
Профиль
|
Сайт
|
Отправить PM
| Цитировать
Код: 
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
;
$hGUI = GUICreate("My GUI with TreeView", 350, 215)
$TreeView = GUICtrlCreateTreeView(6, 6, 110, 150, -1, $WS_EX_STATICEDGE+$WS_EX_CLIENTEDGE)
#Region General TVItem
$General_TVItem = GUICtrlCreateTreeViewItem("General", $TreeView)
GUICtrlSetColor(-1, 0x0000C0)
$TVDemo_Label = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
$iGeneral_Last_Item = GUICtrlCreateDummy()
#EndRegion General TVItem
;
#Region About TVItem
$About_TVItem = GUICtrlCreateTreeViewItem("About", $General_TVItem)
$About_Label = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "aboutlabel"-text during initialization
$Some_Button = GUICtrlCreateButton("My Button", 190, 135, 70, 20)
GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "My Button"-button during initialization
$iAbout_Last_Item = GUICtrlCreateDummy()
#EndRegion About TVItem
;
#Region Computer TVItem
$Computer_TVItem = GUICtrlCreateTreeViewItem("Computer", $General_TVItem)
$ComputerInfo_Label = GUICtrlCreateLabel( _
StringFormat("Name:\t%sOS:\n\t%s\nSP:\t%s", @ComputerName, @OSVersion, @OSServicePack), 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "compinfo"-text during initialization
$iComputer_Last_Item = GUICtrlCreateDummy()
#EndRegion Computer TVItem
;
#Region User TVItem
$User_TVItem = GUICtrlCreateTreeViewItem("User", $General_TVItem)
$UserInfo_Label = GUICtrlCreateLabel("User Name: " & @CRLF & @TAB & @TAB & @UserName, 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "UserInfo"-text during initialization
$iUser_Last_Item = GUICtrlCreateDummy()
#EndRegion User TVItem
;
#Region Display TVItem
$Display_TVItem = GUICtrlCreateTreeViewItem("Display", $TreeView)
GUICtrlSetColor(-1, 0x0000C0)
$iDisplay_Last_Item = GUICtrlCreateDummy()
#EndRegion Display TVItem
;
#Region Resolution TVItem
$Resolution_TVItem = GUICtrlCreateTreeViewItem("Resolution", $Display_TVItem)
$iResolution_Last_Item = GUICtrlCreateDummy()
#EndRegion Resolution TVItem
;
#Region Other TVItem
$Other_TVItem = GUICtrlCreateTreeViewItem("Other", $Display_TVItem)
$iOther_Last_Item = GUICtrlCreateDummy()
#EndRegion Other TVItem
;
;Last ItemID - to hide all controls when showing other (current)
$iLast_TVItemsID = GUICtrlCreateDummy()
GUICtrlCreateLabel("", 0, 180, 350, 2, $SS_SUNKEN)
$Toggle_Button = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
$Info_Button = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
$ColExp_Button = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
$Cancel_Button = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)
GUICtrlSetState($General_TVItem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($Display_TVItem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Cancel_Button, $GUI_EVENT_CLOSE
Exit
Case $Toggle_Button ; Toggle the bold painting
If BitAND(GUICtrlRead($General_TVItem), $GUI_DEFBUTTON) Then
GUICtrlSetState($General_TVItem, 0)
GUICtrlSetState($Display_TVItem, 0)
Else
GUICtrlSetState($General_TVItem, $GUI_DEFBUTTON)
GUICtrlSetState($Display_TVItem, $GUI_DEFBUTTON)
EndIf
Case $Info_Button
$iItem_CtrlID = GUICtrlRead($TreeView) ; Get the controlID of the current selected treeview item
If $iItem_CtrlID = 0 Then
MsgBox(64, "TreeView Demo", "No item currently selected.", 0, $hGUI)
Else
$sItem_Msg = GUICtrlRead($iItem_CtrlID, 1) ; Get advanced infos about the treeview item
If $sItem_Msg == "" Then
MsgBox(16, "Error", "Error while retrieving infos about item.", 0, $hGUI)
Else
MsgBox(64, "TreeView Demo", "Current item selected is: " & $sItem_Msg, 0, $hGUI)
EndIf
EndIf
Case $ColExp_Button
$iItem_CtrlID = GUICtrlRead($TreeView)
If $iItem_CtrlID > 0 Then
$hItem = GUICtrlGetHandle($iItem_CtrlID)
GUICtrlSendMsg($TreeView, $TVM_EXPAND, $TVE_TOGGLE, $hItem)
EndIf
;The following items will hide the other labels (1st and 2nd parameter),
;and then show the 'own' labels (3rd and 4th parameter)
Case $General_TVItem, $About_TVItem, $Computer_TVItem, $User_TVItem, $Display_TVItem, $Resolution_TVItem, $Other_TVItem
$iEnd_ItemID = 0
Switch $nMsg
Case $General_TVItem
$iEnd_ItemID = $iGeneral_Last_Item
Case $About_TVItem
$iEnd_ItemID = $iAbout_Last_Item
Case $Computer_TVItem
$iEnd_ItemID = $iComputer_Last_Item
Case $User_TVItem
$iEnd_ItemID = $iUser_Last_Item
Case $Display_TVItem
$iEnd_ItemID = $iDisplay_Last_Item
Case $Resolution_TVItem
$iEnd_ItemID = $iResolution_Last_Item
Case $Other_TVItem
$iEnd_ItemID = $iOther_Last_Item
EndSwitch
;This list is the control IDs that should be ignored when we set items state
$sExclude_IDs = $General_TVItem & "|" & $Display_TVItem
_GUICtrlTreeView_ToggleItemsState($General_TVItem, $iLast_TVItemsID, $nMsg+1, $iEnd_ItemID, $sExclude_IDs)
EndSwitch
WEnd
Func _GUICtrlTreeView_ToggleItemsState($iHideStartID, $iHideEndID, $iShowStartID, $iShowEndID, $sExclude_IDs="")
If $sExclude_IDs <> "" Then $sExclude_IDs = "|" & $sExclude_IDs & "|"
For $i = $iHideStartID To $iHideEndID
If $sExclude_IDs = "" Or Not StringInStr($sExclude_IDs, "|" & $i & "|") Then GUICtrlSetState($i, $GUI_HIDE)
Next
For $i = $iShowStartID To $iShowEndID
If $sExclude_IDs = "" Or Not StringInStr($sExclude_IDs, "|" & $i & "|") Then GUICtrlSetState($i, $GUI_SHOW)
Next
EndFunc
Хотя этот пример немного сложны для понимания и для использования, нужно придумать более лояльный метод...
Переделал полностью пример, теперь должно быть яснее - Для каждого TreeViewItem'а выделен блок (через #Region), в границах этого блока, !!!до « $i*_Last_Item = GUICtrlCreateDummy()», можно помещать новые элементы, они будут попадать под процесс отображения/скрытия элементов.
|