回复 1# 破帽遮颜
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel, $compinfo
Local $togglebutton, $infobutton, $statebutton, $cancelbutton
Local $msg, $item, $hItem, $text
GUICreate("My GUI with treeview", 350, 215)
$treeview = GUICtrlCreateTreeView(6, 6, 200, 180, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
$compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
$useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
$resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
$otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)
GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold
GUIRegisterMsg($WM_NOTIFY, 'MY_WM')
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
EndSelect
WEnd
GUIDelete()
Func MY_WM($hWnd, $Msg, $wParam, $lParam)
Local $tNMHdr = DllStructCreate($tagNMHDR, $lParam), $tNM_TREEVIEW
Local $hWndFrom = DllStructGetData($tNMHdr, 'hWndFrom')
Local $iIDFrom = DllStructGetData($tNMHdr, 'IDFrom')
Local $iCode = DllStructGetData($tNMHdr, 'Code')
If $iIDFrom = $TreeView Then
Switch $iCode
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
If GUICtrlRead($TreeView) > 0 Then _
MsgBox(0, 0, 'ID: ' & GUICtrlRead($TreeView) & @CRLF & 'Text: ' & GUICtrlRead($TreeView, 1))
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_OnNotify
|