Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Enable menu implemented thu XDocHostUIHandler::ShowContextMenu


I have integrated a CHtmlView in my application and want to control the context menu.  I have implemented IDocHostUIHandler::ShowContextMenu in order to do this.  I can get the menu to show up on a right-click, but each item on the menu is disabled (grayed out).  The commands that I am adding to the context menu work from the main menu.  I have OnUpdate handlers enabling the commands in the view and in the main frame.  My question is how do I get the menu items enabled.  

Following is the code that I use to create the menu.

// ShowContextMenu
STDMETHODIMP TCOleControlSite::XDocHostUIHandler::ShowContextMenu(
  /* [in ] */     DWORD dwID,
  /* [in ] */     POINT __RPC_FAR *ppt,
  /* [in ] */     IUnknown __RPC_FAR *pcmdtReserved,
  /* [in ] */     IDispatch __RPC_FAR *pdispReserved)
{
  METHOD_PROLOGUE(TCOleControlSite, DocHostUIHandler)

  CMenu menu;
  CString strMenu;
  int pos;

  UINT flags = 0;
  flags |= MF_STRING;
  flags |= MF_ENABLED;
 
  menu.CreatePopupMenu();

  VERIFY(strMenu.LoadString(ID_FORWARD));
  pos=strMenu.Find("\n");
  strMenu = strMenu.Mid(pos+1);
  menu.AppendMenu(flags, ID_FORWARD, strMenu);

[SNIP] more items added [/SNIP]

  HWND hwnd = WindowFromPoint(*ppt);
  CWnd* pWnd = CWnd::FromHandle(hwnd);
   
  pWnd->SetForegroundWindow();
  VERIFY(menu.TrackPopupMenu(TPM_CENTERALIGN | TPM_RIGHTBUTTON,
                                  ppt->x, ppt->y, pWnd));
  pWnd->SetForegroundWindow();

  return S_OK;
}
0
kruiser
Asked:
kruiser
  • 2
1 Solution
 
ShaunWildeCommented:
0
 
kruiserAuthor Commented:

Not quite, but you got me on the right track.  The problem was the way that I was getting a CWnd was returning a temporary.  I assigned the menu to the main frame and everything works fine. Thanks for the help.
0
 
ShaunWildeCommented:
sorry it wasn't exact - glad to help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now