Results 1 to 11 of 11

Thread: Hoe to Print Screen

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    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?????

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    As I understood you want to copy the screen buffer right? Well, if so check out the demo project on my website .

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    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

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    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

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    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.

  7. #7
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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...

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    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

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 1999
    Posts
    154
    I set autoRedraw and it printed. It works Great. Thanks s much for all your help!!!!!!

  11. #11
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    np

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width