IDispatch* FindElement( REFIID riid, IDispatch* pDispBrowser )
{
 HRESULT hr;
 IHTMLDocument2* pHTMLDocument2;

 hr= pDispBrowser->QueryInterface( IID_IHTMLDocument2, (void**)&pHTMLDocument2 );
 if (hr != S_OK) return 0;

 IHTMLElementCollection* pColl;
 hr= pHTMLDocument2->get_all( &pColl );
 if (hr != S_OK) return 0;

 LONG celem;
 hr = pColl->get_length( &celem );
 if (hr != S_OK) return 0;

 for ( int i=0; i< celem; i++ ) {
  COleVariant varIndex( (long)i );
  COleVariant var2;
  IDispatch* pDisp;

  hr = pColl->item( varIndex, var2, &pDisp );
  if ( hr != S_OK ) {
   return 0;
  }
  IHTMLElement* pElem;
  //---------- see if this one is of the requested type...
  hr = pDisp->QueryInterface( riid, (void **)&pElem );
  if ( hr == S_OK ) {   // YES!
   pDisp->Release();
   return( pElem );
  }
  pDisp->Release();
 }
 return(0);
}


==========================================
실제로쓰기

CWebBrowser2* pBrowser= (CWebBrowser2*)GetDlgItem( IDC_PREVIEW_IKEA );


  IHTMLFrameBase* pFrameSetElem= (IHTMLFrameBase*)FindElement(
   IID_IHTMLFrameBase, pBrowser->GetDocument()
   );

Posted by 모과이IT
,