Results 1 to 9 of 9

Thread: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Resolved [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    I can capture a picture of the form and put it on the clipboard perfectly... except the portion that's off the screen. If my form is wider than the screen is, it takes that portion of the picture and just makes it black when I paste it into something like PaintBrush. I've even tried saving it, as opposed to just putting it on the clipboard... same result. Any way to capture a picture of the entire form without blacking out the portion that's off the screen?

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    Try this, first add a PictureBox to your Form and make it invisible, then add this code (I used a CommandButton to capture)
    Code:
    Private Declare Function SendMessage Lib "user32" Alias _
       "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
       ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Const WM_PAINT = &HF
    Private Const WM_PRINT = &H317
    Private Const PRF_CLIENT = &H4&    ' Draw the window's client area
    Private Const PRF_CHILDREN = &H10& ' Draw all visible child
    Private Const PRF_OWNED = &H20&    ' Draw all owned windows
    
    Private Sub Command1_Click()
    Dim rv As Long
    
        Clipboard.Clear
        
        Picture1.Width = Me.Width
        Picture1.Height = Me.Height
       
        Picture1.AutoRedraw = True
        rv = SendMessage(Me.hwnd, WM_PAINT, Picture1.hDC, 0)
        rv = SendMessage(Me.hwnd, WM_PRINT, Picture1.hDC, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
        
        Set Picture1.Picture = Picture1.Image
        Clipboard.SetData Picture1.Picture, vbCFBitmap
    End Sub
    This should add the complete Form Picture to Clipboard with offscreen parts included. Just ensure the Form use twips as Scalemode, if not a little coordinate conversion would be needed.
    Last edited by jcis; Sep 18th, 2013 at 09:20 PM.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Re: Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    JCIS... you are the man (unless you're a girl). That totally worked! Thank you so much!!! Now, how do I set this as [RESOLVED]?

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    You're welcome, go to Thread Tools Menu (up right) and select "Mark thread Resolved".

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    I don't know how yours turned out but when I try it I get a black rectangle on the left side of the client area and it chops off part of the top of the client area. I used that code exactly as is, I made the picturebox invisible.
    Attached Images Attached Images  


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    Quote Originally Posted by jmsrickland View Post
    I don't know how yours turned out but when I try it I get a black rectangle on the left side of the client area and it chops off part of the top of the client area. I used that code exactly as is, I made the picturebox invisible.
    Could you attach an example project so i can see what's happening? The problem could be a control in the Form or the Form's properties or many other things, so if you attach an small project it will be easier.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Resolved Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    Okay. I've created a community gmail account.

    Username: vbforumsmail@gmail.com
    Password: vbforumsmail1

    Since I can't upload anything larger than 500k, you can use this. Just don't change anything and we can all use it. Use the honor system.

    You'll see my project (RPG Map Maker) in the GMail Inbox.

  8. #8
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    I tried to sign in to the communal gmail and copped this -

    Name:  gmail_does_notLet_me_in.jpg
Views: 2114
Size:  23.0 KB

  9. #9
    Junior Member
    Join Date
    Feb 2012
    Posts
    26

    Re: Capture Picture Of A Form When A Portion Of It Is Off The Screen...

    jcis,
    I am trying to capture a form - part of which is off-screen; your code and code below I am using does capture the whole form... BUT some parts of the form are out of place and it does not capture a RichText Box information; my code below
    Clipboard.Clear
    picDest.AutoRedraw = True
    picDest.ScaleMode = 1 '- Twip
    picDest.Width = Me.Width
    picDest.Height = Me.Height

    rv = SendMessage(Me.hWnd, WM_PAINT, picDest.hdc, 0)
    rv = SendMessage(Me.hWnd, WM_PRINT, picDest.hdc, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)

    Set picDest.Picture = picDest.Image
    Clipboard.SetData picDest.Picture, vbCFBitmap

    What is wrong?

Tags for this Thread

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