Search the Community
Showing results for tags 'wm_contextmenu'.
-
I have several context menus that's been built using _GUICtrlMenu_CreatePopup() and _GUICtrlMenu_AddMenuItem(). When using _GUICtrlMenu_CreatePopup() it returns the identifier of the clicked item, sure. But it blocks the main loop while the menu is open. When using _GUICtrlMenu_CreatePopup($MNS_MODELESS) it returns immediately (of course), but I cannot figure out how/where to read the item that was clicked. Is there a Windows Message (WM) somewhere that is triggered? I've spend an entire day trying to figure out how to do this, but I'm not getting anywhere. My google fu is depleted (I must have tried like hundreds of script variations today), I'm about to smash my keyboard and just go to bed, and abandon the entire endeavor of making pretty menus and go back to using Koda and forget about using menu icons, colors, etc. Anyone wanna help me out with how to read the clicked item? Before I smash my keyboard, please... Example script here: #include <GuiMenu.au3> #include <WinAPIError.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> GUIRegisterMsg($WM_CONTEXTMENU, "_WM_CONTEXTMENU") Global $idMenuItem = 10000, $counter = 0 Global $hGUI = GUICreate("Menu test", 400, 300) Global $hListview = GUICtrlCreateListView("", 2, 2, 396, 200) GUISetState(@SW_SHOW) ;~ Global $hMenuContext = _GUICtrlMenu_CreatePopup() Global $hMenuContext = _GUICtrlMenu_CreatePopup($MNS_MODELESS) _GUICtrlMenu_AddMenuItem($hMenuContext, "Menu item", $idMenuItem) Global $hTimer = TimerInit() Do If TimerDiff($hTimer)>200 Then $counter += 1 ConsoleWrite($counter & " " ) $hTimer = TimerInit() EndIf Until GUIGetMsg() = $GUI_EVENT_CLOSE Exit Func _WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch $wParam Case GUICtrlGetHandle($hListview) ConsoleWrite( @CRLF & "_GUICtrlMenu_TrackPopupMenu = " & _GUICtrlMenu_TrackPopupMenu($hMenuContext, $wParam, -1, -1, 1, 1, 2) & @CRLF) EndSwitch EndFunc
- 1 reply
-
- mns_modeless
- context
-
(and 3 more)
Tagged with:
-
Greetings forum, Hi develop this script, to use context menu with listview. It's work fine, run and click with left or right mouse button, you see on Console the id from item. If you click none, the id is -1, like this: $NM_RCLICK[-1] $NM_RCLICK[-1] $NM_RCLICK[2] $NM_RCLICK[1] $NM_RCLICK[0] $NM_RCLICK[1] That is correct. But if you uncoment the line: GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") You have to click with left button (over item or none) and after click with right button. LeftButton is to update $HOSTS_INDEX. RightButton is to open ContextMenu. Exist another way to update $HOSTS_INDEX? Example: Call WM_NOTIFY every time WM_CONTEXTMENU is called? I ask this, becouse i cant understanding why $HOSTS_INDEX is not updated when WM_CONTEXTMENU is uncomented. Someone can explain or help me? Best regards. ;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #Tidy_Parameters=/sf #include-once #include-once #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiMenu.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <SendMessage.au3> #include <Timers.au3> #include <AutoItConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <FontConstants.au3> #include <GuiComboBoxEx.au3> #include <GuiImageList.au3> #include <GuiTreeView.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <String.au3> OnAutoItExitRegister("OnExit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global Enum $eCREATE = 1000, $eUPDATE, $eDELETE, $eICON_TABLE, $eDEFAULT, $eEXPORT_HTML Global Const $EMPTY = -1 Global $HOSTS_INDEX = -1 Global $HOST_Host Global $aGuiSize[2] = [800, 600] Global $sGuiTitle = "GuiTitle" Global $hGui Global $iList, $hList $hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1]) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $iList = GUICtrlCreateListView("nome", 20, 50, 240, 490) $hList = GUICtrlGetHandle($iList) _GUICtrlListView_SetColumnWidth($hList, 0, 236) Populate() GUISetState(@SW_SHOW, $hGui) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") While Sleep(25) WEnd Func OnExit() GUISetState($hGui, @SW_HIDE) GUIDelete($hGui) EndFunc ;==>OnExit Func Quit() Exit EndFunc ;==>Quit Func Populate() Local $arr[4] = [3, "nome 1", "nome 2", "nome 3"] _GUICtrlListView_BeginUpdate($hList) _GUICtrlListView_DeleteAllItems($hList) For $ii = 1 To $arr[0] _GUICtrlListView_AddItem($hList, $arr[$ii]) Next _GUICtrlListView_SetItemSelected($hList, 0, True, True) _GUICtrlListView_EndUpdate($hList) EndFunc ;==>Populate Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_CONTEXTMENU..( $hWnd=" & $hWnd & ", $iMsg=" & $iMsg & ", $wParam=" & $wParam & ", $lParam=" & $lParam & " )" & @LF) Local $exec = 0 Local $hMenu Switch $wParam Case $hList Local $TRY_ID = _GUICtrlListView_GetHotItem($hList) If Not ($TRY_ID = $HOSTS_INDEX) Then $HOSTS_INDEX = $TRY_ID Local $aOrigin = _GUICtrlListView_GetOrigin($hList) ConsoleWrite("WM_CONTEXTMENU $HOSTS_INDEX[" & $HOSTS_INDEX & "] $aOrigin[" & _GUICtrlListView_GetOriginX($iList) & "]" & @LF) $hMenu = _GUICtrlMenu_CreatePopup() If $HOSTS_INDEX = $EMPTY Then _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Add", $eCREATE) Else _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Rename", $eUPDATE) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Del", $eDELETE) EndIf _GUICtrlMenu_SetMenu($hGui, $hMenu) $exec = _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam, -1, -1, 1, 1, 2, 1) _GUICtrlMenu_DestroyMenu($hMenu) EndSwitch Return True EndFunc ;==>WM_CONTEXTMENU Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Local $TRY_ID Switch $hWndFrom Case $hList $TRY_ID = _GUICtrlListView_GetHotItem($hList) If Not ($TRY_ID = $HOSTS_INDEX) Then $HOSTS_INDEX = $TRY_ID Switch $iCode Case $NM_CLICK ConsoleWrite("$NM_CLICK[" & $TRY_ID & "]" & @LF) If $HOSTS_INDEX = $EMPTY Or $HOST_Host Then ;~ HOSTS_Clear() ;~ HOSTS_ListView_ItemCancel() ;~ GUICtrlSetState($HOSTS_ITEM_DEL, $GUI_DISABLE) ;~ GUICtrlSetState($HOSTS_ITEM_UPD, $GUI_DISABLE) Else Local $name = _GUICtrlListView_GetItemText($hList, $HOSTS_INDEX) ;~ HOSTS_FieldLoad($name) ;~ GUICtrlSetState($HOSTS_ITEM_DEL, $GUI_ENABLE) ;~ GUICtrlSetState($HOSTS_ITEM_UPD, $GUI_ENABLE) EndIf Return 0 ; allow the default processing Case $NM_RCLICK ConsoleWrite("$NM_RCLICK[" & $TRY_ID & "]" & @LF) Return 0 ; allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
- 11 replies
-
- wm_contextmenu
- context menu
-
(and 1 more)
Tagged with:
-
Greetings, I try work with WM_CONTEXT, I take from help's example, and modify to generate a custom context menu to each control (ListView, TreeView or another control). If you leave with default/generic it work. If you custom for a specific control, does not work, what is my erro? When I say work, I want call the Switch...Case from WM_COMMAND. This is the code: #include <GUIConstantsEx.au3> #include <GuiMenu.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> OnAutoItExitRegister("OnExit") Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) Opt("MustDeclareVars", 1) Global Enum $eOPEN = 1000, $eSAVE, $eINFO Global $hGui = GUICreate("Menu", 400, 300) ConsoleWrite("$hGui........[" & $hGui & "]" & @LF) Global $iListView1 = GUICtrlCreateListView("", 10, 10, 80, 120) Global $hListView1 = GUICtrlGetHandle($iListView1) ConsoleWrite("$iTreeView1..[" & $iListView1 & "] $hListView1..[" & $hListView1 & "]" & @LF) Global $iListView2 = GUICtrlCreateListView("", 100, 10, 80, 120) Global $hListView2 = GUICtrlGetHandle($iListView2) ConsoleWrite("$iTreeView1..[" & $iListView2 & "] $hListView2..[" & $hListView2 & "]" & @LF) Global $iTreeView1 = GUICtrlCreateTreeView(190, 10, 80, 120) Global $hTreeView1 = GUICtrlGetHandle($iTreeView1) ConsoleWrite("$iTreeView1..[" & $iTreeView1 & "] $hTreeView1..[" & $hTreeView1 & "]" & @LF) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit", $hGui) GUISetState(@SW_SHOW, $hGui) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While Sleep(25) WEnd Func Quit() Exit EndFunc ;==>Quit Func OnExit() GUIDelete($hGui) EndFunc ;==>OnExit ; Handle WM_COMMAND messages Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_CONTEXTMENU( $hWnd=" & $hWnd & ", $iMsg=" & $iMsg & ", $wParam=" & $wParam & ", $lParam=" & $lParam & " )" & @LF) Switch $wParam Case $eOPEN ConsoleWrite("Open" & @LF) Case $eSAVE ConsoleWrite("Save" & @LF) Case $eINFO ConsoleWrite("Info" & @LF) EndSwitch EndFunc ;==>WM_COMMAND ; Handle WM_CONTEXTMENU messages Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_CONTEXTMENU( $hWnd=" & $hWnd & ", $iMsg=" & $iMsg & ", $wParam=" & $wParam & ", $lParam=" & $lParam & " )" & @LF) Local $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Generic Open", $eOPEN) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Generic Save", $eSAVE) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "Generic Info", $eINFO) _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam) _GUICtrlMenu_DestroyMenu($hMenu) Return True ; does not work #cs #forceref $hWnd, $iMsg, $wParam, $lParam ConsoleWrite("WM_CONTEXTMENU( $hWnd=" & $hWnd & ", $iMsg=" & $iMsg & ", $wParam=" & $wParam & ", $lParam=" & $lParam & " )" & @LF) Local $hMenu = _GUICtrlMenu_CreatePopup() Switch $wParam Case $hListView1 _GUICtrlMenu_InsertMenuItem($hMenu, 0, "$hListView1 Open", $eOPEN) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "$hListView1 Save", $eSAVE) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "$hListView1 Info", $eINFO) Case $hListView2 _GUICtrlMenu_InsertMenuItem($hMenu, 0, "$hListView2 Open", $eOPEN) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "$hListView2 Save", $eSAVE) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "$hListView2 Info", $eINFO) Case $hTreeView1 _GUICtrlMenu_InsertMenuItem($hMenu, 0, "$hTreeView1 Open", $eOPEN) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "$hTreeView1 Save", $eSAVE) _GUICtrlMenu_InsertMenuItem($hMenu, 2, "$hTreeView1 Info", $eINFO) EndSwitch _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam) _GUICtrlMenu_DestroyMenu($hMenu) Return True #ce EndFunc ;==>WM_CONTEXTMENU Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") EndFunc ;==>WM_NOTIFY
-
#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <GuiMenu.au3> Global $g_hTreeView Global Enum $e_idOpen = 1000, $e_idSave, $e_idInfo Example() Func Example() Local $hGUI, $hItem Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) $hGUI = GUICreate("(UDF Created) TreeView Create", 400, 300) $g_hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") _GUICtrlTreeView_BeginUpdate($g_hTreeView) For $x = 1 To Random(2, 10, 1) $hItem = _GUICtrlTreeView_Add($g_hTreeView, 0, StringFormat("[%02d] New Item", $x)) For $y = 1 To Random(2, 10, 1) _GUICtrlTreeView_AddChild($g_hTreeView, $hItem, StringFormat("[%02d] New Child", $y)) Next Next _GUICtrlTreeView_EndUpdate($g_hTreeView) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam ;ConsoleWrite($GUI_RUNDEFMSG & @CRLF) ;Switch $wParam ; Case $hTreeView Local $hMenu $hMenu = _GUICtrlMenu_CreatePopup() _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $e_idOpen) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $e_idSave) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0) _GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $e_idInfo) _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam) _GUICtrlMenu_DestroyMenu($hMenu) Return True ;EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_CONTEXTMENU Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch $wParam Case $e_idOpen _DebugPrint("WM_COMMAND " & $wParam & " Open") Case $e_idSave _DebugPrint("WM_COMMAND " & $wParam & " Save") Case $e_idInfo _DebugPrint("WM_COMMAND " & $wParam & " Info") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $g_hTreeView If Not IsHWnd($g_hTreeView) Then $hWndTreeview = GUICtrlGetHandle($g_hTreeView) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control _DebugPrint("$NM_DBLCLK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ "-->Code:" & @TAB & $iCode) ; Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint In the example code I have a treeview and a context/popup menu, I can't use a conventional context menu because I need to use the treeview UDF functions. The WM_COMMAND never fires from the context/popup menu selection while there is a treeview using _GuiCtrlTreeview_Create If you comment out _GuiCtrlTreeview_Create line you will then see the right click selection works as expected and the debug is written to the console on selection. Autoit Ver 3.3.14.2 Any ideas why this combination won't work together? Thanks
- 2 replies
-
- wm_contextmenu
- _guictrltreeview_create
- (and 3 more)
-
Here's the code I have, pulled from the examples and a couple things added. I've been trying to implement something like this in one of my scripts with no luck. So I went to the basics and decided to just get this part working. #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global Enum $idOpen = 1000, $idSave, $idInfo _Main() Func _Main() ; Create GUI GUICreate("Menu", 400, 300) GUISetState() ; Register message handlers GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") Global $listview = GUICtrlCreateListView( "test1|test2|test3|test4", 5, 5, 390, 290 ) Global $row1 = GUICtrlCreateListViewItem( "item1|item2|item3|item4", $listview ) Global $row2 = GUICtrlCreateListViewItem( "test1|test2|test3|test4", $listview ) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Handle WM_COMMAND messages Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Switch $iwParam Case $idOpen _WinAPI_ShowMsg("Open") Case $idSave _WinAPI_ShowMsg("Save") Case $idInfo _WinAPI_ShowMsg("Info") EndSwitch EndFunc ;==>WM_COMMAND ; Handle WM_CONTEXTMENU messages Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Local $hMenu Local $selected = GUICtrlRead( GUICtrlRead( $listview ) ) If $selected = 0 Then Return 1 $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) _GUICtrlMenu_TrackPopupMenu($hMenu, $iwParam) _GUICtrlMenu_DestroyMenu($hMenu) Return True EndFunc ;==>WM_CONTEXTMENU I added this to the main function: Global $listview = GUICtrlCreateListView( "test1|test2|test3|test4", 5, 5, 390, 290 ) Global $row1 = GUICtrlCreateListViewItem( "item1|item2|item3|item4", $listview ) Global $row2 = GUICtrlCreateListViewItem( "test1|test2|test3|test4", $listview ) and added this to wm_contextmenu: Local $selected = GUICtrlRead( GUICtrlRead( $listview ) ) If $selected = 0 Then Return 1 The rest is pulled straight from the example script for "_GUICtrlMenu_CreatePopup()" Basically I only want the menu to show up if something is selected inside the listview. The problem is that it won't show up at all when I have the coded added to WM_CONTEXTMENU. I checked $selected with a traytip and it shows the info correctly.. and if nothing is selected it always displays 0. I'm not sure how to do this.