[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CHTMLView, View Source

Posted on 2002-03-21
5
Medium Priority
?
1,187 Views
Last Modified: 2013-11-20
I am using VC++6.0, Created a SDI App based on CHTMLVIEW

I use the following code to get & set the HTML source in the browser...


#include "mshtml.h"

CString CMyBrowserView::GetHTML()
{
     IHTMLDocument2* pDoc = (IHTMLDocument2*)GetHtmlDocument();
     IHTMLElement* pBody;
     pDoc->get_body ( &pBody );
     
     BSTR Body;
     pBody->get_outerHTML ( &Body );
     
     CString Page ( Body );
     ::SysFreeString (Body );

     return Page;
}

void CMyBrowserView::SetHTML(CString html)
{
     IHTMLDocument2* pDoc = (IHTMLDocument2*)GetHtmlDocument();
     
     IHTMLElement* pBody;
     pDoc->get_body ( &pBody );
     
     BSTR what = html.AllocSysString();
     pBody->put_innerHTML(what);
     ::SysFreeString (what);
}

But the above code only gets the body HTML and sets the body HTML.

What I need is a new function which gets the correct source.  Something that would get
the same source as when I would right click and go view source and it would open in notepad.. also like The IE->View Source

Also a fix on the setHTML function would be appreciated but not needed
0
Comment
Question by:MarkOttoSmith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Accepted Solution

by:
peterdownes earned 1200 total points
ID: 6887794
// Get document.
IHTMLDocument2* pDoc = (IHTMLDocument2*)GetHtmlDocument();

// Get element collection.
CComPtr<IHTMLElementCollection> p2;
   
VERIFY(SUCCEEDED(pDoc->get_all(&p2)));

// First element.
CComPtr<IDispatch>      p3;
CComQIPtr<IHTMLElement> p4;
CComBSTR                bstr;
CComVariant             var1(0);
CComVariant             var2(0);
long                    lLength = 0;

VERIFY(SUCCEEDED(p2->get_length(&lLength)));
VERIFY(SUCCEEDED(p2->item(var1, var2, &p3)));
VERIFY((p4 = p3) != NULL);
VERIFY(SUCCEEDED(p4->get_tagName(&bstr)));
VERIFY(bstr == "HTML");
VERIFY(SUCCEEDED(p4->get_outerHTML(&bstr)));

bstr contains your "View Source".

Regards
0
 

Author Comment

by:MarkOttoSmith
ID: 6890477
.cpp(352) : error C2065: 'CComPtr' : undeclared identifier
.cpp(352) : error C2275: 'IHTMLElementCollection' : illegal use of this type as an expression
        C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\mshtml.h(28115) : see declaration of 'IHTMLElementCollection'
.cpp(352) : error C2065: 'p2' : undeclared identifier
.cpp(357) : error C2275: 'IDispatch' : illegal use of this type as an expression
        C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oaidl.h(2694) : see declaration of 'IDispatch'
.cpp(357) : error C2065: 'p3' : undeclared identifier
.cpp(358) : error C2065: 'CComQIPtr' : undeclared identifier
.cpp(358) : error C2275: 'IHTMLElement' : illegal use of this type as an expression
        C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\mshtml.h(10120) : see declaration of 'IHTMLElement'
.cpp(358) : error C2065: 'p4' : undeclared identifier
.cpp(359) : error C2065: 'CComBSTR' : undeclared identifier
.cpp(359) : error C2146: syntax error : missing ';' before identifier 'bstr'
.cpp(359) : error C2065: 'bstr' : undeclared identifier
.cpp(360) : error C2065: 'CComVariant' : undeclared identifier
.cpp(360) : error C2146: syntax error : missing ';' before identifier 'var1'
.cpp(360) : error C2065: 'var1' : undeclared identifier
.cpp(361) : error C2146: syntax error : missing ';' before identifier 'var2'
.cpp(361) : error C2065: 'var2' : undeclared identifier
.cpp(364) : error C2227: left of '->get_length' must point to class/struct/union
.cpp(365) : error C2227: left of '->item' must point to class/struct/union
.cpp(367) : error C2227: left of '->get_tagName' must point to class/struct/union
.cpp(368) : error C2446: '==' : no conversion from 'char *' to 'int'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
.cpp(368) : error C2040: '==' : 'int' differs in levels of indirection from 'char [5]'
.cpp(369) : error C2227: left of '->get_outerHTML' must point to class/struct/union
Error executing cl.exe.

22 error(s), 0 warning(s)

Didn't work
0
 
LVL 3

Expert Comment

by:job_s
ID: 6890745
#include "Atlbase.h"
for avoiding error due to ComPtr
0
 

Author Comment

by:MarkOttoSmith
ID: 6891774
cool it works.. but it doesnt give me the same as right clicking and view source...
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6973445
Is more needed here?
Moondancer - EE Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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