#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiMenu.au3>
#include <GuiTreeView.au3>
$Form1 = GUICreate("Example", 460, 280)
$MenuBtn1 = GUICtrlCreateMenu("菜单01")
$MenuItem11 = GUICtrlCreateMenuItem("子菜单01", $MenuBtn1)
GUICtrlCreateMenuItem("", $MenuBtn1)
$MenuItem12 = GUICtrlCreateMenuItem("子菜单02", $MenuBtn1)
$MenuItem13 = GUICtrlCreateMenuItem("子菜单03", $MenuBtn1)
$MenuBtn2 = GUICtrlCreateMenu("菜单02")
$MenuItem21 = GUICtrlCreateMenuItem("子菜单01", $MenuBtn2)
$MenuItem22 = GUICtrlCreateMenuItem("子菜单02", $MenuBtn2)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 110)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 137)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 146)
$TreeView = GUICtrlCreateTreeView(5, 5, 160, 250, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
_GUICtrlTreeView_SetNormalImageList($TreeView, $hImage)
$Group = _GUICtrlTreeView_Add($TreeView, 0, "分组列表", 0, 0)
For $i = 1 To 8
_GUICtrlTreeView_AddChild($TreeView, $Group, StringFormat("测试分组[%02d]", $i), 1, 2) ;生成分组列表
Next
_GUICtrlTreeView_Expand($TreeView, $Group) ;展开列表
_GUICtrlTreeView_SelectItemByIndex($TreeView, $Group, 0) ;启动时默认选择第一个分组
$ListView = GUICtrlCreateListView("", 170, 5, 285, 250)
_GUICtrlListView_AddColumn($ListView, "1", 90) ;创建列
_GUICtrlListView_AddColumn($ListView, "2", 86) ;创建列
_GUICtrlListView_AddColumn($ListView, "3", 86) ;创建列
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES)) ;设置ListView样式
For $i = 1 To 5
_GUICtrlListView_AddItem($ListView, StringFormat("测试List[%02d]", $i))
_GUICtrlListView_AddSubItem($ListView, $i-1, "第2列-数据", 1)
_GUICtrlListView_AddSubItem($ListView, $i-1, "第3列-数据", 2)
Next
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
Local $hWndListView = $ListView,$hWndTreeView = $TreeView
If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
If Not IsHWnd($TreeView) Then $hWndTreeView = GUICtrlGetHandle($TreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeView
Switch $iCode
Case $NM_CLICK ;鼠标左键单击项目时由控件发送
Case $NM_DBLCLK ;鼠标左键双击项目时由控件发送
;~ MsgBox(0, "", "双击了<左键>")
Case $NM_RCLICK ;鼠标右键单击项目时由控件发送
Local Enum $TreeEdit = 1000, $TreeDelete
Local $TreeContext = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($TreeContext, 0, "快捷菜单按钮01", $TreeEdit)
_GUICtrlMenu_InsertMenuItem($TreeContext, 1, "")
_GUICtrlMenu_InsertMenuItem($TreeContext, 2, "快捷菜单按钮02", $TreeDelete)
Switch _GUICtrlMenu_TrackPopupMenu($TreeContext, $Form1, -1, -1, 1, 1, 2)
Case $TreeEdit
MsgBox(0, "", "点击了“快捷菜单按钮01”按钮")
Case $TreeDelete
MsgBox(0, "", "点击了“快捷菜单按钮02”按钮")
EndSwitch
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd