Delphi图象截取编程示例(6)
2006-02-04 13:52:23 来源:WEB开发网(六)区域抓图窗体
创建一个新的Form1,保存为Capture1.pas。设置属性BorderIcons的四个属性为false.
BorderStyle设为bsNone,Cursor设为crCross,FormStyle设为fsStayOnTop.
添加一个私有变量:fDragging:Boolean;两个公共变量:fRect:TRect,fBmp:TBitmap;
Form1的作用:在区域抓图时创建,抓图后消失.
unit Capture1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
PRocedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
fDragging:Boolean;
public
fRect:TRect;
fBmp:TBitmap;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var aDC:HDC; //设备描述表的句柄
begin
fBmp := TBitmap.Create ;
fBmp.Width := Screen.Width ;
fBmp.Height:= Screen.Height;
aDC := GetDC(0); //获取一个窗口的设备描述表的句柄,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 TForm1.FormDestroy(Sender: TObject);
begin
fBmp.Free ;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Draw(0,0,fBmp); //将图形绘制到 Canvas
end;
//如果按下鼠标左键,用SetRect设置矩形fRect,使其只是一个点。
//用 DrawFocusRect 把这个矩形画出来
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button=mbLeft then begin
fDragging:=true;
SetRect(fRect,x,y,x,y);
Canvas.DrawFocusRect(fRect);
end;
end;
//鼠标移动时, 判断是否在画图中(按下鼠标左键),DrawFocusRect重新设置矩形
//使右下角为当前鼠标位置,在调用DrawFocusRect画出矩形
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if fDragging then begin
Canvas.DrawFocusRect(fRect);
fRect.Right := X ;
fRect.Bottom:= Y ;
Canvas.DrawFocusRect(fRect);
end;
end;
//判断是否在画图中(按下鼠标左键),鼠标弹起时,
//DrawFocusRect重新设置矩形 .关闭窗体
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if fDragging then begin
Canvas.DrawFocusRect(fRect);
fDragging:=false;
end;
ModalResult:=mrOK; //关闭窗体
end;
end.
- ››Delphi实现把10进制转换成16进制的函数进制转化
- ››Delphi中将字符串按给定字符分隔(似split函数功能...
- ››Delphi 动态创建窗体,锁定窗口赋值
- ››Delphi 与 VC 共享接口和对象
- ››Delphi图像处理 -- 表面模糊
- ››Delphi之多线程实例
- ››Delphi SelectSingleNode的使用 根据节点属性获取...
- ››Delphi接口详述
- ››delphi 远程调试
- ››Delphi与DirectX之DelphiX(34): TDIB.Lightness()...
- ››Delphi Application.MessageBox详解
- ››Delphi只能运行一个程序实例的两种方法
更多精彩
赞助商链接