Article View: borland.public.cppbuilder.internet.web
Article #255Re: Converting HTML page from TCppWebBrowser into Image
From: Trevor Keegan
Date: Tue, 06 Feb 2007 23:36
Date: Tue, 06 Feb 2007 23:36
104 lines
4127 bytes
4127 bytes
Hi Hans,
Sure....it is the least that I can do :-D Here is is:
void __fastcall TForm1::btnSaveScreenClick(TObject *Sender)
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface( IID_IHTMLDocument2,
(LPVOID*)&Doc );
if( Doc )
{
IHTMLElement * pBodyElement;
Doc->get_body( &pBodyElement );
if( pBodyElement )
{
IHTMLBodyElement * pBody = 0;
pBodyElement->QueryInterface( IID_IHTMLBodyElement, (void**)&pBody );
if( pBody )
{
//Hide 3D border
IHTMLStyle * pStyle;
pBodyElement->get_style( &pStyle );
if( pStyle )
{
pStyle->put_borderStyle( WideString( "none" ) );
pStyle->Release();
}
//Hide Scroll Bars
pBody->put_scroll( WideString( "no" ) );
//Resize the browser component to the size of the HTML content
IHTMLElement2 * pBodyElement2;
pBody->QueryInterface( IID_IHTMLElement2, (void **)&pBodyElement2 );
if( pBodyElement2 )
{
long iScrollWidth = 0;
long iScrollHeight = 0;
pBodyElement2->get_scrollWidth( &iScrollWidth );
pBodyElement2->get_scrollHeight( &iScrollHeight );
try
{
//Allow the browser window to be resized so that we can get the
whole image
CppWebBrowser1->Align = alNone;
CppWebBrowser1->Width = iScrollWidth;
CppWebBrowser1->Height = iScrollHeight;
pBodyElement2->Release();
IViewObject * pViewObject;
Doc->QueryInterface( IID_IViewObject, ( void ** )&pViewObject );
if( pViewObject )
{
Graphics::TBitmap * Bitmap = new Graphics::TBitmap();
if( Bitmap )
{
RECTL rcSource = {0,0, iScrollWidth, iScrollHeight };
Bitmap->Width = iScrollWidth;
Bitmap->Height = iScrollHeight;
pViewObject->Draw( DVASPECT_CONTENT, 1, NULL, NULL, Handle,
Bitmap->Canvas->Handle, &rcSource, NULL, NULL, 0 );
TJPEGImage * JPEG = new TJPEGImage;
if( JPEG )
{
try
{
JPEG->Assign( Bitmap );
JPEG->SaveToFile( "c:\\Rubbish\\test.jpg" );
}
__finally
{
delete JPEG;
}
}
delete Bitmap;
}
pViewObject->Release();
}
}
__finally
{
//Set the browser back to the original size
CppWebBrowser1->Align = alClient;
}
}
pBody->Release();
}
pBodyElement->Release();
}
Doc->Release();
}
}
Regards
Trevor Keegan
Technical Details
Message-ID:
<45c910ff$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45c7e3f6@newsgroups.borland.com> <45c7ea27$1@newsgroups.borland.com> <45c7f506@newsgroups.borland.com> <45c80675$1@newsgroups.borland.com> <45c85eb5$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,4384ebb9896c72c9 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Trevor Keegan" <tkeegan@ealink.com> From: "Trevor Keegan" <tkeegan@ealink.com> Newsgroups: borland.public.cppbuilder.internet.web References: <45c7e3f6@newsgroups.borland.com> <45c7ea27$1@newsgroups.borland.com> <45c7f506@newsgroups.borland.com> <45c80675$1@newsgroups.borland.com> <45c85eb5$1@newsgroups.borland.com> Subject: Re: Converting HTML page from TCppWebBrowser into Image Date: Wed, 7 Feb 2007 07:36:29 +0800 Lines: 106 Organization: EA-Link System Sdn Bhd X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 219.95.95.11 Message-ID: <45c910ff$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1170804991 219.95.95.11 (6 Feb 2007 15:36:31 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail