开发者

CMFCPopupMenu Stays In the Background in Win7

开发者 https://www.devze.com 2023-03-19 21:14 出处:网络
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

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 开发者_C百科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...)

CMFCPopupMenu Stays In the Background in Win7

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

Thanks


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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号