MacScript Posted August 20, 2014 Share Posted August 20, 2014 I have a context menu that I am using in an autoit gui. The application loop is based on GUIGetMsg(). So the loop of course watches for Left mouse clicks on the Context menu options. I was wondering if there was a way to provide an Alternative action on the context menu option. My idea was to see if there was a way to catch Right clicks on the context menu options. If you get right click do X versus doing Y with left click. Here is just a basic piece of GUI code that has a context menu in it. Thanks in advance for all help that is provided expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI Context Menu", 300, 200) Local $idContextmenu = GUICtrlCreateContextMenu() Global $CtxMenuTrans = GUICtrlCreateMenu("Read Only", $idContextmenu) ;-45a- Global $CtxMenuNo = GUICtrlCreateMenuItem("No", $CtxMenuTrans, -1, 1) ;-49b- Global $CtxMenuYes = GUICtrlCreateMenuItem("Yes", $CtxMenuTrans, -1, 1) ;-49b- GUICtrlSetState($CtxMenuNo, $GUI_CHECKED) ;-49b- Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu) Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu) Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20) Local $idButtoncontext = GUICtrlCreateContextMenu($idButton) Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext) Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu) Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu) GUICtrlCreateMenuItem("", $idContextmenu) ; separator Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu) GUISetState(@SW_SHOW) ; Loop until the user exits. GUICtrlSetState($idNewsubmenuText, 32) While 1 Switch GUIGetMsg() Case $CtxMenuNo ;----> Show the Control $idNewsubmenu <---- Case $CtxMenuyes ;----> HIDE the Control $idNewsubmenu <---- Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK') Case $idMenuAbout MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About') Case $idMenuOpen MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open') Case $idMenuSave MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save') Case $idMenuInfo MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info') Case $idNewsubmenuText MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text') EndSwitch WEnd GUIDelete() EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Exit Posted August 20, 2014 Share Posted August 20, 2014 (edited) Here is just a basic piece of GUI code that has a context menu in it. I would like if all users would submit such a well prepared basic piece of code. I don't know, how to handle right click, but here an alternative with Right+Left click. But I think it is easier to add an additional item for that purpose. Single clicking is easier than click two buttons. But this code works for both. R+L click on info is the same as Lclick on info2 expandcollapse popup#include <Misc.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI Context Menu", 300, 200) Local $idContextmenu = GUICtrlCreateContextMenu() Global $CtxMenuTrans = GUICtrlCreateMenu("Read Only", $idContextmenu) ;-45a- Global $CtxMenuNo = GUICtrlCreateMenuItem("No", $CtxMenuTrans, -1, 1) ;-49b- Global $CtxMenuYes = GUICtrlCreateMenuItem("Yes", $CtxMenuTrans, -1, 1) ;-49b- GUICtrlSetState($CtxMenuNo, $GUI_CHECKED) ;-49b- Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu) Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu) Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20) Local $idButtoncontext = GUICtrlCreateContextMenu($idButton) Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext) Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu) Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu) GUICtrlCreateMenuItem("", $idContextmenu) ; separator Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu) Local $idMenuInfo2 = GUICtrlCreateMenuItem("Info2", $idContextmenu) GUISetState(@SW_SHOW) ; Loop until the user exits. GUICtrlSetState($idNewsubmenuText, 32) While 1 Switch GUIGetMsg() Case $CtxMenuNo ;----> Show the Control $idNewsubmenu <---- Case $CtxMenuYes ;----> HIDE the Control $idNewsubmenu <---- Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK') Case $idMenuAbout MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About') Case $idMenuOpen MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open') Case $idMenuSave MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save') Case $idMenuInfo If _IsPressed("02") Then ContinueCase MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info') Case $idMenuInfo2 MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info 2') Case $idNewsubmenuText MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text') EndSwitch WEnd GUIDelete() EndFunc ;==>Example Edited August 20, 2014 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
MikahS Posted August 25, 2014 Share Posted August 25, 2014 (edited) _IsPressed("02") ; this will handle the right click You'll need to get the selected text with the right click once it has been pressed, if nothing is selected then you'll need to return as it will have nothing in the selected indices Edited August 25, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
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