Function Reference

GUICtrlCreateContextMenu

Creates a context menu for a control or entire GUI window.

GUICtrlCreateContextMenu ( [controlID] )

 

Parameters

controlID [optional] Control identifier as returned by GUICtrlCreate...

 

Return Value

Success: Returns the identifier (controlID) of the new control.
Failure: Returns 0.

 

Remarks

After creating the context menu main control with this function, each menu item can be created by using GUICtrlCreateMenuItem.
Sub-menus can be created using GUICtrlCreateMenu.

If you use no parameters or -1 in this function then the context menu that is created is associated with the entire GUI window rather than an individual control.

Only one context menu per control is possible. If you wish to create a new context menu one you have to delete the existing menu first.

Note: You can't create context menus for controls that already have system context menus, i.e. edit or input controls.

 

Related

GUICtrlCreateMenuItem, GUICtrlCreateMenu, GUICtrlSetState, GUICtrlDelete

 

Example


#include <GUIConstants.au3>

GUICreate("My GUI Context Menu",300,200)

$contextmenu = GUICtrlCreateContextMenu ()

$button = GUICtrlCreateButton("OK",100,100,70,20)
$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()
   
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend