|
-
Aug 7th, 2001, 11:59 PM
#1
Thread Starter
Fanatic Member
FROM MSDN:
TrackPopupMenu
The TrackPopupMenu function displays a shortcut menu at the specified location and tracks the selection of items on the menu. The shortcut menu can appear anywhere on the screen.
To specify an area of the screen the menu should not overlap, use the TrackPopupMenuEx function.
BOOL TrackPopupMenu(
HMENU hMenu, // handle to shortcut menu
UINT uFlags, // options
int x, // horizontal position
int y, // vertical position
int nReserved, // reserved, must be zero
HWND hWnd, // handle to owner window
CONST RECT *prcRect // ignored
);
Parameters
hMenu
[in] Handle to the shortcut menu to be displayed. The handle can be obtained by calling CreatePopupMenu to create a new shortcut menu, or by calling GetSubMenu to retrieve a handle to a submenu associated with an existing menu item.
uFlags
[in] Use zero of more of these flags to specify function options.
Use one of the following flags to specify how the function positions the shortcut menu horizontally. Value Meaning
TPM_CENTERALIGN If this flag is set, the function centers the shortcut menu horizontally relative to the coordinate specified by the x parameter.
TPM_LEFTALIGN If this flag is set, the function positions the shortcut menu so that its left side is aligned with the coordinate specified by the x parameter.
TPM_RIGHTALIGN Positions the shortcut menu so that its right side is aligned with the coordinate specified by the x parameter.
Use one of the following flags to specify how the function positions the shortcut menu vertically. Value Meaning
TPM_BOTTOMALIGN If this flag is set, the function positions the shortcut menu so that its bottom side is aligned with the coordinate specified by the y parameter.
TPM_TOPALIGN If this flag is set, the function positions the shortcut menu so that its top side is aligned with the coordinate specified by the y parameter.
TPM_VCENTERALIGN If this flag is set, the function centers the shortcut menu vertically relative to the coordinate specified by the y parameter.
Use the following flags to determine the user selection without having to set up a parent window for the menu. Value Meaning
TPM_NONOTIFY If this flag is set, the function does not send notification messages when the user clicks on a menu item.
TPM_RETURNCMD If this flag is set, the function returns the menu item identifier of the user's selection in the return value.
Use one of the following flags to specify which mouse button the shortcut menu tracks. Value Meaning
TPM_LEFTBUTTON If this flag is set, the user can select menu items with only the left mouse button.
TPM_RIGHTBUTTON If this flag is set, the user can select menu items with both the left and right mouse buttons.
Windows 98/Me, Windows 2000 or later: Use any reasonable combination of the following flags to modify the animation of a menu. For example, by selecting a horizontal and a vertical flag you can achieve diagonal animation. Value Meaning
TPM_HORNEGANIMATION Animates the menu from right to left.
TPM_HORPOSANIMATION Animates the menu from left to right.
TPM_NOANIMATION Displays menu without animation.
TPM_VERNEGANIMATION Animates the menu from bottom to top.
TPM_VERPOSANIMATION Animates the menu from top to bottom.
For any animation to occur, the SystemParametersInfo function must set SPI_SETMENUANIMATION. Also, all the TPM_*ANIMATION flags, except TPM_NOANIMATION, are ignored if menu fade animation is on, See the SPI_GETMENUFADE flag in SystemParametersInfo.
Windows 98/Me, Windows 2000 or later: Use the TPM_RECURSE flag to display a menu when another menu is already displayed. This is intended to support context menus within a menu.
Whistler: To have text layout from right-to-left, use TPM_LAYOUTRTL. By default, the text layout is left-to-right.
x
[in] Specifies the horizontal location of the shortcut menu, in screen coordinates.
y
[in] Specifies the vertical location of the shortcut menu, in screen coordinates.
nReserved
Reserved; must be zero.
hWnd
[in] Handle to the window that owns the shortcut menu. This window receives all messages from the menu. The window does not receive a WM_COMMAND message from the menu until the function returns.
If you specify TPM_NONOTIFY in the uFlags parameter, the function does not send messages to the window identified by hWnd. However, you must still pass a window handle in hWnd. It can be any window handle from your application.
prcRect
Ignored.
Return Values
If you specify TPM_RETURNCMD in the uFlags parameter, the return value is the menu-item identifier of the item that the user selected. If the user cancels the menu without making a selection, or if an error occurs, then the return value is zero.
If you do not specify TPM_RETURNCMD in the uFlags parameter, the return value is nonzero if the function succeeds and zero if it fails. To get extended error information, call GetLastError.
Remarks
To display a context menu for a notification icon, the current window must be the foreground window before the application calls TrackPopupMenu or TrackPopupMenuEx. Otherwise, the menu will not disappear when the user clicks outside of the menu or the window that created the menu (if it is visible). However, when the current window is the foreground window, the second time this menu is displayed, it displays and then immediately disappears. To correct this, you must force a task switch to the application that called TrackPopupMenu at some time in the near future. This is done by posting a benign message to the window or thread, as shown in the following code sample:
SetForegroundWindow(hDlg);
// Display the menu
TrackPopupMenu( hSubMenu,
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
hDlg,
NULL);
PostMessage(hDlg, WM_NULL, 0, 0);
For an example, see Displaying a Shortcut Menu.
Requirements
Windows NT/2000 or later: Requires Windows NT 3.1 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
See Also
Menus Overview, Menu Functions, CreatePopupMenu, GetSubMenu, RECT, SystemParametersInfo, TrackPopupMenuEx, WM_COMMAND
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Aug 7th, 2001, 11:59 PM
#2
Thread Starter
Fanatic Member
you'll be interested in the
TPM_NOANIMATION
bit I think
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|