枚举IHTMLDocument2中所有IFRAME的内容
枚舉IHTMLDocument2中所有IFRAME的內容 收藏
#include <mshtml.h>
#include <afxhtml.h>
#include <atlbase.h>
#include <oleacc.h>
#include <MsHtmcid.h>
void EnumFrame( IHTMLDocument2 *pHTML )
{
??? CComQIPtr<IOleContainer> spContainer( pHTML );
??? if( spContainer )
??? {
??????? CComPtr<IEnumUnknown> spEnumerator; // 注:參數OLECONTF_EMBEDDINGS // 表示列舉容器內的所有嵌入對象
??????? HRESULT hr = spContainer->EnumObjects(OLECONTF_EMBEDDINGS, &spEnumerator);
??????? if( spEnumerator )
??????? {
??????????? CComPtr<IUnknown> spUnk;
??????????? while (spEnumerator->Next(1, &spUnk, NULL) == S_OK)
??????????? {
??????????????? CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> spWB(spUnk);
??????????????? spUnk=NULL;
??????????????? if ( spWB )
??????????????? {
????????????????????
??????????????????? CComPtr<IDispatch> spDocDisp;
??????????????????? hr = spWB->get_Document(&spDocDisp);?
??????????????????? CComQIPtr<IHTMLDocument2> spHTML (spDocDisp) ;
????????????????????
??????????????????? HGLOBAL hMemory;
??????????????????? hMemory = GlobalAlloc(GMEM_MOVEABLE, 0);
??????????????????? CComPtr<IStream> spStream;
??????????????????? CComQIPtr<IPersistStreamInit> spPersistStream = spDocDisp;
??????????????????? if (SUCCEEDED(CreateStreamOnHGlobal(hMemory, TRUE, &spStream)))
??????????????????? {
??????????????????????? spPersistStream->Save(spStream, FALSE);
??????????????????????? LPCTSTR pstr = (LPCTSTR) GlobalLock(hMemory);
??????????????????????? if (pstr != NULL)
??????????????????????? {
??????????????????????????? // Stream is always ANSI, but CString?
??????????????????????????? // assignment operator will convert implicitly.
??????????????????????????? CString html(pstr);
??????????????????????????
????????????????????????????????????????????????????
?????????????????????????????
????????????????????????
?????????????????????????????? AfxMessageBox(html);
??????????????????????? }
??????????????????? }
????????????????????
??????????????????? EnumFrame( spHTML );
????????????????????
??????????????? }
??????????? }
??????? }
??? }
}
發表于 @ 2008年11月15日 09:09:00 | 評論( 0 ) | 編輯| 舉報| 收藏
舊一篇:使用IHTMLDocument2操作IE命令 | 新一篇:用RegisterHotKey為程序注冊系統熱鍵
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/twtzw/archive/2008/11/16/3304218.aspx
總結
以上是生活随笔為你收集整理的枚举IHTMLDocument2中所有IFRAME的内容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于一个枚举IE表单的DLL,编译无错,
- 下一篇: struct的成员对齐