有关于mfc webbrowser插件的使用
2016-05-25 09:35
615 查看
最近写的东西中常常需要嵌入一些浏览器,微软提供了一个比较好的接口,可以在MFC写的程序中嵌入一个简易的浏览器,是以ActiveX插件的形式提供的接口,使用起来也比较的方便,这里我就简单记录下这个插件的使用
这里我用vc6为例吧,我的机器太烂,跑不动vs这种巨人级别的软件。
1.首先创建一个对话框,在对话框上右击插入ActiveX的插件
2.可以看到微软提供了很多ActiveX的插件供我们选择。
3.选中浏览器插件确定后就能看到一个浏览器的ActiveX的插件了,下面我们为他关联一个变量m_test如下图
4.关联好后在确定按钮处填写一个消息响应。
m_test.Navigate("www.baidu.com",NULL,NULL,NULL,NULL);
用这个变量的一个成员函数打开这个网址
关于WebBrowser几个问题
1.关于如何取得这个网页的内容
2.有关于如何取得这个网页的cookie
3.关于一些消息映射
往往我们要等待网页加载完成才能进行一些操作,微软为我们提供了丰富的消息映射,在ClassWizard中可以看到
程序员的基础教程:菜鸟程序员
这里我用vc6为例吧,我的机器太烂,跑不动vs这种巨人级别的软件。
1.首先创建一个对话框,在对话框上右击插入ActiveX的插件
2.可以看到微软提供了很多ActiveX的插件供我们选择。
3.选中浏览器插件确定后就能看到一个浏览器的ActiveX的插件了,下面我们为他关联一个变量m_test如下图
4.关联好后在确定按钮处填写一个消息响应。
m_test.Navigate("www.baidu.com",NULL,NULL,NULL,NULL);
用这个变量的一个成员函数打开这个网址
关于WebBrowser几个问题
1.关于如何取得这个网页的内容
HRESULT hr; IDispatch* lpDispatch; lpDispatch = m_WebBrower.GetDocument(); IHTMLDocument2* lpDocument2; hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2); if ( hr == S_OK ) { IHTMLElement * pBody; lpDocument2->get_body(&pBody); BSTR html;//存放html源代码 CComBSTR html_t;//用于将BSTR转换为cout可以处理的字符串 pBody->get_innerHTML(&html); CString strCookie(html); CFile myfile("1.html",CFile::modeWrite|CFile::modeCreate); myfile.Write(strCookie,strCookie.GetLength()); myfile.Close(); pBody->Release(); lpDocument2->Release(); } lpDispatch->Release();
2.有关于如何取得这个网页的cookie
HRESULT hr; IDispatch* lpDispatch; lpDispatch = m_WebBrower.GetDocument(); IHTMLDocument2* lpDocument2; hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2); if ( hr == S_OK ) { hr = lpDocument2->get_cookie(&bstrCookie); if ( hr == S_OK ) { CString strCookie(bstrCookie); CFile myfile("1.txt",CFile::modeWrite|CFile::modeCreate); myfile.Write(strCookie,strCookie.GetLength()); myfile.Close(); //::MessageBox(NULL, strCookie,"当前Cookie", MB_ICONINFORMATION); } lpDocument2->put_cookie(NULL); pBody->Release(); lpDocument2->Release(); } lpDispatch->Release();
3.关于一些消息映射
往往我们要等待网页加载完成才能进行一些操作,微软为我们提供了丰富的消息映射,在ClassWizard中可以看到
程序员的基础教程:菜鸟程序员
相关文章推荐
- php Xdebug调试
- 紫金桥组态软件分屏显示技术的应用
- 百度整顿贴吧盗版 国家版权局给了个大大的赞
- uva 839 Not so Mobile
- 看完这篇文章前千万别做微信营销
- MySQL配置多实例
- Java泛型全解析
- Ubuntu16.04下qtcreator 3.6.1不能输入中文(fcitx)
- 通过 HTTP 头进行 SQL 注入
- [mysql]实现影子表数据表切换
- Centos 如何安装Django环境
- 发现自己什么都不懂,什么都想学,又什么都学不精,这是一种病态
- ssh配置
- JavaScript模块化
- 别再为了iOS新系统设备而重新安装一个新版Xcode了.其实我们可以添加版本支持
- 求最长回文子串_Manacher算法_Java实现
- Android 事件分发机制
- MySQL运算符使用问题
- 淘宝部分解禁百度蜘蛛啦!这对SEO意味着什么?
- vSphere PowerCLI安装及命令