I am using a CHtmlView in my SDI program. Everytime the mouse is right
clicked, a stand IE menu is popped up. How can I change this menu and
add me own items? I also want add different items depending on the
location or objects clicked. For example, if a image is clicked, I
want to add something menu item that is different when a link is
clicked.
Thanks,
John
> I am using a CHtmlView in my SDI program. Everytime the mouse is right
> clicked, a stand IE menu is popped up. How can I change this menu and
> add me own items?
typically you would do this by implementing the interface IDocHostUIHandler
on the ActiveX Control client site that hosts the web browser control. In the
MSDN Library there is a good description of the interface and especially of
how to replace or modify the browser context menu. In short: each time the web
browser control is about to show a context menu, it first calls ShowContextMenu
on the IDocHostUIHandler interface. The implementor now can decide whether
to let the web browser control show the context menu or not. In the latter case
you could show your own context menu or load the web browser context menu,
modify it and then show it.
The bad news is: there is no way to implement additional interfaces on the MFC
ActiveX Control client site. All that stuff (COccManager, COleControlContainer,
COleControlSite) simply is not flexible enough to allow for additional interfaces.
The only solution from my point of view (apart from implementing it from scratch)
is to use the ATL client site implementation. It does implement IDocHostUIHandler
and delegates to an interface called IDocHostUIHandlerDispatch which is seman-
tically identical with IDocHostUIHandler (a few differences in structure). The ATL
class CAxWindow, which is used as a representative of the ActiveX Control at
the client side, provides a method SetExternalUIHandler which expects such an
IDocHostUIHandlerDispatch interface.
> I also want add different items depending on the
> location or objects clicked. For example, if a image is clicked, I
> want to add something menu item that is different when a link is
> clicked.
ShowContextMenu is being passed the mouse cursor position at least. Should
be possible to figure out the HTML element beneath using the DOM.
HTH
Frank
recommended reading:
Q241750 BUG: CHtmlView Leaks Memory by Not Releasing BSTRs in Several
Methods
Q196835 HOWTO: Override the MFC Default Control Containment
"Frank Renner" <frank-...@arcor.de> 写入邮件
news:40bb7eb4$0$26358$9b4e...@newsread4.arcor-online.net...