您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页Windows上使用CEF嵌入基于chrome内核浏览器小例

Windows上使用CEF嵌入基于chrome内核浏览器小例

来源:保捱科技网

浏览器代码已开源:欢迎收藏 

CEF出来很久了,使用的也很广泛的,QQ里面很多地方都是嵌入的CEF浏览器(个人资料、微博、查找……),网上的资料也挺多的,大家可以搜搜看。

这里推荐一个很详细的解说:http://www.cnblogs.com/think/archive/2011/10/06/CEF-Introduce.html

重载CEF的各种“消息”处理类,当你需要自己处理或者自定义这些消息时,才需要重载它们,重载后一定要重写相应的虚函数返回this指针。估计内部是有这些个回调类对象指针,不返回this的话默认就是NULL了,就会执行内部默认的那套机制。

 

#pragma once
#include "include/cef_client.h"
#include <list>
#include <string>
using std::wstring;

class CCefHandler :
	public CefClient,
    public CefDisplayHandler,
    public CefLifeSpanHandler,
	public CefLoadHandler,
	public CefRequestHandler,
	public CefContextMenuHandler,
	public CefDownloadHandler
{
public:
	CCefHandler(const wstring& strUrl=L"");
	virtual ~CCefHandler();
	//自定义方法
	CefRefPtr<CefBrowser> GetBrowser() { return m_pBrowser; }
	CefRefPtr<CefFrame>	GetMainFram() { return m_pBrowser.get()?m_pBrowser->GetMainFrame():NULL; }
	HWND	GetBrowserHostWnd() { return m_pBrowser.get()?m_pBrowser->GetHost()->GetWindowHandle():NULL; }
	void	SetHomePage(const wstring& strUrl) { m_strHomePage=strUrl; }
	const wstring& GetHomePage()const { return m_strHomePage; }
	wstring GetLoadingUrl();
	void	Navigate(const wstring& strUrl);
	void	CreateBrowser(HWND hParentWnd, const RECT& rect);
	bool	IsClosing() const { return m_bIsClose; }

  //凡是继承了的处理功能都在这里返回this指针
	virtual CefRefPtr<CefDisplayHandler>		GetDisplayHandler()		{ return this; }
	virtual CefRefPtr<CefLifeSpanHandler>		GetLifeSpanHandler()	{ return this; }
	virtual CefRefPtr<CefLoadHandler>			GetLoadHandler()		{ return this; }
	virtual CefRefPtr<CefContextMenuHandler>	GetContextMenuHandler()	{ return this; }
	virtual CefRefPtr<CefDownloadHandler>		GetDownloadHandler()	{ return this; }
  // CefDisplayHandler methods:
  virtual void OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title);
  virtual void OnAddressChange(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& url);
  virtual bool OnTooltip(CefRefPtr<CefBrowser> browser, CefString& text);
  virtual void OnStatusMessage(CefRefPtr<CefBrowser> browser, const CefString& value);

  // CefLifeSpanHandler methods:
  virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, \
	  const CefString& target_url, const CefString& target_frame_name, const CefPopupFeatures& popupFeatures, \
	  CefWindowInfo& windowInfo, CefRefPtr<CefClient>& client, CefBrowserSettings& settings, \
	  bool* no_javascript_access);
  virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser);
  virtual bool DoClose(CefRefPtr<CefBrowser> browser);
  virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser);

  // CefLoadHandler methods:
  virtual void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame);
  virtual void OnLoadEnd(CefRefPtr<CefBrowser>

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务