C++实现WEB功能方法总结

来源:互联网 发布:淘宝二手ps4主机能买吗 编辑:程序博客网 时间:2024/06/08 00:53
C++调用Web进行编程的总结

   核心提示:C++于Web通信就是实现C++函数调用JS函数,JS函数调用C++函数


1.使用cef,cef是谷歌浏览器的核心,调试的时候需要将devtools_resources.pak放在
  可执行程序的运行目录下,然后在程序开头增加代码:
  cSettings.remote_debugging_port = 8088;//网页调试CEF使用,如果不定义,则不能运行调试工具
  
  触发谷歌啦浏览器进行调试,需要调用如下代码:
  CefRefPtr<CefBrowser> browser = g_webBrowserClient->GetBrowser();;
CefString devtools_url = browser->GetHost()->GetDevToolsURL(true);
TCHAR tmpBuf[1024 + 1] = { 0 };
_stprintf(tmpBuf, _T("window.open('%s')"), devtools_url.c_str());

browser->GetMainFrame()->ExecuteJavaScript(tmpBuf, "about:blank", 0);


CEF比较厉害的博客
http://blog.csdn.net/mfcing/article/details/43953433
http://www.cnblogs.com/chechen/p/6104943.html
http://blog.csdn.net/wangshubo1989/article/details/50180413
http://blog.csdn.net/zhuhongshu/article/details/70159672


注:腾讯QQ,微信PC端都使用了CEF,而且微信PC端也使用了免费DUILIB开源皮肤库,本人项目中用到的就是此引擎

2. DUILIB库的CActiveXUI控件和IWebBrowser2实现(基于IE浏览器内核)
   部分参考代码如下:
   CActiveXUI* pActiveXUI = static_cast<CActiveXUI*>(m_PaintManager.FindControl(_T("ie")));
if (pActiveXUI) {
IWebBrowser2* pWebBrowser = NULL;
pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser);
if (pWebBrowser != NULL) {
/*
std::string strPath = ConfigManager::instance()->getSkinPath() + "MailEditorindex.html";


int Len = ::MultiByteToWideChar(CP_ACP, 0, strPath.c_str(), -1, NULL, 0);
wchar_t *buf = new wchar_t[Len];
MultiByteToWideChar(CP_ACP, 0, strPath.c_str(), -1, buf, Len);
std::wstring wstrFilePath = std::wstring(buf);
delete[] buf;
*/
std::wstring wstrFilePath = _T("C:\\Users\\HeShiYang\\Desktop\\demo(2)\\demo\\index.html");//_T("C:\\Users\\HeShiYang\\Desktop\\demo(2)\\demo\\index.html");//
pWebBrowser->Navigate((BSTR)(wstrFilePath.c_str()), NULL, NULL, NULL, NULL);
pWebBrowser->Release();
}
}

3. 使用DUILIB库的CWebBrowserUI控件,该方法是DUILIB自己封装IWebBrowser2实现,基于IE浏览器内核


4. wke(基于WebKit是一个开源的浏览器引擎)
   wke是wke.dll是国外大神封装的webkit,体积算是极小的,另外upx压缩下才3M多,不可多得的好东西哦,只是版本旧了些。
   一般用法是将wke封装成DUILIB一个浏览器控件来使用(基于wke封装的duilib的webkit浏览器控件)

   参考网址:  http://www.cnblogs.com/findumars/p/5027146.html


阅读全文
0 0
原创粉丝点击