Partager via


CMenu::TrackPopupMenu

Displays a floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu.

BOOL TrackPopupMenu( 
   UINT nFlags, 
   int x, 
   int y, 
   CWnd* pWnd, 
   LPCRECT lpRect = 0 
);

Parameters

  • nFlags
    Specifies screen-position and mouse-position flags. See TrackPopupMenu for a list of available flags.

  • x
    Specifies the horizontal position in screen coordinates of the pop-up menu. Depending on the value of the nFlags parameter, the menu can be left-aligned, right-aligned, or centered relative to this position.

  • y
    Specifies the vertical position in screen coordinates of the top of the menu on the screen.

  • pWnd
    Identifies the window that owns the pop-up menu. This parameter cannot be NULL, even if the TPM_NONOTIFY flag is specified. This window receives all WM_COMMAND messages from the menu. In Windows versions 3.1 and later, the window does not receive WM_COMMAND messages until TrackPopupMenu returns. In Windows 3.0, the window receives WM_COMMAND messages before TrackPopupMenu returns.

  • lpRect
    Ignored.

Return Value

This method returns the result of calling TrackPopupMenu in the Windows SDK.

Remarks

A floating pop-up menu can appear anywhere on the screen.

Example

// The code fragment shows how to get the File menu from the 
// application window and displays it as a floating popup menu 
// when the right mouse button is clicked in view. 
// CMdiView is a CView-derived class. 
void CMdiView::OnRButtonDown(UINT nFlags, CPoint point)
{
   CView::OnRButtonDown(nFlags, point);

   CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
   CMenu* file_menu = menu_bar->GetSubMenu(0);    
   ASSERT(file_menu);

   ClientToScreen(&point);
   file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
      point.y, this);
}

Requirements

Header: afxwin.h

See Also

Reference

CMenu Class

Hierarchy Chart

CMenu::CreatePopupMenu

CMenu::GetSubMenu

TrackPopupMenu