- #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 );
- }
- }
- }
- }
- }
枚举IHTMLDocument2中所有IFRAME的内容
最新推荐文章于 2021-06-10 00:16:07 发布