Examples Delphi

Title: Screen capture
Question: How to capture the screen contence, while the application, which will capture the screen is minimized
Answer:
//Title: How to capture the screen contence, while
the application, which will capture the screen
is minimized (and runs on the background)
//Category: graphic, screen, capture
//Uploader: Maarten de Haan (M.deHaan@inn.nl)
//Delphi: 3, 4 and 5 (verified)
//Platform: NT and W95 (verified)
//================================================
//This procedure is activated by a control from the
//application, which will capture the screen
//even when another application is running
//and thus have the focus
Procedure CaptureStart(Sender: TObject);
Var
Bo : Boolean;
X,Y : Integer;
DummyCanvas : TCanvas;
KeyNumber : Byte;
KeyStr : String;
mRect : TRect;
Begin
loopQuit := False;
KeyNumber := VK_F12;
//The capture of the screen starts by pressing F12
KeyStr := 'F12';

Application.Title := 'Capture = ';
//In the systemtray a button is visible
Application.Minimize;
//Application to the system tray
//Do a dummy read
//This dummy read is not needed for WinNT, but
//for some reason needed for W95
Application.ProcessMessages;
Bo := (GetAsyncKeyState(KeyNumber) and 1 = 1);
//According to the Help the function GetAsyncKeyState
//returns a ShortInt, but that isn't true
//You'll get a range check error for sure if you try it
Repeat
Application.ProcessMessages;
//Enables other application to run
Bo := (GetAsyncKeyState(KeyNumber) and 1 = 1);
//Check for pressing of F12
Until Bo or loopQuit or (Application.Active);
//If Bo = True then F12 was pressed
//If Bo = Flase the application was activated from
//the system tray or was closed from the system tray
If Bo then
//F12 pressed
Begin
DummyCanvas := TCanvas.Create;
DummyCanvas.Handle := GetDC(0);
//Write the whole screen into the dummy canvas
Image1 := TImage.Create(Self);
Image1.Width := X;
Image1.Height := Y;
//Create a image
Image1.Canvas.CopyRect(mRect,DummyCanvas,mRect);
//Copy the screen contence to the image
DummyCanvas.Free;
//Free the dummy canvas
Application.Restore;
//Restore the minimized application
Application.Title := ProductStr + ' V' + VersionStr;
//Change back the app name
//The screen contence is now in Image1
//You can now copy it to a image of the application
//by using: AppImage.Picture := Image1.Picture
End;
//Make loopQuit true in the OnClose event of the mainform
//of the application which will capture the screen to be sure
//that the loop ends on closing the application from the
//system tray (task bar)
End;