i can copy everything(inclued controls) in a hwd property by using PrintWindows() API function. my problem is how can i copy these image by a size and position(crop the image).
i did and try that without sucess:(
can anyone advice me?
thanks
Printable View
i can copy everything(inclued controls) in a hwd property by using PrintWindows() API function. my problem is how can i copy these image by a size and position(crop the image).
i did and try that without sucess:(
can anyone advice me?
thanks
Use GetWindowRect to get the size of the window Printwindow is going to capture, set the temp destination to that size, then use BitBlt to set the crop size and x,y positions you want.
I did this in a hurry using pic boxes, maybe it help?
Code:Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function PrintWindow Lib "User32.dll" (ByVal hwnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Sub Command1_Click()
Dim Calc_hWnd As Long
Dim Calc_Rect As RECT
Me.ScaleMode = vbPixels
' temp destination
Picture1.ScaleMode = vbPixels
Picture1.AutoRedraw = True
' final destination
Picture2.ScaleMode = vbPixels
Picture2.AutoRedraw = True
' Get Handle to windows calculator
Calc_hWnd = FindWindow(vbNullString, "Calculator")
' get size of windows calculator
If Calc_hWnd Then
GetWindowRect Calc_hWnd, Calc_Rect
' size temp destination to calc
Picture1.Width = Calc_Rect.Right - Calc_Rect.Left
Picture1.Height = Calc_Rect.Bottom - Calc_Rect.Top
' capture it
PrintWindow Calc_hWnd, Picture1.hDC, 0
Picture1.Refresh 'update temp
'Set final destination to crop size
Picture2.Width = Picture1.Width / 2
Picture2.Height = Picture1.Height / 2
'copy, x=10, y=51
BitBlt Picture2.hDC, 0, 0, _
Picture2.ScaleWidth, _
Picture2.ScaleHeight, _
Picture1.hDC, 10, 51, vbSrcCopy
'update dest.
Picture2.Refresh
' save it as bmp file
SavePicture Picture2.Image, "C:\Calc_Capture.bmp"
Else
MsgBox "Calculator is not running!", vbInformation
End If
End Sub
think in these way: i have the image in a picturebox(the container image with controls), now i need crop the image. but the bitblt isn't working:(
but, i don't know if these must be said(i don't know write the other word), i don't use the container size to the picturebox size. is these a problem?
Maybe you could upload demo of your code, but just some quick thoughts,...
If Picbox.AutoRedraw=True then call Picbox.Refesh after the BitBlt call.
If Picbox.AutoRedraw=False then do not call Picbox.Refesh after the BitBlt call.
The xSrc and ySrc in BitBlt are the source capture points, so xSrc must be < the source width and ySrc < source height.
using these sub i can copy a container image with it controls(by image way):
ok how my code works:Code:Public Sub ImageWithControls(ByRef srcPicture As Long, ByRef dstPicture As Long)
PrintWindow srcPicture, dstPicture, 0
End Sub
i don't understand why these bug(i know by seing:(Code:picGraphicsEffects.Picture = UserControl.Image ' coopy the uc image to picgraphicseffects picturebox(until here fine)
UserControl.Picture = Nothing
Load PicAnimation(PicAnimation.Count) 'then i create 1 picturebox fox put the container image
ImageWithControls Extender.Container.hwnd, PicAnimation(PicAnimation.Count - 1).hDC
PicAnimation(PicAnimation.Count - 1).Picture = PicAnimation(PicAnimation.Count - 1).Image ' unti here works fine
Load PicAnimation(PicAnimation.Count)
Debug.Print BitBlt(PicAnimation(PicAnimation.Count - 1).hDC, 0, 0, UserControl.Width, UserControl.Height, PicAnimation(PicAnimation.Count - 2).hDC, Extender.Left, Extender.Top, SRCCOPY) ' i use these line for crop the image. i only need the usercontrol position and it's size(for crop the image). but here is the problem. is like isn't working or ignored:(
see the image result.. the problem is the girl background image, isn't correct, like you can see by container