Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen Printing

Status
Not open for further replies.

KneeBreaker

Programmer
Aug 27, 1998
12
0
0
US
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.
 
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.<br>
<br>
If I can figure out anything I'll let you know - otherwise I hope this can start to shed some light!<br>
<br>
The URL below is the page I was looking at for this piece of delphi code.<br>
<br>
 
Head over to and poke through the huge collection of delphi components, applications and samples there--you are bound to find something (everything!) you need.<br>
<br>
:eek:)
 
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...<br>
<br>
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.<br>
<br>
{ START OF SCREEN PRINTING PROCEDURE }<br>
procedure TForm1.Button1Click(Sender: TObject);<br>
<br>
var<br>
DesktopDC: hDC;<br>
DesktopCanvas: TCanvas;<br>
DesktopRect: TRect;<br>
ScreenShot : Tbitmap;<br>
<br>
begin<br>
<br>
{ Create the ScreenShot 'bitmap object' }<br>
ScreenShot := TBitmap.create;<br>
<br>
{ This is a Windows API function that can be used to permit painting anywhere in a window, see Win32 API help for more details}<br>
DesktopDC := GetWindowDC( GetDesktopWindow );<br>
<br>
{ Creating a canvas which will contain our 'desktop' }<br>
DesktopCanvas := TCanvas.Create;<br>
try<br>
DesktopCanvas.Handle := DesktopDC;<br>
<br>
{ Creating a rectangle that is the size of the screen}<br>
DeskTopRect := Rect(0,0,Screen.Width,Screen.Height);<br>
<br>
{ Now we can set up our 'bitmap object' to the correct dimensions }<br>
ScreenShot.Width :=DeskTopRect.Right-DeskTopRect.Left;<br>
ScreenShot.Height:=DeskTopRect.Bottom-DeskTopRect.Top;<br>
<br>
{ This function copies a rectangular image from one canvas to another, in our case from the 'desktop' canvas to our 'bitmap object' }<br>
ScreenShot.Canvas.CopyRect( DeskTopRect,<br>
DeskTopCanvas, DeskTopRect );<br>
<br>
finally<br>
<br>
{ Free up resources }<br>
DesktopCanvas.Free;<br>
ReleaseDC( GetDesktopWindow, DesktopDC );<br>
end;<br>
<br>
{ Save our bitmap to the disk }<br>
ScreenShot.SaveToFile( 'c:\ScreenShot.bmp' );<br>
<br>
end;<br>
{ END OF SCREEN PRINTING PROCEDURE }<br>
<br>
<br>
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. :)<br>
<br>
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. <br>
<br>
I hope this helps somewhat.<br>
<br>

 
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...<br>
<br>
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.<br>
<br>
{ START OF SCREEN PRINTING PROCEDURE }<br>
procedure TForm1.Button1Click(Sender: TObject);<br>
<br>
var<br>
DesktopDC: hDC;<br>
DesktopCanvas: TCanvas;<br>
DesktopRect: TRect;<br>
ScreenShot : Tbitmap;<br>
<br>
begin<br>
<br>
{ Create the ScreenShot 'bitmap object' }<br>
ScreenShot := TBitmap.create;<br>
<br>
{ This is a Windows API function that can be used to permit painting anywhere in a window, see Win32 API help for more details}<br>
DesktopDC := GetWindowDC( GetDesktopWindow );<br>
<br>
{ Creating a canvas which will contain our 'desktop' }<br>
DesktopCanvas := TCanvas.Create;<br>
try<br>
DesktopCanvas.Handle := DesktopDC;<br>
<br>
{ Creating a rectangle that is the size of the screen}<br>
DeskTopRect := Rect(0,0,Screen.Width,Screen.Height);<br>
<br>
{ Now we can set up our 'bitmap object' to the correct dimensions }<br>
ScreenShot.Width :=DeskTopRect.Right-DeskTopRect.Left;<br>
ScreenShot.Height:=DeskTopRect.Bottom-DeskTopRect.Top;<br>
<br>
{ This function copies a rectangular image from one canvas to another, in our case from the 'desktop' canvas to our 'bitmap object' }<br>
ScreenShot.Canvas.CopyRect( DeskTopRect,<br>
DeskTopCanvas, DeskTopRect );<br>
<br>
finally<br>
<br>
{ Free up resources }<br>
DesktopCanvas.Free;<br>
ReleaseDC( GetDesktopWindow, DesktopDC );<br>
end;<br>
<br>
{ Save our bitmap to the disk }<br>
ScreenShot.SaveToFile( 'c:\ScreenShot.bmp' );<br>
<br>
end;<br>
{ END OF SCREEN PRINTING PROCEDURE }<br>
<br>
<br>
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. :)<br>
<br>
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. <br>
<br>
I hope this helps somewhat.<br>
<br>

 
opps for the double sumission, I thought my first one had timed out :) DOH !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top