Solved

C++Builder TCppWebBrowser and dynamically linked OnDocumentComplete event

Posted on 2001-06-12
8
2,122 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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
 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does std::atomic give me? 7 124
Fully specialized class template function 21 136
PDF library for Delphi 2 121
Unable to start eclipse ? 17 141
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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