tester4 Posted June 27, 2008 Share Posted June 27, 2008 Hi, I need to do a right cllick action and then select an optioj from right click context menu. I can use control click or mouse click func to for right click action but dont know how to slect an item from context menu. How do i refer to context menu. please help Link to comment Share on other sites More sharing options...
AustrianOak Posted June 27, 2008 Share Posted June 27, 2008 I'm sorry, but I'm a bit confused. Are you having trouble creating a context menu on right click or selecting an option from the context menu? Link to comment Share on other sites More sharing options...
tester4 Posted June 30, 2008 Author Share Posted June 30, 2008 I'm sorry, but I'm a bit confused.Are you having trouble creating a context menu on right click or selecting an option from the context menu?Hi, i have to select an option from context menu. Link to comment Share on other sites More sharing options...
Malkey Posted June 30, 2008 Share Posted June 30, 2008 (edited) Hi, I need to do a right cllick action and then select an optioj from right click context menu. I can use control click or mouse click func to for right click action but dont know how to slect an item from context menu. How do i refer to context menu. please helpThis example might help you along. Right mouse click on the AutoIt GUI. expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $bFlag = 1, $MenuItem1, $MenuItem2, $MenuItemExit, $bFlag = 1, $exit = 0 Local $hGui, $ContextMenu, $separator1, $msg $hGui = GUICreate("With Context Menu") $ContextMenu = GUICtrlCreateContextMenu() $MenuItem1 = GUICtrlCreateMenuItem("Menu Item1", $ContextMenu, 1) GUICtrlSetState($MenuItem1, $GUI_CHECKED) GUICtrlSetOnEvent($MenuItem1, "FuncMenuItem1") $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line $MenuItem2 = GUICtrlCreateMenuItem("Menu Item2", $ContextMenu) GUICtrlSetOnEvent($MenuItem2, "FuncMenuItem2") $separator1 = GUICtrlCreateMenuItem("", $ContextMenu) ; create a separator line $MenuItemExit = GUICtrlCreateMenuItem("Exit", $ContextMenu) GUICtrlSetOnEvent($MenuItemExit, "quitclk") GUISetState() While 1 If $exit = 1 Then Exit Sleep(20) WEnd Func FuncMenuItem1() If $bFlag = 1 Then GUICtrlSetState($MenuItem1, $GUI_UNCHECKED) $bFlag = 0 Else GUICtrlSetState($MenuItem1, $GUI_CHECKED) $bFlag = 1 EndIf Return EndFunc ;==>FuncMenuItem1 Func FuncMenuItem2() MsgBox(0, "", "Item 1 Selected") Return EndFunc ;==>FuncMenuItem2 ; Called from context menu Exit script. Func quitclk() $exit = 1 EndFunc ;==>quitclk Edit: Removed GUIGetMsg() function. In Opt("GUIOnEventMode", 1) mode GUIGetMsg() does not work. Edited June 30, 2008 by Malkey Link to comment Share on other sites More sharing options...
Malkey Posted June 30, 2008 Share Posted June 30, 2008 Edit: Removed GUIGetMsg() function. In Opt("GUIOnEventMode", 1) mode GUIGetMsg() does not work.I was playing around with the example in help file for GUICtrlCreateContextMenu ( ) for an OnEventMode disabled, Opt("GUIOnEventMode", 0), example that actually did something, be it just a message box. I came across yet another thing I did not know you could do with GUI controls. In this case a GuiCrtlButton. Normally, you left mouse button click on an AutoIt button to do its thing, or, hover to bring up a tooltip. What I discovered is, you can also right mouse button click on the same button which can bring up a context menu which you can again click on. Amazing, and tricky. You could put a menu for a four course meal on an Exit button. Here is the example of OnEventMode disabled with button. expandcollapse popup#include <GuiConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 0) Example1() ; **************** ; * context menu sample * ; ; Right click on gui to bring up context Menu. ; Right click on the "Exit" button to bring up a control specific context menu. ; Left click on the "Exit" button to exit. ; **************** Func Example1() Local $contextmenu, $button, $buttoncontext, $buttonitem, $msg Local $newsubmenu, $textitem, $fileitem, $saveitem, $infoitem GUICreate("My GUI Context Menu", 300, 200) $contextmenu = GUICtrlCreateContextMenu() $button = GUICtrlCreateButton("Exit", 100, 100, 70, 20) GUICtrlSetTip($button, "Right Click for Context Menu") $buttoncontext = GUICtrlCreateContextMenu($button) $buttonitem = GUICtrlCreateMenuItem("About button", $buttoncontext) $newsubmenu = GUICtrlCreateMenu("new", $contextmenu) $textitem = GUICtrlCreateMenuItem("text", $newsubmenu) $fileitem = GUICtrlCreateMenuItem("Open", $contextmenu) $saveitem = GUICtrlCreateMenuItem("Save", $contextmenu) GUICtrlCreateMenuItem("", $contextmenu) ; separator $infoitem = GUICtrlCreateMenuItem("Info", $contextmenu) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $button ExitLoop Case $buttonitem MsgBox(0, "", "About Exit button Pressed") Case $textitem MsgBox(0, "", "Text Item Pressed") Case $fileitem MsgBox(0, "", "Open Item Pressed") Case $saveitem MsgBox(0, "", "Save Item Pressed") Case $infoitem MsgBox(0, "", "Info Item Pressed") EndSwitch WEnd EndFunc ;==>Example1 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