Creates a drop down menu, submenu, or shortcut menu
#include <GuiMenu.au3>
_GUICtrlMenu_CreatePopup ( [$iStyle = $MNS_CHECKORBMP] )
$iStyle | [optional] Style of the menu. It can be one or more of the following values: $MNS_AUTODISMISS - Menu automatically ends when mouse is outside the menu for 10 seconds $MNS_CHECKORBMP - The same space is reserved for the check mark and the bitmap (default) $MNS_DRAGDROP - Menu items are OLE drop targets or drag sources $MNS_MODELESS - Menu is modeless $MNS_NOCHECK - No space is reserved to the left of an item for a check mark $MNS_NOTIFYBYPOS - Menu owner receives a WM_MENUCOMMAND message instead of a WM_COMMAND message for selections |
Success: | The handle to the newly created menu. |
Failure: | 0. |
Menu resources that are assigned to a window are freed automatically. If the menu is not assigned to a window, an application must free system resources associated with the menu before closing.
An application frees menu resources by calling the _GUICtrlMenu_DestroyMenu() function.
$MNS_NOTIFYBYPOS is a menu header style and has no effect when applied to individual sub menus
_GUICtrlMenu_CreateMenu, _GUICtrlMenu_DestroyMenu
Search CreatePopupMenu in MSDN Library.
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <WinAPIError.au3>
#include <WindowsConstants.au3>
Global Enum $e_idOpen = 1000, $e_idSave, $e_idInfo
Example()
Func Example()
; Create GUI
GUICreate("Menu", 400, 300)
GUISetState(@SW_SHOW)
; Register message handlers
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>Example
; Handle WM_COMMAND messages
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $lParam
Switch $wParam
Case $e_idOpen
_WinAPI_ShowMsg("Open")
Case $e_idSave
_WinAPI_ShowMsg("Save")
Case $e_idInfo
_WinAPI_ShowMsg("Info")
EndSwitch
EndFunc ;==>WM_COMMAND
; Handle WM_CONTEXTMENU messages
Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $lParam
Local $hMenu
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Open", $e_idOpen)
_GUICtrlMenu_InsertMenuItem($hMenu, 1, "Save", $e_idSave)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "", 0)
_GUICtrlMenu_InsertMenuItem($hMenu, 3, "Info", $e_idInfo)
_GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
_GUICtrlMenu_DestroyMenu($hMenu)
Return True
EndFunc ;==>WM_CONTEXTMENU