Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create screen shot (image) of hidden Internet Explorer window

Posted on 2002-04-07
4
Medium Priority
?
233 Views
Last Modified: 2010-04-04
Functionality:
I want to present the user with a screen shot (small image) of an url.

Example:
Latest version of Copernic has this 'Document Preview' function.

Method (I think):
Open the url with the IE explorer component in a hidden window, make a screen shot (image) to a file, resample the image, show the image.

Challenge:
- How to make a screen shot (image) of a non visible window?

Any suggestions?
0
Comment
Question by:Dik Bots
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6924293
just tried the BitBlt but it doesn't work
it captures just the area where the window should be
hope I find something on this ... really wanna know :)
0
 
LVL 9

Accepted Solution

by:
ginsonic earned 400 total points
ID: 6924607
I suggest to use TWebBrowser instead Internet Explorer .
Attention ! Don't set visible property to false . just display the TWEBBrowser outside your form . Alike Left:=5000.
I use this code and work perfect.


unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, activeX,
 Dialogs, ExtCtrls, StdCtrls, OleCtrls, SHDocVw_TLB;

type
 TForm1 = class(TForm)
   WebBrowser1: TWebBrowser;
   Edit1: TEdit;
   Button1: TButton;
   Button2: TButton;
   Image1: TImage;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
    webBrowser1.navigate(edit1.text);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  ViewObject: IViewObject;
  sourceDrawRect: TRect;
begin
    if webBrowser1.Document <> nil then
    try
       webBrowser1.Document.QueryInterface(IViewObject, ViewObject);
       if ViewObject <> nil then
       try
          sourceDrawRect := Rect(0, 0, Image1.Width, Image1.Height);
          ViewObject.Draw(DVASPECT_CONTENT, 1, nil, nil, Self.Handle,
          image1.Canvas.Handle, @sourceDrawRect, nil, nil, 0);
       finally
              ViewObject._Release;
       end;
       image1.Refresh;
    except
    end;
end;

end.
0
 

Author Comment

by:Dik Bots
ID: 7090094
Is this code also usable for regular Forms?

I now use this code:

tempHDC := GetWindowDC(frmStats.Handle);
with BMP do
begin
  PixelFormat := pf32bit;
  Width := frmStats.Width;
  Height := frmStats.Height;
  BitBlt(Canvas.Handle,0,0,Width,Height,tempHDC,0,0,SRCCopy);
end;
ReleaseDC(frmStats.Handle,tempHDC);

If the form is 'not visible' (for example left = 5000) it will give an empty image.

A regular TForm doesn't seem to have the QueryInterface method...
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7090179
Don't work for TForm :(
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Screencast - Getting to Know the Pipeline

885 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