#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $hTreeView, $hContext1, $hContext2, $hItem1, $hItem2
Global Const $TVS_HASBUTTONS = 0x0001
Global Const $TVS_HASLINES = 0x0002
Global Const $TVS_LINESATROOT = 0x0004
Global Const $TVS_DISABLEDRAGDROP = 0x0010
Global Const $TVS_SHOWSELALWAYS = 0x0020
$hMainGUI = GUICreate("TreeView with Context Menus", 400, 300)
$hTreeView = GUICtrlCreateTreeView(10, 10, 380, 280, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
$htvRoot = GUICtrlCreateTreeViewItem("Root Node", $hTreeView)
$hItem1 = GUICtrlCreateTreeViewItem("Child Node 1", $htvRoot)
$hItem2 = GUICtrlCreateTreeViewItem("Child Node 2", $htvRoot)
; Create Context Menu 1 for Child Node 1
$hContext1 = GUICtrlCreateContextMenu($hItem1)
$hItem1Option1 = GUICtrlCreateMenuItem("Option 1 for Child Node 1", $hContext1)
$hItem1Option2 = GUICtrlCreateMenuItem("Option 2 for Child Node 1", $hContext1)
; Create Context Menu 2 for Child Node 2
$hContext2 = GUICtrlCreateContextMenu($hItem2)
$hItem2Option1 = GUICtrlCreateMenuItem("Option 1 for Child Node 2", $hContext2)
$hItem2Option2 = GUICtrlCreateMenuItem("Option 2 for Child Node 2", $hContext2)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $hItem1Option1
MsgBox(0, "Child Node 1 Option 1", "Option 1 for Child Node 1")
Case $hItem1Option2
MsgBox(0, "Child Node 1 Option 2", "Option 2 for Child Node 1")
Case $hItem2Option1
MsgBox(0, "Child Node 2 Option 1", "Option 1 for Child Node 2")
Case $hItem2Option2
MsgBox(0, "Child Node 2 Option 2", "Option 2 for Child Node 2")
EndSwitch
WEnd
GUIDelete($hMainGUI)
|