Function Reference

GUICtrlCreateMenuitem

Creates a MenuItem control for the GUI.

GUICtrlCreateMenuitem ( "text", menuID [, menuentry [, menuradioitem]] )

 

Parameters

text The text of the control.
menuID Allow to create a submenu in the refered menu. If equal -1 it refers to first level menu.
menuentry [optional] Allow to define the entry number to be created. The entries are numbered starting 0.
menuradionitem [optional] 0 (default) = create a normal menuitem, 1 = create a menuradioitem

 

Return Value

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

 

Remarks

To set or change information in the control see GUICtrlSet....

If the Text parameter is a "" then a separator line is created. GUICtrlSetState can be use as for other control. See example.

 

Related

GUICtrlSet..., GUIGetMsg

 

Example


#include <GUIConstants.au3>

GUICreate("My GUI menu",300,200)

Global $defaultstatus = "Ready"
Global $status

$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu ("?")
$saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
$recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2)    ; create a separator line

$viewmenu = GUICtrlCreateMenu("View",-1,1)  ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
$okbutton = GUICtrlCreateButton ("OK",50,130,70,20)
GUICtrlSetState(-1,$GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton ("Cancel",180,130,70,20)

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN))

GUISetState ()
While 1
    $msg = GUIGetMsg()
   
    If $msg = $fileitem Then
        $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
        If @error <> 1 Then GUICtrlCreateMenuitem ($file,$recentfilesmenu)
    EndIf
    If $msg = $viewstatusitem Then
        If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
            GUICtrlSetState($statuslabel,$GUI_HIDE)
        Else
            GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
            GUICtrlSetState($statuslabel,$GUI_SHOW)
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
    If $msg = $infoitem Then Msgbox(0,"Info","Only a test...")
WEnd
GUIDelete()

Exit