Click to See Complete Forum and Search --> : Popup Menu does not work with OnUpdate...() methods
kug
April 11th, 1999, 12:07 PM
Hey Folks !
Whenever I use a Popup Menu, i.e. over a CTreeCtrl, the accompanied menuitems will not be updated by the OnUpdate...() methods. That means all items are allways active. I debuged that and realized that the OnUpdate...() methods are called when then a single item was selected by mouse or keyboard !
Does anybody know about this problem or has a solution ?
kug
Lynx
April 11th, 1999, 08:59 PM
I found the same problem before. I guess the best way to solve it is to disable/enable the popup menu items when you create the popup menu, not using OnUpdate.. function. For example, you want to disable "Save" menu item for pooup menu, use EnableMenuItem to disable it.
void CMyView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu menuText;
menuText.LoadMenu(IDR_POPUPMENU);
// remove the header of menu
CMenu* pMenuPopup = menuText.GetSubMenu(0);
menuText.RemoveMenu(0, MF_BYPOSITION);
// only enable necessary menu items to user
if(m_bNotSave == TRUE)
// don't need to enable "Save" menu item pMenuPopup->EnableMenuItem(ID_FILE_SAVE, MF_GRAYED|MF_BYCOMMAND);
pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, pWnd, NULL);
}
//..........................
Hope this will help. Good luck.
Lynx
Brain Studio
April 12th, 1999, 07:51 AM
I met the same questions too,I finally used removemenu function,more ID!some enabled,some grayed!but I thought it was not a good way.
sally
April 12th, 1999, 09:15 PM
I ran into the same problem, so I checked if the commands were applicable or not, and if they were, I enabled them, and if not I disabled them
Voila....
Sally
Sally
April 12th, 1999, 09:15 PM
I ran into the same problem, so I checked if the commands were applicable or not, and if they were, I enabled them, and if not I disabled them
Voila....
Sally
JohnCz
May 20th, 1999, 09:24 PM
I would like to explain it in more detail fashion but I do not have enough time.
Handling of popup menus in the view is different than regular menu. If you had checked message routing, the way OnUpdate… is dispatched, it is looking for an ACTIVE View. When application is idle, view may not be active, frame is. And to your surprise, main frame window is active. So when you invoke call to pop menu up, you are not getting OnUpdate…, and this is quite expected view behavior.
Try to this in your View class:
CMenu menuText;
CWnd* pActiveWnd = SetActiveWindow(); // <- this will set view active and show you window that was active. Set breakpoint here to see.
menuText.LoadMenu(IDR_POPUP_I);
CMenu* pMenuPopup = menuText.GetSubMenu(0);
pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this/*or pWnd from parameter list*/, NULL);
Another thing you can do is to handle popup menu in chold frame class. Child frame will receive notification, since framework dowz not look for a active frame. Remember, you can invoke it in the view, but show different window to process command messages by setting 4-th parameter in TrackPopupMenu call. For example this will invoke menu in the view, but all command messages including updates will be dispatched to Child Frame (assuming you have simple view-frame architecture):
pMenuPopup->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent(), NULL);
Please let me know if this resolved your problem.
Good luck.
John Cz
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.