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 开发者_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...)
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 thepMenu->SetForegroundWindow ();
inCTrayMenuDlg::OnTrayContextMenu ()
function.
For me this worked!
精彩评论