Solved

C++Builder TCppWebBrowser and dynamically linked OnDocumentComplete event

Posted on 2001-06-12
8
2,109 Views
Last Modified: 2012-06-21
I am creating a TCppWebBrowser component dynamically and linking the OnDocumentComplete event. I have tested this fires correctly when the component exists on the form. It does not fire now when I do a CppWebBrowser1->Navigate for the html page.

void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  CppWebBrowser1 = new TCppWebBrowser(this);
  CppWebBrowser1->OnDocumentComplete = DocumentComplete;
}

void __fastcall TMainForm::DocumentComplete(TObject *Sender, LPDISPATCH pDisp, TVariant *URL)
{
 // print the document
 CppWebBrowser1->ExecWB   (Shdocvw_tlb::OLECMDID_PRINT,                          Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER),&vIn, &vOut);
}

(C++Builder 5.01)

Thanks and cheers, Tom.


0
Comment
Question by:tomcorcoran
8 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6181836
How you navigate? Must be something as
TCppWebBrowser1->Navigate2( WideString(TheURLAnsiString).c_bstr() );



0
 

Author Comment

by:tomcorcoran
ID: 6181915
Alex, thanks for the mail, as I said I use
CppWebBrowser1->Navigate
Navigate2 will not work with a WideString as you describe, it looks for a TVariant.
Any more ideas?
Thanks, Tom.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6185131
>>TCppWebBrowser1->Navigate2( WideString(TheURLAnsiString).c_bstr() );
Of course, it works(from some working apps).
For Navigate, it must be
CppWebBrowser1->Navigate((TVariant)Edit1->Text); //for example

Next article is NOT mine (Edward O. Warren)

http://delphi.mers.com/cgi-bin/mer.exe/EXECSEARCH?pageno=1&searchtext=DocumentComplete&grouptext=cppbuilder&linktype=viewmsg&msgno=8771&boardno=1680
.....
Well I solve it but not 'elegant'.

I hacked some code from Microsoft that used the IWebBrowser interface.
Turns out I had to change this to the IWebBrowser2 interface to work with
the TCppWebBrowser.

This codes 'gets the job done' but I would appreciate any comments on a
better way to do this. This Lacks something.

-----------code----------
// BUTTON 1:
void __fastcall TSketchPadForm1::Button1Click(TObject *Sender)
{

CppWebBrowser1->Navigate(WideString("about:blank"));
// this works it navigates to a blank page

}

// CPPWEBBROWSER 1 DOCUMENT COMPLETE EVENT -

void __fastcall TSketchPadForm1::CppWebBrowser1DocumentComplete(
TObject *Sender, LPDISPATCH pDisp, TVariant *URL)
{

// get a pointer to a IWebBrowser2 interface

IWebBrowser2* m_pBrowser
m_pBrowser = CppWebBrowser1->ControlInterface;

HRESULT hr;
IUnknown* pUnkBrowser = NULL;
IUnknown* pUnkDisp = NULL;
IStream* pStream = NULL;
HGLOBAL hHTMLText;
static char szHTMLText[]="<html><h1>HELLO</h1>";

// MODIFICATIONS *******

AnsiString strHTML;

int szHTML;
strHTML = Memo1->Text;

szHTML= strHTML.Length();

// Is this the DocumentComplete event for the top frame window?
// Check COM identity: compare IUnknown interface pointers.
hr = m_pBrowser->QueryInterface( IID_IUnknown, (void**)&pUnkBrowser );
if ( SUCCEEDED(hr) )
{
hr = pDisp->QueryInterface( IID_IUnknown, (void**)&pUnkDisp );
if ( SUCCEEDED(hr) )
{
if ( pUnkBrowser == pUnkDisp )
{ // This is the DocumentComplete event for the top
frame - page is loaded!
// Create a stream containing the HTML.
// Alternatively, this stream may have been passed to
us.
// hHTMLText = GlobalAlloc( GPTR,
lstrlen(szHTMLText)+1 );

// MODIFICATION
// *****************************************
hHTMLText = GlobalAlloc( GPTR, szHTML+1 );

if ( hHTMLText )
{
// lstrcpy( (char*)hHTMLText, szHTMLText );

// MODIFICATION ***********************

lstrcpy( (char*)hHTMLText, strHTML.c_str() );

hr = CreateStreamOnHGlobal( hHTMLText, TRUE, &pStream );
if ( SUCCEEDED(hr) )
{
// Call the helper function to load the WebOC
from the stream.
LoadWebOCFromStream( m_pBrowser, pStream );
pStream->Release();
}
GlobalFree( hHTMLText );
}
}
pUnkDisp->Release();
}
pUnkBrowser->Release();
}


}
// -HELPER FUNCTION LOAD WEB OC FROM STREAM

HRESULT LoadWebOCFromStream(IWebBrowser2* pWebBrowser, IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

// Retrieve the document object.
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) )
{
// Query for IPersistStreamInit.
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,
(void**)&pPersistStreamInit );
if ( SUCCEEDED(hr) )
{
// Initialize the document.
hr = pPersistStreamInit->InitNew();
if ( SUCCEEDED(hr) )
{
// Load the contents of the stream.
hr = pPersistStreamInit->Load( pStream );
}
pPersistStreamInit->Release();
}
}
}

-----------end code-----

Edward O. Warren <eowarren@alltel.net>  
0
 

Author Comment

by:tomcorcoran
ID: 6185403
Alex,

Thanks for the mail. I read that post prior to posting my question. I don't want to do that hack all I want to do is to get OnDownlaodComplete to fire when the TCppWebBrowser is created dynamically. Cane you help me?

Thanks, Tom.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:tomcorcoran
ID: 6227119
No one could help :-(
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7087986
Hi tomcorcoran,
You've requested to delete this question, but its status has remained as 'Pending Delete' because one or more comments have been added.  Normally, the only way to fully delete such a Question is to post a message to Community Support and ask for assistance.

EE is making a one-time database sweep to purge the Pending Delete Questions automatically.  During this sweep:

    tomcorcoran -- To allow the deletion to proceed:  Do nothing.
    EXPERTS -- Please DON'T POST a comment except to contest this deletion.

In the future, please refer to http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp#8 for instruction on deleting questions.

DanRollins -- EE database cleanup volunteer
0
 
LVL 11

Expert Comment

by:griessh
ID: 7106142
PAQ & refund

======
Werner
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 7111831
Thanks, Werner, 50 points refunded, item closed.  PAQd at zero points.
Moondancer - EE Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now