Article View: borland.public.cppbuilder.internet.web
Article #1672Re: TCppWebBrowser and CaptureThumbnail
From: Remy Lebeau (TeamB)
Date: Tue, 24 Aug 2004 19:36
Date: Tue, 24 Aug 2004 19:36
152 lines
6002 bytes
6002 bytes
"Lapo Guidi" <lapoguidi@inwind.it> wrote in message
news:412b4ebf@newsgroups.borland.com...
> In the first I got an error because IHTMLDocument2
> seems don't have a Body property.
Use its get_body() method for that.
> ------- first code ----------
Try this code:
#include <utilcls.h>
#include <memory>
TComInterface< IHTMLDocument2> Doc;
if(
SUCCEEDED(CppWebBrowser->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc)) )
{
TComInterface<IHTMLElement> Body;
if( SUCCEEDED(Doc->get_body(&Body)) )
{
TComInterface<IHTMLBodyElement> BodyElement;
if( SUCCEEDED(Body->QueryInterface(IID_IHTMLBodyElement,
(LPVOID*)&BodyElement)) )
{
BodyElement->put_noWrap(VARIANT_TRUE);
// hide scrollbars
TComInterface<IHTMLStyle> Style;
if( SUCCEEDED(Body->get_style(&Style)) )
Style->put_borderStyle(WideString("none"));
BodyElement->put_scroll(WideString("no"));
TComInterface<IHTMLElement2> BodyElement2;
if( SUCCEEDED(Body->QueryInterface(IID_IHTMLElement2,
(LPVOID*)&BodyElement2)) )
{
long ScrollWidth = 0;
BodyElement2->get_scrollWidth(&ScrollWidth);
long ScrollHeight = 0;
BodyElement2->get_scrollHeight(&ScrollHeight);
CppWebBrowser1->Width = ScrollWidth;
CppWebBrowser1->Height = ScrollHeight;
TComInterface<IViewObject> ViewObject;
CppWebBrowser->Document->QueryInterface(IID_IViewObject,
(LPVOID*)&ViewObject);
if( ViewObject )
{
std::auto_ptr<Graphics::TBitmap> Source(new
Graphics::TBitmap);
Source->Width = CppWebBrowser1->Width;
Source->Height = CppWebBrowser->Height;
RECT SourceRect = Rect(0, 0, ScrollWidth,
ScrollHeight);
if( SUCCEEDED(ViewObject->Draw(DVASPECT_CONTENT, 1,
NULL, NULL, this->Handle, Source->Canvas->Handle, &SourceRect, NULL, NULL,
0)) )
Source->SaveToFile("c:\\somefile.bmp");
}
}
}
}
}
> -------- second code ----------------
Try this code:
#include <utilcls.h>
#include <memory>
TComInterface<IHTMLDocument2> Doc;
if(
SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc)) )
{
int tmpX = CppWebBrowser1->Width;
int tmpY = CppWebBrowser1->Height;
((TControl*)CppWebBrowser1)->Visible = false;
TComInterface<IHTMLWindow2> ParentWindow;
if( SUCCEEDED(Doc->get_ParentWindow(&ParentWindow)) )
{
TComInterface<IHTMLScreen> HTMLScreen;
if( SUCCEEDED(ParentWindow->get_screen(&HTMLScreen)) )
{
long width = 0;
HTMLScreen->get_width(&width);
long height = 0;
HTMLScreen->get_width(&height);
CppWebBrowser1->Width = width;
CppWebBrowser1->Height = height;
GenerateJPEGfromBrowser(CppWebBrowser1->ControlInterface,
"c:\\test.jpg", width, height, width, height);
}
}
CppWebBrowser1->Width = tmpX;
CppWebBrowser1->Height = tmpY;
((TControl*)CppWebBrowser1)->Visible = true;
}
void __fastcall GenerateJPEGfromBrowser(IWebBrowser2* Browser, const
AnsiString &jpegFQFilename, int srcWidth, int srcHeight, int tarWidth, int
tarHeight)
{
try
{
TComInterface<IViewObject> ViewObject;
Browser->QueryInterface(IID_IViewObject, (LPVOID*)&ViewObject);
if( ViewObject )
{
std::auto_ptr<Graphics::TBitmap> Source(new
Graphics::TBitmap);
Source->Width = srcWidth;
Source->Height = srcHeight;
RECT SourceRect = Rect(0, 0, srcWidth, srcHeight);
OLECHECK(ViewObject->Draw(DVASPECT_CONTENT, 1, NULL, NULL,
Form1->Handle, Source->Canvas->Handle, &SourceRect, NULL, NULL, 0));
// Resize the src bitmap to the target bitmap
std::auto_ptr<Graphics::TBitmap> Target(new
Graphics::TBitmap);
Target->Width = tarWidth;
Target->Height = tarHeight;
Target->Canvas->StretchDraw(Rect(0, 0, tarWidth, tarHeight),
Source);
// Create a JPEG from the Bitmap and save it
std::auto_ptr<TJPEGImage> Jpeg(new TJPEGImage);
Jpeg->Assign(Target);
Jpeg->SaveToFile(jpegFQFilename);
}
}
catch(const Exception &) {}
catch(...) {}
}
Gambit
Technical Details
Message-ID:
<412b9867$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<412a9c86@newsgroups.borland.com> <412aedc2@newsgroups.borland.com> <412b4ebf@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,9c51eda80d523333 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.internet.web References: <412a9c86@newsgroups.borland.com> <412aedc2@newsgroups.borland.com> <412b4ebf@newsgroups.borland.com> Subject: Re: TCppWebBrowser and CaptureThumbnail Date: Tue, 24 Aug 2004 12:36:12 -0700 Lines: 154 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <412b9867$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1093376103 68.69.17.41 (24 Aug 2004 12:35:03 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail