legend Posted September 24, 2022 Posted September 24, 2022 expandcollapse popup#include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global Enum $idOpen = 1000, $idSave, $idInfo 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) $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $idOpen) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $idSave) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $idInfo) ; 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") EndSwitch EndFunc ;==>WM_COMMAND How can i make a submenu under one of the menu points when right clicking?
Gianni Posted September 24, 2022 Posted September 24, 2022 expandcollapse popup#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 Danyfirex 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
legend Posted September 25, 2022 Author Posted September 25, 2022 On 9/24/2022 at 8:25 PM, Gianni said: expandcollapse popup#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 Expand it's working great, how would I get the name of the selected item in the listview, when i right click, and selects one of the menus?
pixelsearch Posted September 25, 2022 Posted September 25, 2022 On 9/25/2022 at 6:57 AM, legend said: How would I get the name of the selected item in the listview... Expand You can get it directly during the WM_NOTIFY() function, by adding a line to the code : If DllStructGetData($tInfo, "Item") > -1 Then ConsoleWrite($tInfo.Item & " " & $tInfo.SubItem & " " & _ _GUICtrlListView_GetItemText($listview, $tInfo.Item, $tInfo.SubItem) & @crlf) _GUICtrlMenu_TrackPopupMenu($hMenu, $GUI) EndIf "I think you are searching a bug where there is no bug... don't listen to bad advice."
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now