|
-
May 23rd, 2000, 02:38 AM
#1
Thread Starter
Addicted Member
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?????
-
May 23rd, 2000, 03:43 AM
#2
PowerPoster
As I understood you want to copy the screen buffer right? Well, if so check out the demo project on my website .
-
May 23rd, 2000, 03:57 AM
#3
Thread Starter
Addicted Member
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
-
May 23rd, 2000, 11:02 AM
#4
PowerPoster
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...
Code:
'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...
-
May 23rd, 2000, 09:21 PM
#5
Thread Starter
Addicted Member
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
-
May 23rd, 2000, 09:41 PM
#6
Thread Starter
Addicted Member
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.
-
May 23rd, 2000, 11:25 PM
#7
PowerPoster
Ah, you meant printing on paper Sorry 'bout that!
well, just add this code:
Code:
Printer.StartDoc
Printer.PaintPicture Buffer.Image, 0, 0
Printer.EndDoc
Should work...
-
May 24th, 2000, 12:50 AM
#8
Thread Starter
Addicted Member
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
-
May 24th, 2000, 01:51 AM
#9
-
May 24th, 2000, 03:11 AM
#10
Thread Starter
Addicted Member
I set autoRedraw and it printed. It works Great. Thanks s much for all your help!!!!!!
-
May 24th, 2000, 12:00 PM
#11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|