|
qados (Programmer) |
8 Jun 99 7:37 |
Thanks for the tip Tim, I managed to find a couple of programs that accessed the desktop at the URL you gave, it actually turned out to be quite easy...
Create a new project, and place a button on the form, double click it to create a new procedure and then cut and paste in the procedure I have included below.
{ START OF SCREEN PRINTING PROCEDURE }
procedure TForm1.Button1Click(Sender: TObject);
var
DesktopDC: hDC;
DesktopCanvas: TCanvas;
DesktopRect: TRect;
ScreenShot : Tbitmap;
begin
{ Create the ScreenShot 'bitmap object' }
ScreenShot := TBitmap.create;
{ This is a Windows API function that can be used to permit painting anywhere in a window, see Win32 API help for more details}
DesktopDC := GetWindowDC( GetDesktopWindow );
{ Creating a canvas which will contain our 'desktop' }
DesktopCanvas := TCanvas.Create;
try
DesktopCanvas.Handle := DesktopDC;
{ Creating a rectangle that is the size of the screen}
DeskTopRect := Rect(0,0,Screen.Width,Screen.Height);
{ Now we can set up our 'bitmap object' to the correct dimensions }
ScreenShot.Width :=DeskTopRect.Right-DeskTopRect.Left;
ScreenShot.Height:=DeskTopRect.Bottom-DeskTopRect.Top;
{ This function copies a rectangular image from one canvas to another, in our case from the 'desktop' canvas to our 'bitmap object' }
ScreenShot.Canvas.CopyRect( DeskTopRect,
DeskTopCanvas, DeskTopRect );
finally
{ Free up resources }
DesktopCanvas.Free;
ReleaseDC( GetDesktopWindow, DesktopDC );
end;
{ Save our bitmap to the disk }
ScreenShot.SaveToFile( 'c:\ScreenShot.bmp' );
end;
{ END OF SCREEN PRINTING PROCEDURE }
Just a quick note, some of the lines of code may have been split over two lines in your browser window... just use common sense to piece it back together. :)
This program should copy the desktop to the file name given in the code, but you can always change this so that it saves to a user specified file or something.
I hope this helps somewhat.
|
|