INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Screen Printing

Screen Printing

(OP)
I am new to DELPHI and cannot seem to find how to print the contents of a screen using a button to activate the process. Any help would be appreciated.

RE: Screen Printing

I'm also looking for an answer to this question, one piece of information I've found is for a little delphi program that "magnifies" a section of the desktop screen. I havn't really studied this yet, but I figure that in order to magnify part of the screen you must have to capture it in some way.

If I can figure out anything I'll let you know - otherwise I hope this can start to shed some light!

The URL below is the page I was looking at for this piece of delphi code.

http://delphi.miningco.com/library/weekly/aa120198.htm?rf=dp&COB=home

RE: Screen Printing

Head over to www.torry.ru and poke through the huge collection of delphi components, applications and samples there--you are bound to find something (everything!) you need.

:o)

RE: Screen Printing

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.

RE: Screen Printing

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.

RE: Screen Printing

opps for the double sumission, I thought my first one had timed out :) DOH !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close