Enable menu implemented thu XDocHostUIHandler::ShowContextMenu

Posted on 2001-06-14
Last Modified: 2013-11-20

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;

  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);
                                  ppt->x, ppt->y, pWnd));

  return S_OK;
Question by:kruiser
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

ShaunWilde earned 200 total points
ID: 6194581

Author Comment

ID: 6195520

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.

Expert Comment

ID: 6195943
sorry it wasn't exact - glad to help

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question