Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //in my case, the menu is a popup from a tree control created with:
- CMenu menu;
- menu.CreatePopupMenu();
- //add stuff to the menu...
- pTreeCtrl->SetMenu(&menu);
- m_hMenu = menu.GetSafeHmenu();
- CPoint pt;
- GetCursorPos(&pt);
- menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, _pTreeCtrl);
- menu.Detach();
- m_hMenu = NULL;
- CRect rc;
- GetMenuItemRect(pTreeCtrl->GetSafeHwnd(), m_hMenu, targetMenuItemIndex, &rc);
- if(FALSE == rc.IsRectEmpty())
- {
- CPoint target = rc.CenterPoint();
- //this closes the menu
- ::PostMessage(pTreeCtrl->GetSafeHwnd(), WM_CANCELMODE, 0, 0);
- DestroyMenu(m_hMenu);
- m_hMenu = NULL;
- //now simulate the menu click
- ::PostMessage(pTreeCtrl->GetSafeHwnd(), WM_COMMAND, targetMenuItemID, 0);
- }
Add Comment
Please, Sign In to add comment