Implement in Borland Delphi a function (or a class) with the following interface:
Function TakeScreenshot(Window : THandle; TopLeftPoint : TPoint, BottomRightPoint : TPoint; Filename : String) : Integer;
The function takes a screenshot of a given window's canvas area (window's handle is given with the Window parameter). But instead of the entire canvas, only area between TopLeftPoint and BottomRightPoint. Parameter Filename defines the filename in which the screenshot file is saved. The file can be saved in any format, such as BMP or JPG.
The function returns a status code of 0 if everything worked OK, and an error code in a case of error.
p1.x := 0;
p1.y := 0;
p2.x := 100;
p2.y := 100;
TakeScreenshot(12345, p1, p2, 'c:\[url removed, login to view]');
This call would create a screenshot of a window whose handle is 12345, the screenshot would be only of the top left corner of the window canvas. The screenshot is saved to the given filename.
The code must work under Windows 7 and Windows Vista.