MFC ActiveX访问WebBrowser(读取本地登录的QQ信息)
2013-10-30 16:10
323 查看
我用的MFC编写的ActiveX。
要点1:项目中引入WebBrowserActiveX控件
要点2:由于WebBrowser本身是一个ActiveX组件,请在“项目名称App"类的initInstance()方法中添加:AfxEnableControlContainer();
要点3:添加全局变量,并在Create方法中创建ActiveX,并调用navigate方法:
要点4:通过谷歌浏览器分析浏览器读取到的本地QQ号的网页内容格式:
要点5:添加ActiveX组件对外暴露的接口方法,并代码实现:
fetchList()方法的代码:
要点1:项目中引入WebBrowserActiveX控件
要点2:由于WebBrowser本身是一个ActiveX组件,请在“项目名称App"类的initInstance()方法中添加:AfxEnableControlContainer();
要点3:添加全局变量,并在Create方法中创建ActiveX,并调用navigate方法:
要点4:通过谷歌浏览器分析浏览器读取到的本地QQ号的网页内容格式:
要点5:添加ActiveX组件对外暴露的接口方法,并代码实现:
fetchList()方法的代码:
CString strResult; // TODO: Add your dispatch handler code here if(m_wb.GetReadyState()!=READYSTATE_COMPLETE) { // AfxMessageBox("尚未加载完成"); return strResult.AllocSysString(); } USES_CONVERSION; // Get the WebBrowser's document object CComPtr<IDispatch> pDispDocument= m_wb.GetDocument(); HRESULT hr = NULL; CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pHtmlDocument = pDispDocument; IHTMLElement * m_pBody=NULL; // Extract the source code of the document if (pHtmlDocument) { // Get the BODY object hr = pHtmlDocument->get_body(&m_pBody); if (FAILED(hr)) return strResult.AllocSysString(); CComQIPtr< IHTMLElementCollection > spElementCollection;//元素集合 CComPtr< IDispatch > spDisp; CComQIPtr < IHTMLElement > spDiv; pHtmlDocument->get_all(&spElementCollection);//获得元素的集合 if(spElementCollection) { //从元素集合中查找id为"list_uin"的元素 spElementCollection->item(CComVariant(CComBSTR("list_uin")),CComVariant(),&spDisp); spDiv = spDisp; //获取这个div内的文本确定是否有QQ登录 BSTR divbstrHTMLText; spDiv->get_innerHTML(&divbstrHTMLText);//获取div类的文本 if(SysStringLen(divbstrHTMLText)==0)//如果长度为零说明没有登录 { //AfxMessageBox("没有登录的QQ"); strResult.Insert(0,"没有登录的QQ"); return strResult.AllocSysString(); } //程序周到这里说明已经登录 CComPtr<IDispatch> pDispLi; CComQIPtr<IHTMLElementCollection> pElementColletionsLi; spDiv->get_children(&pDispLi);//获取div的所有子元素li,每个li是一个登录的QQ pElementColletionsLi = pDispLi; CComPtr< IDispatch > pDispLi2; CComQIPtr < IHTMLElementCollection > pElementColletionsLi2; pElementColletionsLi->tags(CComVariant(CComBSTR("li")),&pDispLi2); pElementColletionsLi2 = pDispLi2; long licount=0; pElementColletionsLi2->get_length(&licount); for (int i=0;i<licount;i++) { CComPtr< IDispatch > pDispLi3; CComQIPtr < IHTMLElement > pElementLi; pElementColletionsLi2->item(CComVariant(i),CComVariant(i),&pDispLi3);//获得当前这个li pElementLi = pDispLi3; //以下准备获取li里面的label CComPtr<IDispatch> pDispLabel; CComQIPtr<IHTMLElementCollection> pElementColletionsLabel; CComPtr<IDispatch> pDispLabel2; CComQIPtr<IHTMLElementCollection> pElementColletionsLabel2; CComPtr< IDispatch > mylablespDisp; CComQIPtr < IHTMLElementCollection > spLabel; CComPtr< IDispatch > myLabelspDisp; pElementLi->get_children(&pDispLabel); pElementColletionsLabel = pDispLabel; pElementColletionsLabel->tags(CComVariant(CComBSTR("label")),&pDispLabel2); pElementColletionsLabel2 = pDispLabel2; long labelCount = 0; pElementColletionsLabel2->get_length(&labelCount); for (int i=0;i<labelCount;i++) { CComPtr<IDispatch> pDispLabel3; CComQIPtr < IHTMLElement > pLabel; BSTR myLabelInnerHTML; pElementColletionsLabel2->item(CComVariant(0),CComVariant(0),&pDispLabel3); pLabel = pDispLabel3; pLabel->get_innerHTML(&myLabelInnerHTML); CString line(myLabelInnerHTML); CString niceName = line; CString qq = line; niceName = niceName.Left(niceName.Find(" ")); qq.Delete(0,qq.Find("(")+1); qq.Delete(qq.GetLength()-1,1); strResult +=","+niceName+":"+qq; } } } } else { strResult.Insert(0,"这不是一个有效的html"); } if(strResult.GetAt(0)==',') { strResult.Delete(0,1); } return strResult.AllocSysString();
相关文章推荐
- VC++实现读取本地已登录的QQ号及应用代码
- 基于visual c++之windows核心编程代码分析(62)读取本地已登录的QQ号及应用代码
- VC++实现读取本地已登录的QQ号及应用代码
- 基于visual c++之windows核心编程代码分析(62)读取本地已登录的QQ号及应用代码
- 基于visual c++之windows核心编程代码分析(62)读取本地已登录的QQ号及应用代码
- VC++实现读取本地已登录的QQ号及应用代码
- jsp计数器--页面统计特定用户的登录次数或所有人的访问信息
- mfc WebBrowser打开本地网页
- 清除在Windows下访问共享文件夹时的登录信息
- 将页面信息保存到本地文件和读取本地文件信息到页面
- vc++读取文件属性的详细信息描述 通过读取QQ的注册表和EXE路径两种方式
- 【源码】仿qq记住登录信息
- C++开发人脸性别识别教程(8)——搭建MFC框架之读取文件夹信息
- QQ第三方登录获取用户信息
- ODBC + WIN32 API 访问MYSQL 数据库实现简单QQ用户注册和登录
- Windows下访问共享文件夹时的登录信息
- Android 实现qq第三方登录并获取qq基本信息
- oracle服务器本地能够登录但是局域网内其他机器不能访问的解决方法
- MFC Combobox 输入内容自动补全并选中缺失部分(类似qq登录输入账号)
- 在MFC中通过访问IP地址下载文件到本地