共用方式為


CContextMenuManager::ShowPopupMenu

Displays the specified shortcut menu.

virtual BOOL ShowPopupMenu(
   UINT uiMenuResId,
   int x,
   int y,
   CWnd* pWndOwner,
   BOOL bOwnMessage = FALSE,
   BOOL bRightAlign = FALSE
);

virtual CMFCPopupMenu* ShowPopupMenu(
   HMENU hmenuPopup,
   int x,
   int y,
   CWnd* pWndOwner,
   BOOL bOwnMessage = FALSE,
   BOOL bAutoDestroy = TRUE,
   BOOL bRightAlign = FALSE
);

Parameters

  • [in] uiMenuResId
    The resource ID of the menu that this method will display.

  • [in] x
    The horizontal offset for the shortcut menu in client coordinates.

  • [in] y
    The vertical offset for the shortcut menu in client coordinates

  • [in] pWndOwner
    A pointer to the parent window of the shortcut menu.

  • [in] bOwnMessage
    A Boolean parameter that indicates how messages are routed. If bOwnMessage is FALSE, standard MFC routing is used. Otherwise, pWndOwner receives the messages.

  • [in] hmenuPopup
    The handle of the menu that this method will display.

  • [in] bAutoDestroy
    A Boolean parameter that indicates whether the menu will be automatically destroyed.

  • [in] bRightAlign
    A Boolean parameter that indicates how the menu items are aligned. If bRightAlign is TRUE, the menu is right-aligned for right-to-left reading order.

Return Value

The first method overload returns nonzero if the method shows the menu successfully; otherwise 0. The second method overload returns a pointer to CMFCPopupMenu if the shortcut menu displays correctly; otherwise NULL.

Remarks

This method resembles the method CContextMenuManager::TrackPopupMenu in that both methods display a shortcut menu. However, TrackPopupMenu returns the index of the selected menu command.

If the parameter bAutoDestroy is FALSE, you must manually call the inherited DestroyMenu method to release memory resources. The default implementation of ShowPopupMenu does not use the parameter bAutoDestroy. It is provided for future use or for custom classes derived from the CContextMenuManager Class.

Requirements

Header: afxcontextmenumanager.h

See Also

Reference

CContextMenuManager Class

Hierarchy Chart

CContextMenuManager::TrackPopupMenu