如何对webbrowser和IE编程

http://blog.csdn.net/shanhe/archive/2005/06/18/397373.aspx
http://topic.csdn.net/t/20061215/13/5233052.html

IHTMLDocument2*   pDoc   =   CWebBrowser2::GetDocument();  
  IHTMLElement*   pBody,   *pParent;  
  l_pDoc->get_body(&pBody);  
  pBody->get_parentElement(   &pParent   );  
  BSTR   bstrHtml;  
  pParent->get_outerHTML(&bstrHtml);  
  CString   strHtmlText(bstrHtml);   //   这就是你想得到的源文件,   可能没有<!Doctype>标记.  
  ::SysFreeString(bstrHtml);  
   
  另一种方法:  
  IPersistStreamInit   *pPSI=NULL;  
  IStream   *pStream=NULL;    
  HGLOBAL     hHTMLText;    
           
  if     (FAILED(pDoc->QueryInterface(&pPSI)))   return;  
   
   
  hHTMLText   =   GlobalAlloc(GMEM_FIXED,   65534   );  
  CreateStreamOnHGlobal(hHTMLText,   TRUE,   &pStream);    
  pPSI->Save(pStream,   FALSE);  
   
  CString   strSource   ;   //   Html   文本  
  unsigned   short   unicode   =   *(unsigned   short*)hHTMLText;  
  if(   unicode==0xFEFF   )  
  {  
  wchar_t   *   wideString   =   (wchar_t*)(hHTMLText);  
  wideString   +=   1;  
  int   len   =   wcslen(   wideString   );  
  int   count   =   wcstombs(   NULL,   wideString,len);  
  char*   pBuf   =   new   char[count+1];  
  memset(   pBuf,   0   ,   count   );  
  count   =   wcstombs(   pBuf,wideString,count);  
  if(   count   >   0   )  
  pBuf[count]   =   '\0';  
  strSource   =   CString(   pBuf   );  
  delete[]   pBuf;  
  }  
  else  
  {  
  strSource   =   CString(   (char*)hHTMLText   );  
  }  
   
  pStream->Release();  
  pPSI->Release();  

posted on 2009-10-13 06:46  Austin Bai  阅读(400)  评论(0编辑  收藏  举报

导航