PRB: Menus for Notification Icons Do Not Work Correctly ID: Q135788 -------------------------------------------------------------------------------- The information in this article applies to:Microsoft Win32 Software Development Kit (SDK)-------------------------------------------------------------------------------- SYMPTOMS When you display a context menu for a notification icon (see Shell_NotifyIcon), clicking anywhere besides the menu or the window that created the menu (if it is visible) doesn't cause the menu to disappear. When this behavior is corrected, the second time this menu is displayed, it displays and then immediately disappears. RESOLUTION To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx. The second problem is caused by a problem with TrackPopupMenu. It is necessary to force a task switch to the application that called TrackPopupMenu at some time in the near future. This can be accomplished by posting a benign message to the window or thread. The following code will take care of all of this: SetForegroundWindow(hDlg); // Display the menu TrackPopupMenu( hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hDlg, NULL); PostMessage(hDlg, WM_NULL, 0, 0); STATUS This behavior is by design. Additional query words: Keywords : kbcode kbLib kbMenu kbNTOS400 kbWinOS95 kbWinOS98 kbshell Version : WINDOWS: Platform : WINDOWS Issue type : kbprb
ID: Q135788 --------------------------------------------------------------------------------
The information in this article applies to:Microsoft Win32 Software Development Kit (SDK)--------------------------------------------------------------------------------
SYMPTOMS
When you display a context menu for a notification icon (see Shell_NotifyIcon), clicking anywhere besides the menu or the window that created the menu (if it is visible) doesn't cause the menu to disappear. When this behavior is corrected, the second time this menu is displayed, it displays and then immediately disappears. RESOLUTION
To correct the first behavior, you need to make the current window the foreground window before calling TrackPopupMenu or TrackPopupMenuEx. The second problem is caused by a problem with TrackPopupMenu. It is necessary to force a task switch to the application that called TrackPopupMenu at some time in the near future. This can be accomplished by posting a benign message to the window or thread. The following code will take care of all of this:
SetForegroundWindow(hDlg); // Display the menu
TrackPopupMenu( hSubMenu,
TPM_RIGHTBUTTON,
pt.x,
pt.y,
0,
hDlg,
NULL); PostMessage(hDlg, WM_NULL, 0, 0); STATUS
This behavior is by design. Additional query words: Keywords : kbcode kbLib kbMenu kbNTOS400 kbWinOS95 kbWinOS98 kbshell
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: January 6, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect); point = rect.TopLeft();
point.Offset(5, 5);
} CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPUP_MENU));
menu.SetMenuItemBitmaps(ID_POP_CONNECT,MF_BYCOMMAND,&bitmapConnectServer,&bitmapConnectServer);
menu.SetMenuItemBitmaps(ID_POP_LOGIN,MF_BYCOMMAND,&bitmapLogin,&bitmapLogin);
menu.SetMenuItemBitmaps(ID_POP_LOGOUT,MF_BYCOMMAND,&bitmapLogout,&bitmapLogout);
menu.SetMenuItemBitmaps(ID_POP_RUN,MF_BYCOMMAND,&bitmapRun,&bitmapRun);
menu.SetMenuItemBitmaps(ID_POP_CLOSE,MF_BYCOMMAND,&bitmapExit,&bitmapExit);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
SetForegroundWindow();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
PostMessage(WM_NULL,0,0);
其中函数SetForegroundWindow()一定要加上。你没有加上这个函数,所以出现这个问题。我也碰到过,如果还有问题,来EMAIL:[email protected]