Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C++Builder TCppWebBrowser and dynamically linked OnDocumentComplete event

Posted on 2001-06-12
8
Medium Priority
?
2,242 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
[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
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
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!

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

636 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