#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global Enum $idOpen = 1000, $idSave, $idInfo, $idSub1, $idSub2
Global $GUI, $listview, $hMenu
_Main()
Func _Main()
; Create GUI
$GUI = GUICreate("Menu", 400, 300)
$listview = GUICtrlCreateListView("test1|test2|test3|test4", 5, 5, 390, 290)
GUICtrlCreateListViewItem("item1|item2|item3|item4", $listview)
GUICtrlCreateListViewItem("test1|test2|test3|test4", $listview)
; ----- Create subitem menu -----
$hSubItems1 = _GUICtrlMenu_CreateMenu()
_GUICtrlMenu_InsertMenuItem($hSubItems1, 0, "SubItem &1", $idSub1)
_GUICtrlMenu_InsertMenuItem($hSubItems1, 1, "SubItem &2", $idSub2)
; -------------------------------
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave)
_GUICtrlMenu_InsertMenuItem($hMenu, 2, "Info", $idInfo)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 4, "More", 0, $hSubItems1) ; <---- append subitems here
; Register message handlers
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState()
; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $iIDFrom, $iCode, $tNMHDR, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $listview
Switch $iCode
Case $NM_CLICK, $NM_RCLICK
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
If DllStructGetData($tInfo, "Item") > -1 Then
_GUICtrlMenu_TrackPopupMenu($hMenu, $GUI)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Switch $iwParam
Case $idOpen
_WinAPI_ShowMsg("Open")
Case $idSave
_WinAPI_ShowMsg("Save")
Case $idInfo
_WinAPI_ShowMsg("Info")
; ---- submeenus ----
Case $idSub1
_WinAPI_ShowMsg("submenu1")
Case $idSub2
_WinAPI_ShowMsg("submenu2")
EndSwitch
EndFunc ;==>WM_COMMAND