0

I'm having troubles showing my tray menu above the taskbar. It doesn't matter what I specify as y-position, it only gets against the taskbar at best. The tray menu is a resource.

This is the code I'm using for a rightclick on the systrayicon:

// The message loop
case WM_RBUTTONUP:
{
    CPoint point;
    ::GetCursorPos(&point);

    CMenu menu;
    menu.LoadMenu(IDR_MENU1);
    HMENU hMenu = menu.GetSubMenu(0)->Detach();

    CMFCPopupMenu* pMenu = theApp.GetContextMenuManager()->ShowPopupMenu(hMenu, point.x-5, point.y, this, TRUE);
    pMenu->SetForegroundWindow();
    break;
}
sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • Could you post a screenshot of what the problem looks like? I.e. how the menu looks like when it pops up, and what you expect it to look like? – sashoalm Jun 07 '13 at 08:55
  • Hi. Thank you for your response. Here you have an example: http://i.imgur.com/wYmM3yw.png - the red square is how it appears (against the taskbar), the blue is how I want it to appear. If I set y to less than point.y it moves away from the taskbar. But I can't get it to be placed over it. – Anton Lindgren Jun 07 '13 at 10:19
  • Try using CMenu instead of CMFCPopupMenu. With CMenu I have no problems with my software (although I didn't check with CMFCPopupMenu). – Jabberwocky Jun 07 '13 at 10:37
  • Feature, not a bug. The CMFCPopupMenu::RecalcLayout() method ensures the menu is displayed on the monitor's working area, thus guaranteeing it won't overlap any task bars. Good idea, don't fix it. – Hans Passant Jun 07 '13 at 11:34
  • Wow, I did not know that nor did I find anything about it when I researched the CMFCPopupMenu. Thank you, Hans Passant. And thank you sashoalm and Michael Walz. I'll most likely keep on using CMFCPopupMenu because it looks a little cleaner this way. But good to know that it's not a flaw in my code :) – Anton Lindgren Jun 07 '13 at 11:46

1 Answers1

0

Indeed RecalcLayout makes sure that a popup is displayed within monitor's working area (not obscuring taskbar. But there is nothing to prevent you to override this behavior. The difference between a Windows’ menu and CMFCPopupMenu is that the menu is a window that is created by the OS and CMFCPopupMenu is a frame window that mimics the behavior of the menu. You were almost there but you missed the fact that SetForegroundWindow does not move window, it merely changes Z-order. I personally do not see any advantage of doing it. However, as I say nothing is impossible to achieve. Do following if you really want to do it against advice:

    CMFCPopupMenu* pMFCMenu = pCntxtMgr->ShowPopupMenu(hMenu, ptClick.x, ptClick.y, AfxGetMainWnd());
    CRect rectMenu;
    pMFCMenu->GetWindowRect(rectMenu);

    pMFCMenu->SetWindowPos(&CWnd::wndTopMost, rectMenu.left, rectMenu.top + 25, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);

25 is just an arbitrary number I used for demo purpose. You will have to calculate it to prevent menu bottom appearing off the screen.

JohnCz
  • 1,613
  • 1
  • 9
  • 9