WebBrowser 中遍历所有的frames
枚举所有iframe的IWebBrowser2
// Get the IDispatch of the document.
//
LPDISPATCH lpDisp = NULL;
lpDisp = m_webBrowser.GetDocument(); if (lpDisp)
{
IOleContainer* pContainer; // Get the container.
//
HRESULT hr = lpDisp->QueryInterface(IID_IOleContainer,
(void**)&pContainer);
lpDisp->Release(); if (FAILED(hr))
return hr; // Get an enumerator for the frames.
//
IEnumUnknown* pEnumerator; hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
pContainer->Release(); if (FAILED(hr))
return hr; IUnknown* pUnk;
ULONG uFetched; // Enumerate and refresh all the frames.
//
for (UINT i = ; S_OK == pEnumerator->Next(, &pUnk, &uFetched); i++)
{
// QI for IWebBrowser here to see whether we have
// an embedded browser.
IWebBrowser2* pWebBrowser; hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser);
pUnk->Release(); if (SUCCEEDED(hr))
{
// Refresh the frame.
pWebBrowser->Refresh();
pWebBrowser->Release();
}
} pEnumerator->Release();
}
枚举所有iframe的element
HRESULT hr = S_OK; try
{
CComPtr<IDispatch> spDispDoc;
hr = m_spWebBrowser->get_Document(&spDispDoc); // find all iframe elements and filter by id, then insert ad js
CComQIPtr<IHTMLDocument2> spDoc2 = spDispDoc; if(spDoc2){
CComQIPtr<IHTMLElementCollection> spAll;
hr = spDoc2->get_all(&spAll);
if (SUCCEEDED(hr)) {
CComPtr<IDispatch> spDispObjects;
// just handle iframes as example
CComVariant varTag = _T("IFRAME");
varTag.vt = VT_BSTR;
hr = spAll->tags(varTag, &spDispObjects); if(SUCCEEDED(hr))
{
CComQIPtr<IHTMLElementCollection> spElementCollection = spDispObjects;
long lObjectCount = ;
if( spElementCollection )
hr = spElementCollection->get_length(&lObjectCount);if (SUCCEEDED(hr) && lObjectCount > )
{
for (int i = ; i < lObjectCount; i++)
{
CComVariant vIndex = i;
CComVariant vEmpty;
CComPtr<IDispatch> spdispObject;
hr = spElementCollection->item(vIndex, vEmpty, &spdispObject);
if (SUCCEEDED(hr))
{
CComQIPtr<IHTMLElement> spElement = spdispObject;
if (spElement)
{
CComBSTR bstrId = _T("");;
long width = , height = ;
spElement->get_id(&bstrId);
spElement->get_offsetHeight(&height);
spElement->get_offsetWidth(&width); if(!IsAcceptableSize(width, height))
continue;
CComVariant vSrcUrl = _T("");
hr = spElement->getAttribute(_T("src"), 0, &vSrcUrl);
} } } } } } } } catch(_com_error &ex) { LPCTSTR errMsg = ex.ErrorMessage(); WriteLog(_T("_com_error: ") + CString(errMsg)); } return hr;
WebBrowser 中遍历所有的frames的更多相关文章
- webBrowser中操作网页元素全攻略
原文 webBrowser中操作网页元素全攻略 1.获取非input控件的值: webBrowser1.Document.All["控件ID"].InnerText; 或webBr ...
- Java中遍历Map集合的四种方法
在Java中如何遍历Map对象 How to Iterate Over a Map in Java 在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都 ...
- 关于delphi点击webbrowser中任意一点的问题
关于delphi点击webbrowser中任意一点的问题 有时候我们需要delphi载入webbrowser1打开网页的时候 需要点击某一个点的位置 可能是坐标 可能是按钮 可能是其他的控件应该如何来 ...
- java 中遍历hashmap 和hashset 的方法
一.java中遍历hashmap: for (Map.Entry<String, Integer> entry : tempMap.entrySet()) { String ...
- 在 Django 模板中遍历复杂数据结构的关键是句点字符
在 Django 模板中遍历复杂数据结构的关键是句点字符 ( . ). 实例二 mysit/templates/myhtml2.html修改如下 <!DOCTYPE html> <h ...
- C#:WebBrowser中伪造referer,为何对流量统计器无效?
使用webbrowser伪造referer的方法:webBrowser1.Navigate(url, "_self", null, "Referer:http://www ...
- Freemarker中遍历List以及内置函数使用
在Freemarker应用中经常会遍历List获取需要的数据,并对需要的数据进行排序加工后呈现给用户. 那么在Freemarker中如何遍历List,并对List中数据进行适当的排序呢?一. Free ...
- asp.net中遍历界面上所有控件进行属性设置
* 使用方法: * 前台页面调用方法,重置: protected void Reset_Click(object sender, EventArgs e) { ...
- Java中遍历Map的几种方法
转自: http://blog.csdn.net/wzb56/article/details/7864911 方法分为两类: 一类是基于map的Entry:map.entrySet(); 一类是基 ...
随机推荐
- 显示hello
The modern user interface is constructed from visual objects of various sorts. Depending on the oper ...
- 整理QQ数据库sql语句
设置数据库的时候 qq 号如果用整型,设置成UNSIGNED,不然超过一定数值就错误 UPDATE `sao_qq` SET qq_num = REPLACE ( qq_num, '@qq.com', ...
- xml 解析
例:解析以下片段 <font> <name>Helvetica</name> <size units="pt">36</siz ...
- python 数据库 blob类型 转字符串
例如: 从数据库里读出了blob类型,如 z = b'61736467' 在py里转化成字符串:bytes.fromhex(z).decode('utf8')
- 转:WIN7上搭建Windows Phone 8 开发环境——VMware Workstation下Win8 “无法安装Hyper-V, 某个虚拟机监控程序正在运行”问题解决的办法
转自:http://www.cnblogs.com/shaddock2013/p/3155024.html 最近在试着在Windows 7上搭建Windows Phone 8的开发调试环境,使用的是V ...
- Flex 加载shp
至于gis格式比较常见的shp是开源的,网上开源的as代码也很多 这个支持的shp算比较好的 源码在这边http://files.cnblogs.com/files/haibalai/shp.rar, ...
- CSS中的相对定位和绝对定位
1.元素的position属性的值默认为static 就是没有定位,元素出现在正常的文档流中,,这个时候你给这个元素设置的left,right,bottom,top这些偏移属性都是没有效果的, 使用相 ...
- 给JAVA初学者的50个忠告
摘自: http://wenku.baidu.com/link?url=p5vDKt5bKzUXxG_hAsB9XopHJRROeovOGGh4jnXGZXiUedR-fNOLO7zb6ddENo5U ...
- IMS Global Learning Tools Interoperability™ Implementation Guide
Final Version 1.1 Date Issued: 13 March 2012 Latest version: http://www.imsglobal ...
- Hadoop HDFS编程 API入门系列之简单综合版本1(四)
不多说,直接上代码. 代码 package zhouls.bigdata.myWholeHadoop.HDFS.hdfs4; import java.io.IOException; import ja ...