简体   繁体   中英

CMFCPopupMenu Stays In the Background in Win7

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...)

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

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

Thanks

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!

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 ();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM