home *** CD-ROM | disk | FTP | other *** search
- { Project ScrCap.DPR Delphi 2.0 Demos
-
- Description:- ScrCap.Dpr Project:-
-
- Demonstrates the use of:
-
- 1) 'Hdc'
- 2) 'BitBlt'
- 3) 'TImage'
- 4) 'BitmaptoDib'
- 5) API calls - GetDC
-
- Date of Origin: 18/04/96
- Original Author: Andrew Hutchison
- Modification History:
-
- Date Person Change
- ----------------------------------------------------
- 18/04/96 A Hutchison Created
-
- (c) Copyright Media Architects Inc. 1996.
- All rights reserved. No part of this program may be
- photocopied, reproduced, translated to another programming
- language or transported to any computer system without the
- prior written consent of Media Architects Inc.}
-
- unit UScrCap;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Buttons, OleCtrls, ImageKnife32, ExtCtrls, Menus;
-
- type
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Exit1: TMenuItem;
- Bevel1: TBevel;
- Picbuf1: TPicbuf;
- CapturePicbuf: TSpeedButton;
- CaptureTImage: TSpeedButton;
- Bevel2: TBevel;
- ScrollBox1: TScrollBox;
- Image: TImage;
- procedure CapturePicbufClick(Sender: TObject);
- procedure CaptureTImageClick(Sender: TObject);
- procedure Exit1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
-
- {--------------------------------------------------------------------------------}
- {Capture the Screen to the Picbuf Control - May Not be Supported under early OCX}
- procedure TForm1.CapturePicbufClick(Sender: TObject);
- var
- hDC,hmemdc,hbitmap,holdbitmap:Integer;
- begin
- hDC := CreateDC('DISPLAY', nil, nil, nil);
- hbitmap := CreateCompatibleBitmap(hDC, 200, 200);
- hmemdc := CreateCompatibleDC(hDC);
- holdbitmap := SelectObject(hmemdc, hbitmap);
- BitBlt(hmemdc, 0, 0, 200, 200, hDC, 0, 0, SRCCOPY);
- SelectObject(hmemdc, holdbitmap);
- Picbuf1.BitmapToDib(hbitmap);
- DeleteObject(hbitmap);
- DeleteDC(hDC);
- DeleteDC(hmemdc);
- end;
-
-
- {--------------------------------------------------------------------------------}
- {Capture the Screen to a TImage Component. Note the Use of 'GETDC'. If you pass
- '0' then the Device Context of your Screen is returned. If you wish to Capture
- a Specific Window just pass that Windows Hwnd}
- procedure TForm1.CaptureTImageClick(Sender: TObject);
- var
- HDC:THandle; {Handle to Bitmap}
- begin
- Image.Picture.Bitmap.Width:=Screen.Width; {Set Bitmap to Screen Dimensions}
- Image.Picture.Bitmap.Height:=Screen.Height; {Set Bitmap to Screen Dimensions}
- HDC := GetDc(0); {Get Handle to DC of Screen Object}
- {Use 'BitBlt' to Copy ScreenDC to Timage's Bitmap.Canvas}
- BitBlt(Image.Picture.Bitmap.Canvas.Handle, 0, 0,Screen.Width, Screen.Height, HDC,
- 0, 0, SRCCOPY);
- Image.refresh; {Refresh Image to Paint in Result}
- DeleteDC(HDC); {DeleteDC}
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Exit Application}
- procedure TForm1.Exit1Click(Sender: TObject);
- begin
- Halt;
- end;
-
-
- {-------------------------------------------------------------------------------}
- {Defaults}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.HintPause:=10;
- Application.HintColor:=clAqua;
- end;
-
- end.
-