Function Reference


_GUICtrlMenu_InsertMenuItem

Inserts a new menu item at the specified position

#include <GuiMenu.au3>
_GUICtrlMenu_InsertMenuItem ( $hMenu, $iIndex, $sText [, $iCmdID = 0 [, $hSubMenu = 0]] )

Parameters

$hMenu Handle of the menu
$iIndex 0-based position of the menu item before which to insert the new item
$sText Menu item text. If blank, a separator will be inserted.
$iCmdID [optional] Command ID to assign to the item
$hSubMenu [optional] Handle to the submenu associated with the menu item

Return Value

Success: True.
Failure: False.

Related

_GUICtrlMenu_AddMenuItem, _GUICtrlMenu_AppendMenu, _GUICtrlMenu_InsertMenuItemEx

See Also

Search InsertMenuItem in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>

Example()

Func Example()
        Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
        Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idExit, $e_idCut, $e_idCopy, $e_idPaste

        ; Create GUI
        $hGUI = GUICreate("Menu", 400, 300)

        ; Create File menu
        $hFile = _GUICtrlMenu_CreateMenu()
        _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $e_idNew)
        _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $e_idOpen)
        _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $e_idSave)
        _GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0)
        _GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $e_idExit)

        ; Create Edit menu
        $hEdit = _GUICtrlMenu_CreateMenu()
        _GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $e_idCut)
        _GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $e_idCopy)
        _GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $e_idPaste)

        ; Create Help menu
        $hHelp = _GUICtrlMenu_CreateMenu()

        ; Create Main menu
        $hMain = _GUICtrlMenu_CreateMenu()
        _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile)
        _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit)
        _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp)

        ; Set window menu
        _GUICtrlMenu_SetMenu($hGUI, $hMain)
        GUISetState(@SW_SHOW)

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example