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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 110
sum13 challenge 24 149
matchUp  challenge 9 134
Authenticate using sesu from script 7 159
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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