WEB开发网
开发学院软件开发VC 定制浏览器 阅读

定制浏览器

 2006-07-22 22:02:45 来源:WEB开发网   
核心提示: BOOL CFMDBrowser::DisConnect(){IUnknown *p_Unk=GetControlUnknown();if(p_Unk==NULL)return FALSE;BOOL bOK=FALSE;//查找连接点对象IConnectionPointContainer
BOOL CFMDBrowser::DisConnect()
{
  IUnknown *p_Unk=GetControlUnknown();
  if(p_Unk==NULL)
    return FALSE;
  
  BOOL bOK=FALSE;
  
  //查找连接点对象
  IConnectionPointContainer *i_cpc=0;
  HRESULT hr=p_Unk->QueryInterface(IID_IConnectionPointContainer,
    (void **)(&i_cpc));
  if (SUCCEEDED(hr))
  {
    IConnectionPoint *i_cp=0;
    hr=i_cpc->FindConnectionPoint(DIID_DWebBrowserEvents,&i_cp);
    if (SUCCEEDED(hr))
    {
      hr=i_cp->Unadvise(m_dwEventSinkCookie);
      i_cp->Release();
      bOK=TRUE;
    }
    i_cpc->Release();
  }
  
  return bOK;
}

三、定制浏览器UI

浏览器提供了IDocHostUIHandler出接口,向用户查询界面特性

可以提供这个接口,与浏览器连接上,在其实现中,定制界面

1.建立接口

class CFMDBrowser : public CWebBrowser
{
  ...
  //IDocHostUIHandler接口,控制浏览器界面
  BEGIN_INTERFACE_PART(UIHandlerSink,IDocHostUIHandler)
    STDMETHOD(ShowContextMenu)(DWORD,POINT*,IUnknown*,IDispatch*);
    STDMETHOD(GetHostInfo)(DOCHOSTUIINFO*);
    STDMETHOD(ShowUI)(DWORD,
      IOleInPlaceActiveObject*,
      IOleCommandTarget*,
      IOleInPlaceFrame*,
      IOleInPlaceUIWindow*);
    STDMETHOD(HideUI)();
    STDMETHOD(UpdateUI)();
    STDMETHOD(EnableModeless)(INT);
    STDMETHOD(OnDocWindowActivate)(INT);
    STDMETHOD(OnFrameWindowActivate)(INT);
    STDMETHOD(ResizeBorder)(LPCRECT,IOleInPlaceUIWindow*,INT);
    STDMETHOD(TranslateAccelerator)(LPMSG,const GUID*,DWORD);
    STDMETHOD(GetOptionKeyPath)(LPOLESTR*,DWORD);
    STDMETHOD(GetDropTarget)(IDropTarget*,IDropTarget**);
    STDMETHOD(GetExternal)(IDispatch**);
    STDMETHOD(TranslateUrl)(DWORD,OLECHAR*,OLECHAR**);
    STDMETHOD(FilterDataObject)(IDataObject*,IDataObject**);
  END_INTERFACE_PART(UIHandlerSink)
  ...
}

无需添加接口映射

2.连接到浏览器

需要在NavigateComplete时间发生后,得到

ICustomDoc接口,由此接口的

SetUIHandler成员设置UI接口。

//设置界面接口
IDispatch *i_dispatch=0;
if (SUCCEEDED(i_dispatch=pThis->GetDocument()))
{
  IHTMLDocument2 *i_htmldoc2=0;
  if (SUCCEEDED(i_dispatch->QueryInterface(IID_IHTMLDocument2,
      (void **)(&i_htmldoc2))))
  {
      // force connection of IDocHostUIHandler
      ICustomDoc *i_customdoc=0;
      if (SUCCEEDED(i_htmldoc2->QueryInterface(
            IID_ICustomDoc,
            (void **)(&i_customdoc))))
      {
        i_customdoc->SetUIHandler(
          &(pThis->m_xUIHandlerSink));
        i_customdoc->Release();
      }
  }
  i_dispatch->Release();
}

3.在接口的实现中,控制用户界面

例如更改右键菜单

在STDMETHOD(ShowContextMenu)(DWORD,POINT*,IUnknown*,IDispatch*);

的实现中:

HRESULT CFMDBrowser::ShowContextMenu(DWORD,POINT*,IUnknown*,IDispatch*)
{
  ..建立自己的菜单
    return S_OK;    
}

上一页  1 2 3 

Tags:定制 浏览器

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接