[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?
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.
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]?
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".
1 Attachment(s)
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.
Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...
Quote:
Originally Posted by
jmsrickland
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.
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: [email protected]
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. :check:
1 Attachment(s)
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 -
Attachment 123463
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?