TrackPopupMenu

  BOOL TrackPopupMenu(hmenu, fuFlags, x, y, nReserved, hwnd, lprc)    
  HMENU hmenu; /* handle of pop-up menu */
  UINT fuFlags; /* screen-position and mouse-button flags */
  int x; /* horizontal screen position */
  int y; /* vertical screen position */
  int nReserved; /* reserved */
  HWND hwnd; /* handle of owner window */
  CONST RECT *lprc; /* address of structure with rectangle */

The TrackPopupMenu function displays the given floating pop-up menu at the specified location and tracks the selection of items on the pop-up menu. The floating pop-up menu can appear anywhere on the screen.

Parameters

hmenu

Identifies the pop-up menu to be displayed. An application obtains this handle by calling CreatePopupMenu to create a new pop-up menu or by calling GetSubMenu to retrieve the handle of a pop-up menu associated with an existing menu item.

fuFlags

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

Value Meaning

TPM_CENTERALIGN  
  Centers the pop-up menu horizontally relative to the coordinate specified by the x parameter.
TPM_LEFTALIGN  
  Positions the pop-up menu so that its left side is aligned with the coordinate specified by the x parameter.
TPM_RIGHTALIGN  
  Positions the pop-up menu so that its right side is aligned with the coordinate specified by the x parameter.

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

Value Meaning

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 fuFlags parameter, the pop-up 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.

nReserved

Reserved; must be zero.

hwnd

Identifies the window that owns the pop-up menu. This window receives all messages from the menu. The window will not receive a WM_COMMAND message from the menu until the TrackPopupMenu function returns.

lprc

Points to a RECT structure that contains the screen coordinates of a rectangle in 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. The RECT structure has the following form:

typedef struct tagRECT { /* rc */

LONG left;

LONG top;

LONG right;

LONG bottom;

} RECT;

Return Value

The return value is TRUE if the function is successful or FALSE if an error occurs. To obtain extended error information, use the GetLastError function.

See Also

CreatePopupMenu, GetSubMenu