Re: IHTMLDocument2 problem



Yes, SetHTML is not working. A walkaround is to create the elements
(IHTMLDocument2::create...) and add them to the documents. If you are create
script elemnts, you need to set the defer attribute to true as well.

--
Regards
Sheng Jiang

Microsoft Most Valuable Professional in Visual C++
http://www.jiangsheng.net
http://blog.joycode.com/jiangsheng/
"RushManbert" <RushManbert@xxxxxxxxxxxxxxxxxxxxxxxxx> дÈëÓʼþ
news:D68F6595-06F4-41B8-B0C4-F535D1650787@xxxxxxxxxxxxxxxx
My app uses MFC and specifically the CHtmlCtrl class developed by Paul
DiLascia, which is derived from the CHtmlView class provided with MFC.
Essentially, I have a browser control in a modeless dialog. My intention
is
to render my own XHTML source (don't ask why :-), then load the resulting
HTML string into the control. The class very kindly provides a SetHTML
method. It works and I can load my HTML code and it displays just as
expected. (I have already developed this app for the Mac, so I am
confident
that my rendering code works.)

The source for SetHTML is shown below:
//////////////////
// Set document contents from string
//
HRESULT CHtmlCtrl::SetHTML(LPCTSTR strHTML)
{
HRESULT hr;

// Get document object
SPIHTMLDocument2 doc = GetHtmlDocument();
ASSERT (doc);

// Create string as one-element BSTR safe array for IHTMLDocument2::write.
CComSafeArray<VARIANT> sar;
sar.Create(1,0);
sar[0] = CComBSTR(strHTML);

// open doc and write
LPDISPATCH lpdRet;
HRCHECK(doc->open(CComBSTR("text/html"),
CComVariant(CComBSTR("_self")),
CComVariant(CComBSTR("")),
CComVariant((bool)1),
&lpdRet));

HRCHECK(doc->write(sar)); // write contents to doc
HRCHECK(doc->close()); // close
lpdRet->Release(); // release IDispatch returned

return S_OK;
}

As you can see, he gets the underlying IHTMLDocument2 interface, then uses
the Open, Write, and Close methods to replace the HTML.

The problem that I am seeing is when I load a HTML string that contains
links of the form:
<a href="file://localhost/C:/path/to/file.html>Click this</a>

The display shows the links correctly, but if I click on them nothing
happens. The CHtmlCtrl has the OnBeforeNavigate2 event callback, but it
doesn't get called, and the browser doesn't load the page named in the
link.
(Yes it's a valid path, etc.)

I created a MFC app based on CHtmlView and made it load the file
containing
the links (which I generated by getting the source from the web browser
control after I loaded the HTML string, so I know that it's the same HTML
source). In that case if I click on a link, the OnBeforeNavigate2 event
callback did get called.

I then went back to my app and changed the loading code to write the HTML
string into a temporary file, then load the temporary file using the
Navigate2 method, rather than directly loading the HTML string with
SetHTML.
When I do this, then click on the links, the OnBeforeNavigate2 event
callback
IS called.

This leads me to the conclusion that either there is some bug in the
SetHTML
implementation that causes clicked links to be ignored, or there is a bug
down in the COM (ActiveX?) control that achieves the same (non)result.

I'm hoping that someone who knows about this stuff can shed some light on
this. For various reasons, I really don't want to write my rendered XHTML
out
to a disk file and load it (which would be the blunt workaround). I just
want
to keep it in memory.

Anybody have any ideas?

Thanks,
Rush


.



Relevant Pages

  • IHTMLDocument2 problem
    ... My app uses MFC and specifically the CHtmlCtrl class developed by Paul ... It works and I can load my HTML code and it displays just as ... The problem that I am seeing is when I load a HTML string that contains ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Re: Looking for memo component with text styles
    ... eshipman wrote: bold, italic, and/or underline. ... Preferably, it would load and save its contents as an HTML string, although RTF is acceptable. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Looking for memo component with text styles
    ... >>Preferably, it would load and save its contents as an HTML string, although ... >>RTF is acceptable. ... >> I can use TRichEdit, although it does a little more than I need. ...
    (borland.public.delphi.thirdpartytools.general)