Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TCppWebBrowser print functionaliy

176 views
Skip to first unread message

Luca Picello

unread,
Oct 11, 2005, 4:04:49 PM10/11/05
to
How to print an HTML in my application in C++ Builder ?
The only help I've found googling and in the online help is:

>Look at the TCppWebBrowser help for the ExecWB method. It allows you to
>pass in a command ID (one of which is for print) to execute browser
>commands.

Any further?
Thank you,

Luca

Hans Galema

unread,
Oct 11, 2005, 5:07:52 PM10/11/05
to
Luca Picello wrote:
> How to print an HTML in my application in C++ Builder ?

> >Look at the TCppWebBrowser help for the ExecWB method. It allows you to


> >pass in a command ID (one of which is for print) to execute browser
> >commands.

// // Shdocvw_tlb.h

CppWebBrowser1->ExecWB(Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_PROMPTUSER);
or

CppWebBrowser1->ExecWB(Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER);

Hans.

Luca Picello

unread,
Oct 15, 2005, 2:22:57 PM10/15/05
to Hans Galema
Hello Hans and thank you for answer.
I did find some other good pieces of code however they do not work >:(

// DO NOTHING
CppWebBrowser1->ExecWB(::OLECMDID_PRINT, ::OLECMDEXECOPT_DONTPROMPTUSER);


// FROM http://www.codeproject.com/miscctrl/wbp.asp
// PRINT A BLANK PAGE

// Verify the WebBrowser control is valid.

LPDISPATCH lpDispApp = CppWebBrowser1->Application;
if(lpDispApp)
{
// Get the HTMLDocument interface.
LPDISPATCH lpDispDoc = CppWebBrowser1->Document;
if (lpDispDoc != NULL)
{
// Get the IOleCommandTarget interface so that
// we can dispatch the command.
LPOLECOMMANDTARGET lpTarget = NULL;
if (SUCCEEDED(lpDispDoc->
QueryInterface(IID_IOleCommandTarget,
(LPVOID*) &lpTarget)))
{
// Execute the print preview command. The
// control will handle the print preview
// GUI.
// OLECMDID_PRINTPREVIEW is defined in
// "docobj.h".
lpTarget->Exec(NULL,
::OLECMDID_PRINTPREVIEW, 0, NULL, NULL);
lpTarget->Release();
}
lpDispDoc->Release();
}
lpDispApp->Release();
}

// ----------------------------------

// PRINT A BLANK PAGE
TPrinter* Prntr = Printer();
Prntr->BeginDoc();
CppWebBrowser1->PaintTo( Prntr->Handle, 0,0);
Prntr->EndDoc();
//------------------------


compiling the whole project at http://www.codeproject.com/miscctrl/wbp.asp with
Visual Studio 2003 it runs perfectly. Then I tried to create a DLL to import
functions capabilities to my borland application. Unfortunately I've got no
results :-(


Any help is REALLY appreciated


Luca

Hans Galema

unread,
Oct 15, 2005, 3:30:07 PM10/15/05
to
Luca Picello wrote:

> I did find some other good pieces of code however they do not work >:(

Then use the code that I suggested.

Hans.

Luca Picello

unread,
Oct 15, 2005, 9:17:24 PM10/15/05
to Hans Galema
unfortunately code you suggested does not work

Luca

Hans Galema

unread,
Oct 16, 2005, 5:04:30 AM10/16/05
to
Luca Picello wrote:
> unfortunately code you suggested does not work

Ah... Strange. Here it works ok. What are the problems ?
Errormessages ?

Hans.

Luca Picello

unread,
Oct 16, 2005, 7:19:05 AM10/16/05
to Hans Galema
No error messages.

Using:

TVariant outvar;
CppWebBrowser1->ExecWB(OLECMDID_PRINT, 0, NULL, outvar);

I'd like to understand outvar's meaning but there is no documentation.

I'm using Borland C++ Builder 6 with service pack 4 on WindowsXP pro (with
latest updates).
I believe to a bug not in my code... >:(
What environment do you use?

thanks,
Luca

gizmo

unread,
Oct 17, 2005, 5:16:08 AM10/17/05
to

The Small example. All successfully work, but does not print footline(only headline). Why, I do not know. Where there is mistake?

Code:
void __fastcall TForm1::PrintButtonClick(TObject *Sender)
{
SAFEARRAYBOUND psabBounds[1];
SAFEARRAY *psaHeadFoot;

// Initialize header and footer parameters to send to ExecWB().
psabBounds[0].lLbound = 0;
psabBounds[0].cElements = 2;
psaHeadFoot = SafeArrayCreate(VT_VARIANT, 1, psabBounds);
VARIANT vHeadStr, vFootStr;
long rgIndices;
VariantInit(&vHeadStr);
VariantInit(&vFootStr);

// Argument 1: Header
vHeadStr.vt = VT_BSTR;
vHeadStr.bstrVal = SysAllocString(L"This is my header string.");

// Argument 2: Footer
vFootStr.vt = VT_BSTR;
vFootStr.bstrVal = SysAllocString(L"This is my footer string.");

rgIndices = 0;
SafeArrayPutElement(psaHeadFoot, &rgIndices, static_cast<void *>(&vHeadStr));
rgIndices = 1;
SafeArrayPutElement(psaHeadFoot, &rgIndices, static_cast<void *>(&vFootStr));

// SAFEARRAY must be passed ByRef or else MSHTML transforms it into NULL.
TVariant vArg;
VariantInit(&vArg);
vArg.vt = VT_ARRAY | VT_BYREF;
vArg.parray = psaHeadFoot;

WB->ExecWB(Shdocvw_tlb::OLECMDID_PRINT, Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER, &vArg, NULL);

VariantClear(&vHeadStr);
VariantClear(&vFootStr);
if (psaHeadFoot) {
SafeArrayDestroy(psaHeadFoot);
}
}

Luca Picello

unread,
Oct 17, 2005, 3:33:57 PM10/17/05
to gizmo
Thank you gimzo but there have to be something not working properly in my system.
With copy and paste of your source it does not work too.
No pages are printed :-(
Maybe there are some registry settings to check.

luca

gizmo

unread,
Oct 18, 2005, 4:49:29 AM10/18/05
to

Luca Picello <luca.p...@gmail.com> wrote:
>Thank you gimzo but there have to be something not working properly in my system.
>With copy and paste of your source it does not work too.
>No pages are printed :-(
>Maybe there are some registry settings to check.
>
>luca

MSDN cut:
Microsoft Internet Explorer (Programming) versions 4.0, 4.01, 4.01 SP1, 4.01 SP2, 5, 5.01, 5.5

I tried following combinations:
Win98 + IE5, Win2000 + IE6 - prints...


Mark Guerrieri

unread,
Oct 18, 2005, 10:57:27 AM10/18/05
to
Try calling OleInitialize prior to calling the Exec method...

Mark

"gizmo" <_gi...@mail.ru> wrote in message
news:4354b719$1...@newsgroups.borland.com...

Luca Picello

unread,
Oct 18, 2005, 1:41:02 PM10/18/05
to Mark Guerrieri
with:

OleInitialize(NULL);
CppWebBrowser1->ExecWB(Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER, &vArg, NULL);

but no news...

luca

Luca Picello

unread,
Oct 19, 2005, 7:04:40 AM10/19/05
to Mark Guerrieri
FOLKS I'VE FOUND THE PROBLEM!!!
it is related to the webpage I am trying to load.
using any website (like www.microsoft.com) it works perfectly.

thank you all for your good suggestions

Luca

Luca Picello

unread,
Oct 20, 2005, 3:11:43 PM10/20/05
to Mark Guerrieri
Sometime it works and sometimes it does not...
nobody else has same problem? thanks

luca

Luca Picello

unread,
Oct 20, 2005, 3:24:44 PM10/20/05
to Luca Picello, Mark Guerrieri
It never works with an html file from disk.
It does not print. just update the page in CppWebBrowser1 control.
Neither calling ChDir before.

ChDir( "z:/report/" );
CppWebBrowser1->Navigate("file://z:\\report\\report2.html");

---------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<h1>This is a demonstration</h1>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD></TD>
<TD>Studio dentistico: Dentisti sdentati</TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD><IMG style="WIDTH: 472px; HEIGHT: 256px" height="256" alt=""
src="bhteethl.jpg" width="472"
align="middle"></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD>Paziente: Dante Storto</TD>
<TD></TD>
</TR>
</TABLE>
<P>&nbsp;</P>
</body>
</html>

Hans Galema

unread,
Oct 21, 2005, 7:22:28 AM10/21/05
to
Luca Picello wrote:
> It never works with an html file from disk.
> It does not print. just update the page in CppWebBrowser1 control.
> Neither calling ChDir before.

What would ChDir() have to do with printing ?

> ChDir( "z:/report/" );
> CppWebBrowser1->Navigate("file://z:\\report\\report2.html");

Why would the contents of the html file have to do something with printing?

Hans.

Alan Bellingham

unread,
Oct 21, 2005, 8:18:14 AM10/21/05
to
Luca Picello <luca.p...@gmail.com> wrote:

>It never works with an html file from disk.
>It does not print. just update the page in CppWebBrowser1 control.
>Neither calling ChDir before.
>
>ChDir( "z:/report/" );
>CppWebBrowser1->Navigate("file://z:\\report\\report2.html");

What happens when you do proper forward slashes?

CppWebBrowser1->Navigate("file://z:/report/report2.html");

Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK

Martin Rothschink

unread,
Oct 21, 2005, 12:10:46 PM10/21/05
to
Luca Picello wrote:
> It never works with an html file from disk.
> It does not print. just update the page in CppWebBrowser1 control.
> Neither calling ChDir before.
>
> ChDir( "z:/report/" );
> CppWebBrowser1->Navigate(file://z:\\report\\report2.html);

Luca, you need to wait for the Document complete event after any call to
navigate!

void __fastcall TmainForm::CppWebBrowser1DocumentComplete(TObject *Sender,
LPDISPATCH pDisp, VARIANT *URL)
{
if (Printing)
{
CppWebBrowser1->ExecWB( Shdocvw_tlb::OLECMDID_PRINT,
Shdocvw_tlb::OLECMDEXECOPT_DONTPROMPTUSER);
}
}

--
Regards
Martin


Luca Picello

unread,
Oct 21, 2005, 2:56:59 PM10/21/05
to Martin Rothschink
Hey it ****always WORKS!!!!****
My error was not using CppWebBrowser1DocumentComplete method but:

CppWebBrowser1->Navigate(file://z:\\report\\report2.html);

while(CppWebBrowser1->Busy)
Application->ProcessMessages();

but now I know it is obviously wrong!
Thank you very and very much Martin.

Luca

Luca Picello

unread,
Oct 23, 2005, 4:37:09 AM10/23/05
to Luca Picello, Martin Rothschink
Now that I have CppWebBrowser1 perfectly working, I'd like to set-up my printer
and store its configuration in the registry.
Or in any way the printer configuration can be stored/restored from the application.
Any suggestion is really appreciated

Thank you,
Luca

Martin Rothschink

unread,
Oct 25, 2005, 2:39:07 AM10/25/05
to

Have a look at the keys in \\Software\\Microsoft\\Internet
Explorer\\PageSetup. I usually save these settings, apply what I need for my
app, then restore the old values.

--
Regards
Martin Rothschink


Luca Picello

unread,
Oct 26, 2005, 12:31:46 PM10/26/05
to Martin Rothschink
they are global setting for the system.
are there no way to get/set it only for the application?
thanks

luca

Alan Bellingham

unread,
Oct 26, 2005, 12:49:33 PM10/26/05
to
"Martin Rothschink" <martin.r...@axonet.de> wrote:

>Have a look at the keys in \\Software\\Microsoft\\Internet
>Explorer\\PageSetup. I usually save these settings, apply what I need for my
>app, then restore the old values.

And if your user is running any other application - well, good luck to
them.

I really hope there's a better solution than this.

Martin Rothschink

unread,
Oct 27, 2005, 2:06:44 AM10/27/05
to
Alan Bellingham wrote:
> "Martin Rothschink" <martin.r...@axonet.de> wrote:
>
>> Have a look at the keys in \\Software\\Microsoft\\Internet
>> Explorer\\PageSetup. I usually save these settings, apply what I
>> need for my app, then restore the old values.
>
> And if your user is running any other application - well, good luck to
> them.

Yes, that may be a problem. Actually I do this after my user clicks on the
print button:

... OnPrintClick()
{
SaveOldRegSettings();
ApplyMySettings();
Print();
RestoreOldSettings();
}

So the chance for a collision of two apps is very small.

If anybody knows a better way, please let me know.

--
Regards
Martin Rothschink


Martin Rothschink

unread,
Oct 27, 2005, 2:09:57 AM10/27/05
to
Luca Picello wrote:
> they are global setting for the system.
> are there no way to get/set it only for the application?
> thanks

No, these are per user global settings for Internet Explorer. The key is in
HKEY_CURRENT_USER. I don't know of any other way and it worked well for my
application.

--
Regards
Martin Rothschink


gizmo

unread,
Oct 27, 2005, 4:56:06 AM10/27/05
to

Luca Picello <luca.p...@gmail.com> wrote:
>they are global setting for the system.
>are there no way to get/set it only for the application?
>thanks

The first way:
Show the standard window of the dialogue, install the global hook, install their own parameters, move dialog off screen and print.

The second way:
PrintTemplates

Luca Picello

unread,
Oct 27, 2005, 6:55:58 AM10/27/05
to gizmo
could you please explain better?
thank you

gizmo

unread,
Oct 28, 2005, 1:53:20 AM10/28/05
to
0 new messages