Solved

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

Posted on 2006-11-05
4
1,870 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
Expand macro to ask for filename column 8 35
Hibernate methods 2 58
Problem to event 3 50
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now