Solved

IHTMLDocument2

Posted on 2003-11-01
9
1,233 Views
Last Modified: 2013-12-03
Hi

I have written an IE BHO that uses the IHTMLDocument2 interface to alter the HTML, i need to be able to get the complete modified source including all the tags <!DOCTYPE....<HTML>....</HTML>. the get_body->get_innerHTML only gives me the <BODY>.....</BODY> section, thats no good i need the lot.

I either need to have it as a sting (BSTR) or be able to save it to a file.

i have already seen the few questions on here that suggest get_body, please dont suggest them... it dont work how i want it to.

Ta

Paul
0
Comment
Question by:makerp
  • 2
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:purpleblob
ID: 9663158
I've done this in C# but using IHTMLDocument3 object - however the following C++ should work

QI your IHTMLDocument2 to get an IHTMLDocument3 interface (hopefully) you'll get an IHTMLDocument3 interface back and from this you should be able to get what you want.

Here's the source (note: it's in the most basic form, i.e. no ATL etc. and for brevity all error handling has been removed).

IHTMLDocument3 pHTMLDoc3;
pHTMLDoc2->QueryInterface(IID_IHTMLDocument3, reinterpret_cast<void**>(&pHTMLDoc3);

IHTMLElement* pDocElem;
pHTMLDoc3->get_DocumentElement(&pDocElem);

pHTMLDoc3->Release();

BSTR bstrHTML;
pDocElem->get_OuterHTML(&bstrHTML);
pDocElem->Release();

I've not tested this C++ code but converted it to C# (as I've been using the browser recently in C#) and it seems to produce everything <html> to </html>.

0
 
LVL 8

Expert Comment

by:_corey_
ID: 9663996
I'm pretty sure that'll work for IHTMLDocument2 ?
0
 
LVL 6

Assisted Solution

by:purpleblob
purpleblob earned 250 total points
ID: 9664252
IHTMLDocument2 doesn't include the get_DocumentElement method. However there's another interface called HTMLDocument which also supports this method and can be used in place of IHTMLDocument3.
0
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 2

Accepted Solution

by:
gimmeadrink earned 250 total points
ID: 9709384
What about this...

HRESULT IHTMLDocument2::get_all(IHTMLElementCollection **p);

Its a zero based collection of all the elements in a webpage.
(see http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/all.asp for more info)


the other option is 'tostring'  (http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/document2/tostring.asp)

I have used both of these (although a while ago) in visual basic, should act the same way for VC++ or whatever you are using.

HTH

0
 
LVL 8

Expert Comment

by:_corey_
ID: 9716457
ToString actually does that?  I voiced a thought about that in an earlier question but never actually tried it.
0
 
LVL 2

Expert Comment

by:gimmeadrink
ID: 9719327
hmmm, i might double-check..... it was a while ago that i used it ;)

I'll get back to ya.
0
 
LVL 10

Author Comment

by:makerp
ID: 9733611
i have solved this by getting the IPersistFile interface from the IHTMLDocument2 object...

thanx anyway
0
 
LVL 10

Author Comment

by:makerp
ID: 10800469
sorry about the delay - since the update of the look & feel of EE the flash, adverts and animated gifs anoy slightly.

none of the solutions proposed here are really suitable because of the way IE alters the raw HTML in its object model. anyway i will split the points.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is it possible to use a scroll bar to view records in a form? 7 44
Problem to adjust sheet 1 90
Build VS2015 project in bat command 3 88
Question to Pivot table 1 53
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

803 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