1

In a CMenu menu, WM_MENURBUTTONUP is only fired when the right mouse button is released while the mouse pointer is over a normal menu item (MF_STRING), but not if it's over a popup menu item (MF_POPUP). How can right-clicks on a popup menu item be detected? I'd like to implement a context menu for any menu item.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
stbi
  • 19
  • 2
  • Why would you need a right-click for a context menu item? What is your use case? – Andrew Truckle Jul 27 '23 at 07:31
  • Yes, what would be the difference to just using a sub menu? – thomiel Jul 27 '23 at 10:14
  • It's for a Startmenu replacement (or alternative) for Windows 11. I'd like to provide items like "Open" or "Properties" for each and every item (files and folders) of the main menu. – stbi Jul 28 '23 at 21:30
  • 1
    The 1st version of "TrayMenu" is now released - for now without context menus for the menu items: https://www.stefanbion.de/traymenu/ - If anyone has an idea or hint how to catch right-click on submenu items, I will add them. :-) – stbi Jul 31 '23 at 00:17

1 Answers1

0

I finally found a solution (or maybe a workaround) to detect and handle right-clicks on submenu items:

I defined message handlers for WM_MENUSELECT and WM_RBUTTONUP.

In OnMenuSelect() I store the Item Rect and the Item ID in two member variables of the dialog class:

CRect m_rcItemMenuSelect;
UINT m_uItemIDMenuSelect;

void CTrayMenuDlg::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
    if (nFlags & MF_POPUP)
    {
        MENUITEMINFO mii;
        mii.cbSize = sizeof(mii);
        mii.fMask = MIIM_ID;

        if (GetMenuItemInfo(hSysMenu, nItemID, TRUE, &mii))
        {
            GetMenuItemRect(m_hWnd, hSysMenu, nItemID, m_rcItemMenuSelect);
            m_uItemIDMenuSelect = mii.wID;
        }
    }
}

In OnRButtonUp() I test if the mouse pointer is inside the stored Item Rect. If yes, I use the stored Item ID to open the shell context menu for the folder.

void CTrayMenuDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
    if (m_rcItemMenuSelect.PtInRect(point))
    {
        // Item ID of right-clicked submenu item is in m_uItemIDMenuSelect
    }
}

Working code can be found at https://github.com/fraktalfan/TrayMenu.

stbi
  • 19
  • 2