To use a shortcut menu in an application, pass its handle to the TrackPopupMenuEx function. An application typically calls TrackPopupMenuEx in a window procedure in response to a user-generated message, such as WM_LBUTTONDOWN or WM_KEYDOWN.
In addition to the pop-up menu handle, TrackPopupMenuEx requires that you specify the handle of the owner window, the position of the shortcut menu (in screen coordinates), and the mouse button that the user can use to choose an item.
The older TrackPopupMenu function is still supported, but new applications should use the TrackPopupMenuEx function. The TrackPopupMenuEx function requires the same parameters as TrackPopupMenu, but also lets you specify a portion of the screen that the menu should not obscure. An application typically calls these functions in a window procedure when processing the WM_CONTEXTMENU message.
You can specify the position of a shortcut menu by providing x- and y-coordinates along with the TPM_CENTERALIGN, TPM_LEFTALIGN, or TPM_RIGHTALIGN flag. The flag specifies the position of the shortcut menu relative to the x- and y-coordinates.
You should permit the user to choose an item from a shortcut menu by using the same mouse button used to display the menu. To do this, specify either TPM_LEFTBUTTON or TPM_RIGHTBUTTON flag to indicate which mouse button the user can use to choose a menu item.