🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
12 messages
12 total messages Started by Tom Tue, 13 Mar 2007 21:11
TCPPWebBrowser and obtaining source after changing
#48
Author: Tom
Date: Tue, 13 Mar 2007 21:11
44 lines
2084 bytes
After modifying the source by using IHTMLDOMNode to insert a new node the 
source code that's returned does not reflect this change (what's shown in 
the browser is correct). What is the proper method for obtaining the new 
source? Right now I'm the code below which was obtained from the archives 
and slightly modified.

Thanks,

Tom

  AnsiString Source = "";


  TComInterface<IHTMLDocument2> htm;

  if(Browser->Document && 
SUCCEEDED(Browser->Document->QueryInterface(IID_IHTMLDocument2, 
(LPVOID*)&htm)))
  {
    TComInterface<IPersistStreamInit> spPsi;

    if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit, 
(LPVOID*)&spPsi)))
    {
      TComInterface<IStream> spStream;
      OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
      if(spStream)
      {
        __int64 nSize = 0;
        STATSTG ss;
        LARGE_INTEGER nMove;
        nMove.QuadPart = 0;
        OleCheck(spPsi->Save(spStream, true));
        OleCheck(spStream->Seek(nMove, STREAM_SEEK_SET, 
(ULARGE_INTEGER*)&nSize));
        OleCheck(spStream->Stat(&ss, STATFLAG_NONAME));
        nSize = ss.cbSize.QuadPart;

        Source.SetLength(nSize);
        OleCheck(spStream->Read((void *)Source.data(), nSize, 
(ULONG*)&nSize));
      }
    }
  } 
Re: TCPPWebBrowser and obtaining source after changing
#49
Author: Remy Lebeau (TeamB)
Date: Tue, 13 Mar 2007 22:47
22 lines
1581 bytes
"Tom" <tom@nospam.net> wrote in message
news:45f70570@newsgroups.borland.com...

> After modifying the source by using IHTMLDOMNode to insert a new
node the
> source code that's returned does not reflect this change (what's
shown in
> the browser is correct). What is the proper method for obtaining the
new
> source? Right now I'm the code below which was obtained from the
archives
> and slightly modified.

When you retreive the source for a document, you are telling the
stream to clear its dirty flag.  When you add a new node to the same
document afterwards, I'm guessing that the flag is not being reset, so
the stream does not generate new data the next time it is read from
the same document.


Gambit
Re: TCPPWebBrowser and obtaining source after changing
#50
Author: Tom
Date: Tue, 13 Mar 2007 23:08
9 lines
1183 bytes
> I'm guessing that the flag is not being reset, so
> the stream does not generate new data the next time it is read from
> the same document.

How can I force the flag to be reset?

Thanks,

Tom
Re: TCPPWebBrowser and obtaining source after changing
#51
Author: Remy Lebeau (TeamB)
Date: Tue, 13 Mar 2007 23:47
10 lines
1109 bytes
"Tom" <tom@nospam.net> wrote in message
news:45f720ed@newsgroups.borland.com...

> How can I force the flag to be reset?

You can't.  The browser controls that internally.


Gambit
Re: TCPPWebBrowser and obtaining source after changing
#52
Author: Remy Lebeau (TeamB)
Date: Tue, 13 Mar 2007 23:55
31 lines
1650 bytes
"Tom" <tom@nospam.net> wrote in message
news:45f70570@newsgroups.borland.com...

> After modifying the source by using IHTMLDOMNode to insert a
> new node the source code that's returned does not reflect this
change
> (what's shown in the browser is correct).

Instead of using IPersistStreamInit, try grabbing the current HTML
from the document's outerHTML property instead, for example:

    WideString Source;

    TComInterface<IHTMLDocument3> htm;

    if( Browser->Document )
        Browser->Document->QueryInterface(IID_IHTMLDocument3,
(LPVOID*)&htm);

    if( htm )
    {
        TComInterface<IHTMLElement> element;
        htm->get_documentElement(&element);

        if( element )
            element->get_outerHTML(&Source);
    }


Gambit
Re: TCPPWebBrowser and obtaining source after changing
#53
Author: Tom
Date: Wed, 14 Mar 2007 00:29
12 lines
1241 bytes
Remy,

That code does return the correct source however it removes any formatting 
the source had with respect to line breaks and indenting. It also changes 
the capitalization of the tags and removes quotes from attributes that 
should be there.

Do you have any way of preserving these aspects?

Thanks,

Tom
Re: TCPPWebBrowser and obtaining source after changing
#54
Author: Remy Lebeau (TeamB)
Date: Wed, 14 Mar 2007 02:55
15 lines
1522 bytes
"Tom" <tom@nospam.net> wrote in message
news:45f733de@newsgroups.borland.com...

> Do you have any way of preserving these aspects?

There isn't any.  Those are the only two mechanisms that the provide
provides for extracting the source code.  Your only other option is to
simply not download the original HTML using the web browser at all,
but to download it off of the server directly with your own socket
code.  But then you lose the editing capabilities that you are looking
for, unless you parse the HTML manually as well.


Gambit
Re: TCPPWebBrowser and obtaining source after changing
#55
Author: Tom
Date: Wed, 14 Mar 2007 13:19
17 lines
1695 bytes
Gambit,

I should have clarified things a bit sooner. I'm basically working on an
HTML editor, so the source code the browser starts out with is written
by me. The part I'm struggling with now has to do with re-ordering
objects after the user has dragged and dropped them. The objects
get moved around find in the display. Then when I re-populate the
treeview control with all elements contained in the document those
are shown correctly too. Not sure if that info may shed some light
on what I may already be doing wrong, or if there's another solution
to my problem.

I'm going to keep trying to trigger that dirty flag.

Thanks,

Tom 
Re: TCPPWebBrowser and obtaining source after changing
#57
Author: Tom
Date: Wed, 14 Mar 2007 17:27
18 lines
2039 bytes
> Are you using the DHTML editor control that Microsoft provides?  It is
> already integrated with Internet Explorer, which TCppWebBrowser wraps.

No, alot of what I'm "editing" is CSS based. I have a column of controls for
adjusting background color, border color/thickness/style, fonts, etc all
through CSS and not HTML properties. From what I can tell from the MS
Docs I can't accomplish what I want through the editor. I can edit the same
properties but they get set on a per element basis. I'm reading under:
Web Development -> Internet Explorer Development -> Hosting and
Reuse -> MSHTML Editing. If this is the wrong section please correct
me.

The editor is meant to be as simple as possible, with little to no actual
HTML editing done. Inserting pre-existing blocks of html code for the
desired look. The program is meant for creating templates for another
program of mine, rather than creating static web pages.

-Tom 
Re: TCPPWebBrowser and obtaining source after changing
#56
Author: Remy Lebeau (TeamB)
Date: Wed, 14 Mar 2007 17:58
12 lines
1418 bytes
"Tom" <tom@nospam.net> wrote in message
news:45f7f66b$1@newsgroups.borland.com...

> I should have clarified things a bit sooner. I'm basically
> working on an HTML editor,

Are you using the DHTML editor control that Microsoft provides?  It is
already integrated with Internet Explorer, which TCppWebBrowser wraps.


Gambit
Re: TCPPWebBrowser and obtaining source after changing
#58
Author: Tom
Date: Wed, 14 Mar 2007 20:22
21 lines
1790 bytes
> Are you using the DHTML editor control that Microsoft provides?  It is
> already integrated with Internet Explorer, which TCppWebBrowser wraps.

After looking some more I may be able to use the built in editor and 
accomplish
what I want. The source code seems to pull correctly after re-ordering the
items.

However, I now have a new problem. I had been overriding the event
handler with ICustomDoc -> SetUIHandler to trap the left clicks and context
menus but now that the browser is in design mode it doesn't seem to work?

By this I mean if I click on an element it's selected in the editor but the 
event
isn't triggered. If I don't click on an element, say below the last one, the 
event
is triggered.

Any advice is appreciated.

-Tom
Re: TCPPWebBrowser and obtaining source after changing
#59
Author: Mark Guerrieri
Date: Thu, 15 Mar 2007 03:53
11 lines
1743 bytes
> After looking some more I may be able to use the built in editor and 
> accomplish

If you are using the DHTML Editing ActiveX control, do some research first. 
It is deprecated by Microsoft. Some XP updates disable this control, and it 
is not even shipped with Vista. You are encouraged to use the "designMode" 
attribute of the document and use MSHTML editing instead (very powerful, but 
not easy to extend the default behaviors...) Worst of all, no source 
preservation...

Mark 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads