Solved

Enable menu implemented thu XDocHostUIHandler::ShowContextMenu

Posted on 2001-06-14
3
294 Views
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;
 
  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
Comment
Question by:kruiser
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 200 total points
Comment Utility
0
 

Author Comment

by:kruiser
Comment Utility

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
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
sorry it wasn't exact - glad to help
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 89
EvenOdd challenge 10 83
Modbus - whats the maximum I can store in one register? 4 74
sumHeights2  challenge 7 75
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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now