Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 69
mapAB Challlenge 35 157
wordappend challenge 8 200
"Black Box" Testing of Control System Software 2 70
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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