WEB开发网
开发学院软件开发Delphi Delphi图象截取编程示例(7) 阅读

Delphi图象截取编程示例(7)

 2006-02-04 13:52:25 来源:WEB开发网   
核心提示: (七)抓取窗体或控件图片窗体创建一个新的Form2,保存为Capture2.pas,Delphi图象截取编程示例(7),设置属性BorderIcons的四个属性为false.BorderStyle设为bsNone,FormStyle设为fsStayOnTop.两个公共变量:fRect:TRect,fBmp:TBitm
 

(七)抓取窗体或控件图片窗体
创建一个新的Form2,保存为Capture2.pas。设置属性BorderIcons的四个属性为false.
BorderStyle设为bsNone,FormStyle设为fsStayOnTop.
两个公共变量:fRect:TRect,fBmp:TBitmap;

unit Capture2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm2 = class(TForm)
   PRocedure FormCreate(Sender: TObject);
   procedure FormActivate(Sender: TObject);
   procedure FormDestroy(Sender: TObject);
   procedure FormPaint(Sender: TObject);
   procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  private
   { Private declarations }
  public
   fRect:TRect;
   fBmp:TBitmap;
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

//创建一个新的自定义光标CURSOR_1,放在Capture2.res资源
//文件中.是32*32的白色矩形边框,用来指示抓图的范围.

procedure TForm2.FormCreate(Sender: TObject);
var aDC:HDC;
const crHand = -18;
begin
  Screen.Cursors[crHand]:=LoadCursor(hInstance,'CURSOR_1');
  Cursor:=crHand;
  fBmp:= TBitmap.Create ;
  fBmp.Width := Screen.Width ;
  fBmp.Height:= Screen.Height ;
  aDC := GetDC(0);
  BitBlt(fBmp.Canvas.Handle,0,0,Screen.Width,Screen.Height,aDC,0,0,srcCopy);
  ReleaseDC(0,aDC);
  SetBounds(0,0,Screen.Width,Screen.Height);
end;

procedure TForm2.FormActivate(Sender: TObject);
const crHand=-18;
begin
  Screen.Cursors[crHand]:=LoadCursor(hInstance,pChar('CURSOR_1'));
  Cursor:=crHand;
end;

procedure TForm2.FormDestroy(Sender: TObject);
begin
  fBmp.Free;
  Screen.Cursor := crDefault;
end;

procedure TForm2.FormPaint(Sender: TObject);
begin
  Canvas.Draw(0,0,fBmp);
end;

procedure TForm2.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ModalResult:=mrOK;
end;

end.

Tags:Delphi 图象 截取

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接