Displays a shortcut menu at the specified location
#include <GuiMenu.au3>
_GUICtrlMenu_TrackPopupMenu ( $hMenu, $hWnd [, $iX = -1 [, $iY = -1 [, $iAlignX = 1 [, $iAlignY = 1 [, $iNotify = 0 [, $iButtons = 0]]]]]] )
$hMenu | Handle to the shortcut menu to be displayed |
$hWnd | Handle to the window that owns the shortcut menu |
$iX | [optional] Specifies the horizontal location of the shortcut menu, in screen coordinates. If this is -1, the current mouse position is used. |
$iY | [optional] Specifies the vertical location of the shortcut menu, in screen coordinates. If this is -1, the current mouse position is used. |
$iAlignX | [optional] Specifies how to position the menu horizontally: 0 - Center the menu horizontally relative to $iX 1 - Position the menu so that its left side is aligned with $iX 2 - Position the menu so that its right side is aligned with $iX |
$iAlignY | [optional] Specifies how to position the menu vertically: 0 - Position the menu so that its bottom side is aligned with $iY 1 - Position the menu so that its top side is aligned with $iY 2 - Center the menu vertically relative to $iY |
$iNotify | [optional] Use to determine the selection withouta parent window: 1 - Do not send notification messages 2 - Return the menu item identifier of the user's selection |
$iButtons | [optional] Mouse button the shortcut menu tracks: 0 - The user can select items with only the left mouse button 1 - The user can select items with both left and right buttons |
Success: | If $iNotify is set to 2, the return value is the menu item identifier of the item that the user selected. If the user cancels the menu without making a selection or if an error occurs, then the return value is zero. If $iNotify is not set to 2, the return value is 1. |
Failure: | 0. |
Search TrackPopupMenu 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