(7) Crawl the form of the icon (ICON)
Create a new Form3, save as Capture3.pas. Set the four properties of the attribute BorderIcons to false.
BorderStyle is set to bsNone, FormStyle is set to fsStayOnTop.
One private variable: fDragging:Boolean; Two public variables: fRect:TRect,fBmp:TBitmap;
unit Capture3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm3 = class(TForm)
PRocedure FormCreate(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);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
Private
fDragging:Boolean;
public
fRect:TRect;
fBmp:TBitmap;
end;
var
Form3: TForm3;
Implementation
{$R *.dfm}
//Create a new custom cursor CURSOR_2 and place it in Capture3.res resource
//In the file, there is a white rectangular border of 32*32 to indicate the range of the capture.
procedure TForm3.FormCreate(Sender: TObject);
var aDC:HDC;
const crBox = -19;
Begin
Screen.Cursors[crBox]:=LoadCursor(hInstance,'CURSOR_2');
Cursor := crBox;
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 TForm3.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Begin
if mbLeft = Button then begin
fDragging := true;
SetRect(fRect,X,Y,X+32,Y+32);
Canvas.DrawFocusRect(fRect);
end;
end;
procedure TForm3.FormMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
Begin
if fDragging then begin
Canvas.DrawFocusRect(fRect);
fRect.Left := X ;
fRect.Top := Y ;
fRect.Right:= X+32;
fRect.Bottom:=Y+32;
Canvas.DrawFocusRect(fRect);
end;
end;
procedure TForm3.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Begin
ModalResult:=mrOK;
end;
procedure TForm3.FormActivate(Sender: TObject);
const crHand=-18;
Begin
Screen.Cursors[crHand]:=LoadCursor(hInstance,pChar('CURSOR_1'));
Cursor:=crHand;
end;
procedure TForm3.FormDestroy(Sender: TObject);
Begin
fBmp.Free;
Screen.Cursor := crDefault;
end;
procedure TForm3.FormPaint(Sender: TObject);
Begin
Canvas.Draw(0,0,fBmp);
end;
end.