Customization and extension of browsers

Source: Internet
Author: User
Tags extend

Objective

Because I often in the development of embedded in the program browser, in order to meet their own needs often to expand and customize the browser, to solve these problems need to find information on the Internet and learning process, I think many developers may encounter the same problem, close-up of this article for your reference.

Using Browsers in MFC

In MFC, Microsoft has provided us with the CHtmlView, CDHtmlDialog class makes our program very convenient to embed the browser and carries on the browser two times to develop, this is more convenient than the direct use WebBrowser control, therefore this article discusses the browser question is addressed to the CHtmlView. A class Clhphtmlview is mentioned, which is a derived class of CHtmlView, and the extensions or customizations mentioned in the text are implemented on the Clhphtmlview class (or derived class).

How to extend or customize your browser

The browser defines some extension interfaces (such as IDocHostUIHandler can customize the behavior of the browser interface) for developers to customize and extend. The browser will query these interfaces to his control site when needed, and implement the corresponding interfaces in the control site to expand accordingly. In the MFC7.01 class library, CHtmlView uses a control site that is CHtmlControlSite, implements only the interface IDocHostUIHandler in the CHtmlControlSite class, and implements more extension interfaces, You must replace CHtmlControlSite with a custom control station class, and the class Cdochostsite mentioned below is the custom control station class.

For an introduction to the interface, please refer to:http://dev.csdn.net/develop/article/48/48483.shtm

How do I make a custom control site replace the default control site? In MFC7.0, only the CHtmlView virtual function createcontrolsite can be overloaded:

BOOL CLhpHtmlView::CreateControlSite(COleControlContainer * pContainer,
COleControlSite ** ppSite, UINT /*nID*/, REFCLSID /*clsid*/)
{
  *ppSite = new CDocHostSite(pContainer, this);// 创建自己的 控制站点实例
  return (*ppSite) ? TRUE : FALSE;
}
VC6.0 to replace the control station is much more complicated, here is not discussed, if you need 6.0 version please send me an email to yourshine@21cn.com.

Customize the right mouse button to eject the menu

To customize the browser's right mouse button pop-up menu, you must implement the IDocHostUIHandler2 interface in the custom control site class, and the IE version is 5.5 or more. Invoking the Onshowcontextmenu virtual function of the browser class in the ShowContextMenu method of the interface IDocHostUIHandler2, we can override this virtual function in the derived class of the browser class to customize the right-click menu, see Code

HRESULT Cdochostsite::xdochostuihandler::showcontextmenu (DWORD dwid,
Point * ppt,
IUnknown * pcmdtreserved,
IDispatch * pdispreserved)
{
Method_prologue (Cdochostsite, Dochostuihandler);
Return pthis->m_pview->onshowcontextmenu (Dwid, PPT, pcmdtreserved,pdispreserved);
}
HRESULT Clhphtmlview::onshowcontextmenu (DWORD dwid,
Lppoint ppt,
Lpunknown pcmdtreserved,
Lpdispatch pdispreserved)
{
HRESULT result = S_FALSE;
Switch (M_contextmenumode)
{
Case Nocontextmenu://No Menu
RESULT=S_OK;
Break
Case Defaultmenu://default Menu
Break
Case TEXTSELECTIONONLY://Text Selection menu only
if (!) ( Dwid = = Context_menu_textselect | | Dwid = = Context_menu_control))
RESULT=S_OK;
Break
Case Custommenu://Custom Menu
if (dwid! =context_menu_textselect)
Result=onshowcustomcontextmenu (ppt,pcmdtreserved,pdispreserved);
Break
}
return result;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.