为什么Popup Menu不会消失?

leng 2000-08-06 02:47:00
我把对话框最小化成windows右下角的图标,当鼠标对准图标按下鼠标右键时,会弹出Popup

Menu,但我在window的桌面上按鼠标时,Popup Menu不会消失,Why?
请各位高手帮老弟一把,非常感谢!
...全文
209 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzh 2000-08-08
  • 打赏
  • 举报
回复
在OnContexMenu函数中,参考如下代码:
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:zzh1415@21cn.com
xubin_sh 2000-08-08
  • 打赏
  • 举报
回复
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



Last Reviewed: January 6, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
longx 2000-08-06
  • 打赏
  • 举报
回复
你需要在弹出菜单前将程序窗口设置成最前端窗口,用SetForegroundWindow()

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧