PDA

Click to See Complete Forum and Search --> : Hoe to Print Screen


Steve Thomas
May 23rd, 2000, 02:38 AM
I want to print the screen on my application.

I can use the following code:

MyForm.ActiveForm.PrintForm

However, it only prints half of my screen and changes some fonts. I can copy the screen to Microsoft Word and then print it that way but was hoping that I could do it an easier way?????

Fox
May 23rd, 2000, 03:43 AM
As I understood you want to copy the screen buffer right? Well, if so check out the demo project on my website (http://foxmccloud.tsx.org) ;).

Steve Thomas
May 23rd, 2000, 03:57 AM
I have visited your site but I can't seem to find the proper code. Can you tell me what it would be called???

Thanks

Fox
May 23rd, 2000, 11:02 AM
Well I use GetWindowDC(GetDesktopWindow) to get the DC of the screen, then blitting the DC to any picture box. Very easy and simple demo...

'Module
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long

'Code (Add a picbox 'Buffer' to your app)
Dim DC As Long

'Get DC of desktop (=screen)
DC = GetWindowDC(GetDesktopWindow)

'Adjust size
Buffer.Width = Screen.Width / Screen.TwipsPerPixelX
Buffer.Height = Screen.Height / Screen.TwipsPerPixelY

'BitBlt to Buffer
BitBlt Buffer.hdc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, DC, 0, 0, vbSrcCopy

'Release DC
ReleaseDC Me.hwnd, DC


...and don't forget to set the scalemode to pixels...

Steve Thomas
May 23rd, 2000, 09:21 PM
Thanks for code. However, I am having a few problems with it. I am having a problem with the ReleaseDC. "Sub or Function not Defined." Second. How do you send the buffer "PicBox" to the printer??? I am sure this is easy but I have never done it.

Thanks

Steve Thomas
May 23rd, 2000, 09:41 PM
I added the API call to ReleaseDC. All I need to figure out now is how to Print the PicBox. I haven't done much in the way of printing in VB so thanks for any help.

Fox
May 23rd, 2000, 11:25 PM
Ah, you meant printing on paper ;) Sorry 'bout that!

well, just add this code:


Printer.StartDoc
Printer.PaintPicture Buffer.Image, 0, 0
Printer.EndDoc


Should work...

Steve Thomas
May 24th, 2000, 12:50 AM
I added the Printer code but Printer.StartDoc doesn't seem to be in the collection. It talks about it in Documentation but I am not quite sure how it relates. I created a button that when I click, it creates the PicBox and does indeed display the copied screen. I added the code you gave me less the Printer.StartDoc and it kicks a print job off but with nothing printing. I can manually add a picture to the picBox control and it prints????

Dim DC As Long

'Get DC of desktop (=screen)
DC = GetWindowDC(GetDesktopWindow)

'Adjust size
f.Buffer.Width = Screen.Width / Screen.TwipsPerPixelX
f.Buffer.Height = Screen.Height / Screen.TwipsPerPixelY

'BitBlt to Buffer
BitBlt f.Buffer.HDC, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, DC, 0, 0, vbSrcCopy


Printer.PaintPicture f.Buffer.Image, 0, 0
Printer.EndDoc

'Release DC
ReleaseDC Me.hwnd, DC

Fox
May 24th, 2000, 01:51 AM
You're right, StartDoc doesn't exist (anymore?) :(

Well, did you try to set AutoRedraw of the picturebox to true?

I never did much about printing so I just can give you some ideas you know ;)

Steve Thomas
May 24th, 2000, 03:11 AM
I set autoRedraw and it printed. It works Great. Thanks s much for all your help!!!!!!

Fox
May 24th, 2000, 12:00 PM
np :)