With this code I am going to show you how you can capture your screen using dephi. Let's go step by step.
First we need to insert the component TImage. We are going to use it to paste the screenshot there. Note that you can set up the property stretched to either true or false, with stretch the image will take the whole TImage, this is recommended. You can also try both options and see for yourself the difference.
This is how my application looks like. You can always customize it with whatever you feel comfortable with.
Let's go to the coding now, first we create the procedure that will take care of the screenshot.
Code:
procedure TakeScreenShot (Image : TBitmap);
var
DC : HDC;
begin
DC := GetDC (GetDesktopWindow);
try
Image.Width:= GetDeviceCaps (DC, HORZRES);
Image.Height:= GetDeviceCaps (DC, VERTRES);
BitBlt(Image.Canvas.Handle, 0, 0, Image.Width,
Image.Height,DC, 0, 0, SRCCOPY);
finally
ReleaseDC (GetDesktopWindow, DC);
end;
end;
Take a look that we set up an object named Image, and we especified that it is a bitmap. We will use this to store the image of the screenshot. Then we used
Code:
Image.Width:= GetDeviceCaps (DC, HORZRES);
Image.Height := GetDeviceCaps (DC, VERTRES);
In that code we use the image width and call the GetDeviceCaps that what it does it take the screen width (horizontal) and the Image.Height takes the vertical size of our skin.
And now how do we call this procedure to place the screenshot on our image? We call it like this:
Code:
TakeScreenShot(Image1.Picture.Bitmap);
You can use that anywhere you want, in a button OnClick event, on a timer, etc...
Well that's pretty much it, now go ahead and try the program and make something cool out of it.
Happy Coding!