Solved

How to use IHTMLDocument2 to get images infos, header infors, ....

Posted on 2006-11-05
4
1,902 Views
Last Modified: 2013-11-20
Hi Experts,

I need to cache the HTML that display with CHtmlView control,
I have to use IHTMLDocument2  to query HtmlDocument as below:
m_MyHtmlCtrl->GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2, (void **) &pDoc);
I can get the body infos by using get_body(0 function
But I don't know how to get images infos, header infos with this, I need to save the contents of HTML to local html file and o need to save all images to the local too.

Please help me with this.
Thank in advance!



0
Comment
Question by:CongUan
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 500 total points
ID: 17879002
For HTML you may use IHTMLDocument2::get_innerHTML() and for images IHTMLDocument2::get_images()

You may use following code to extract HTML from view...
e.g.

// Note:  CMyHtmlView is derived from CHtmlView

CString CMyHtmlView::GetHtmlText()
{
 CString Text;
 HRESULT hr;
 IHTMLDocument2 *pDoc = NULL;

 // Load the current document into pDoc
 hr = this->GetHtmlDocument()->QueryInterface(IID_IHTMLDocument2, (void **) &pDoc);

 if (hr == S_OK)
 {
  BSTR pelementText = NULL;
  IHTMLElement *Element = NULL;

  // Get the body
  pDoc->get_body(&Element);

  Element->get_innerHTML(&pelementText);
  Text = pelementText;

 } // End HTMLdocument is valid (HR == OK)

 return Text;
}

For images look here : http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20294289.html

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17879081
Alternatively you may use UrlDownloadToFile() API function to download elements, images, entire webpage to disk.
http://msdn.microsoft.com/workshop/networking/moniker/reference/functions/urldownloadtofile.asp

-MAHESH
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 178
Perl Awk Need Help 3 120
centeredAverage challenge 8 167
lucky13 challenge 11 148
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question