Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Enable menu implemented thu XDocHostUIHandler::ShowContextMenu

Posted on 2001-06-14
3
Medium Priority
?
306 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
[X]
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
3 Comments
 
LVL 9

Accepted Solution

by:
ShaunWilde earned 600 total points
ID: 6194581
0
 

Author Comment

by:kruiser
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.
0
 
LVL 9

Expert Comment

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

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

704 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