Share via


CMenu::TrackPopupMenu

BOOLTrackPopupMenu(UINTnFlags**,intx,inty,CWnd*pWnd,LPCRECTlpRect=NULL);**

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

nFlags

Specifies a screen-position flag and a mouse-button flag. The screen-position flag can be one of the following:

  • TPM_CENTERALIGN   Centers the pop-up menu horizontally relative to the coordinate specified by x.

  • TPM_LEFTALIGN   Positions the pop-up menu so that its left side is aligned with the coordinate specified by x.

  • TPM_RIGHTALIGN   Positions the pop-up menu so that its right side is aligned with the coordinate specified by x.

    The mouse-button flag can be either of the following:

  • TPM_LEFTBUTTON   Causes the pop-up menu to track the left mouse button.

  • TPM_RIGHTBUTTON   Causes the pop-up menu to track the right mouse button.

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 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

Points to a RECT structure or CRect object that contains the screen coordinates of a rectangle within which the user can click without dismissing the pop-up menu. If this parameter is NULL, the pop-up menu is dismissed if the user clicks outside the pop-up menu. This must be NULL for Windows 3.0.

For Windows 3.1 and later, you can use the following constants:

  • TPM_CENTERALIGN

  • TPM_LEFTALIGN

  • TPM_RIGHTALIGN

  • TPM_RIGHTBUTTON

Remarks

Displays a floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu. 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.
// CMyView is a CView-derived class.
void CMyView::OnRButtonDown(UINT nFlags, CPoint point)
{
   CView::OnRButtonDown(nFlags, point);

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

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

CMenu OverviewClass MembersHierarchy Chart

See Also   CMenu::CreatePopupMenu, CMenu::GetSubMenu,