(VI) TMainForm's (picture) Action event
1) Full screen capture
[Capture Desktop] Action Event
PRocedure TMainForm.cptDesktopExecute(Sender: TObject);
Begin
inc(CaptureNum,1);
application.Minimize; //Form minimization
Delay(500); //Minimum delay, in order to capture the image in full screen, do not grab yourself into the image
FileName:='Capture'+IntToStr(CaptureNum)+'.bmp';
FileName:=DefaultDirectory+FileName;
CreateMDIChild(FileName,true);
StatusBar.SimpleText := FileName;
with ActiveMDIChild as TMDIChild do begin
Image1.Picture.Bitmap := CaptureScreen; //Capture pictures
HorzScrollBar.Range := Image1.Picture.Width;
VertScrollBar.Range := Image1.Picture.Height;
end;
Child.Image1.Hint := 'Height:'+intToStr(child.Image1.Picture.Height)+'pixels'
+ ' Width:'+intToStr(child.Image1.Picture.Width)+'pixels';
application.Restore ;
end;
2) Area capture
To capture area images, a new Form1 is to use, see "Delphi Image Intercept Programming Example (6)".
Add Capture1 in the uses of the Main unit implementation.
Add a private process in Main unit CaptureArea:
procedure TMainForm.CaptureArea;
Begin
with TForm1.Create(Application) do
try
if ShowModal=mrOK then
with fRect do begin
if (Right>Left) and(Bottom>Top) then begin
Delay(400);
ABitmap:=TBitmap.Create;
ABitmap.Assign(CaptureScreenRect(fRect));
Child.Image1.Picture.Bitmap:=ABitmap;
Child.ClientWidth := Child.Image1.Picture.Width ;
Child.ClientHeight:= Child.Image1.Picture.Height;
Child.HorzScrollBar.Range:=Child.Image1.Picture.Width;
Child.VertScrollBar.Range:=Child.Image1.Picture.Height;
ABitmap.Free ;
end else begin
MessageDlg('Select the image area incorrectly, please reselect!',mtInformation,[mbOK],0);
Child.Close ;
Form1.Free;
exit;
end;
end;
Finally
Free;
end;
end;
[Capture Area]Action event for area capture
procedure TMainForm.cptAreaExecute(Sender: TObject);
Begin
Inc(CaptureNum,1);
Application.Minimize ;
Delay(500);
FileName:='Capture'+IntToStr(CaptureNum)+'.bmp';
FileName:=DefaultDirectory+FileName;
{ Create MDI Child Window }
CreateMDIChild(FileName,true);
StatusBar.SimpleText := FileName;
{ Capture Area of screen }
CaptureArea;
Child.Image1.Hint := 'Height:'+intToStr(child.Image1.Picture.Height)+'pixels'
+ ' Width:'+intToStr(child.Image1.Picture.Width)+'pixels';
application.Restore ;
end;