CMFCPopupMenu 在 Win7 中保持在后台

发布于 2024-11-19 17:59:55 字数 975 浏览 2 评论 0原文

我正在尝试一些新的 MFC 功能,并且我想要与 Visual Studio 2010 的 Visual C++ 语言示例中的 TrayMenu 项目相同的功能,但在我的计算机中(不知道是否仅在我的计算机中我尝试找到在网上有同样的问题,但没有找到任何类似的报告!!!)菜单出现在新的win7的traynotifywwnd的背景中,我似乎无法让它正常工作:

代码很简单:

void CTrayMenuDlg::OnTrayContextMenu ()
{
      CPoint point;
      ::GetCursorPos (&point);

      CMenu menu;
      menu.LoadMenu (IDR_MENU1);

      CMFCPopupMenu::SetForceShadow (TRUE);

      HMENU hMenu = menu.GetSubMenu (0)->Detach ();
      CMFCPopupMenu* pMenu = theApp.GetContextMenuManager()->ShowPopupMenu(hMenu, point.x, point.y, this, TRUE);

      pMenu->SetForegroundWindow ();
 }

我认为SetForegroundWindow 是解决此问题的一些方法,但它不起作用,它仍然显示在窗口后面,当我们单击小箭头时,所有托盘图标都被隐藏和显示(请注意,如果图标显示在 ToolbarWindow32 -不隐藏 - 我们调用托盘上下文菜单,然后一切正常,只有当图标被隐藏并使用 ToolbarWindow32 中的小箭头显示并且显示带有隐藏图标的窗口时,才会出现此问题 - 该窗口是否保留在...前面我的上下文菜单...)

弹出窗口后面显示的上下文菜单

有人发现这个问题吗?这个问题有什么解决办法吗?

谢谢

I'm trying some of the new MFC functionality and i want the same thing that the TrayMenu project from Visual C++ Language Samples for Visual Studio 2010 does but in my machine (don't know if is only in my machine i try to find the same problem in the web but didn't find any similar report!!!) the menu appears in the background of the new win7 traynotifywwnd, and i can't seem to put it work right:

The code is simple:

void CTrayMenuDlg::OnTrayContextMenu ()
{
      CPoint point;
      ::GetCursorPos (&point);

      CMenu menu;
      menu.LoadMenu (IDR_MENU1);

      CMFCPopupMenu::SetForceShadow (TRUE);

      HMENU hMenu = menu.GetSubMenu (0)->Detach ();
      CMFCPopupMenu* pMenu = theApp.GetContextMenuManager()->ShowPopupMenu(hMenu, point.x, point.y, this, TRUE);

      pMenu->SetForegroundWindow ();
 }

I think that SetForegroundWindow is some how a fix for this problem, but it does not work, it stills show bewind the window where all the tray icon are hidden and displayed when we click in the little arrow (note that if the icon is displayed in the ToolbarWindow32 -not hidden - and we call the tray context menu then it all works fine, this problem only appear if the icon is hidden and is show using the little arrow in the ToolbarWindow32 and a window is displayed with the hidden icons - is this window that stays in front of my context menu...)

context menu shown behind popup window

Has anyone find this problem? and there is any solution for this problem?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筱武穆 2024-11-26 17:59:55

我对此不太确定,但您可以尝试添加:

    // Set window position to topmost window.
    pMenu->SetWindowPos(
                &CWnd::wndTopMost,
                0, 0, 0, 0,
                SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE ); 

而不是 pMenu->SetForegroundWindow ();

I am not sure about this one but you can try adding:

    // Set window position to topmost window.
    pMenu->SetWindowPos(
                &CWnd::wndTopMost,
                0, 0, 0, 0,
                SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE ); 

instead of pMenu->SetForegroundWindow ();

刘备忘录 2024-11-26 17:59:55

来自 MSDN

添加 ::SetWindowPos(pMenu->m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
pMenu->SetForegroundWindow();之前
CTrayMenuDlg::OnTrayContextMenu ()函数中。

对我来说这有效!

From MSDN:

Add ::SetWindowPos(pMenu->m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
before the pMenu->SetForegroundWindow ();
in CTrayMenuDlg::OnTrayContextMenu () function.

For me this worked!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文