Option ExplicitPrivate 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 LongPrivate Sub Command1_Click() '从屏幕上截图 picCopy.Width = Width picCopy.Height = Height - 300 BitBlt picCopy.hDC, 0, 0, Width - 1, Height - 300, Me.hDC, 0, 0, &HCC0020 SavePicture picCopy.Image, "c:\aa.bmp" End SubPrivate Sub Form_Load() '在窗口中加一个PICTUREBOX控件,改名为picCopy picCopy.Visible = False picCopy.AutoRedraw = True End Sub
Private Function CaptureWindow(ByVal hWndSrc As Long, _ ByVal bClient As Boolean, ByVal LeftSrc As Long, _ ByVal TopSrc As Long, ByVal WidthSrc As Long, _ ByVal HeightSrc As Long) As PicturePrivate Sub command1_Click() Set Picture1.Picture = CaptureForm(Me) End SubPrivate Function CaptureForm(frm As Form) As PictureWith frm Set CaptureForm = CaptureWindow(.hWnd, False, 0, 0, _ .ScaleX(.Width, vbTwips, vbPixels), _ .ScaleY(.Height, vbTwips, vbPixels)) End With End Function
截图不一定能把FORM全截取下来 那怎么办?
Private Function CaptureWindow(ByVal hWndSrc As Long, _ ByVal bClient As Boolean, ByVal LeftSrc As Long, _ ByVal TopSrc As Long, ByVal WidthSrc As Long, _ ByVal HeightSrc As Long) As PicturePrivate Sub command1_Click() Set Picture1.Picture = CaptureForm(Me) End SubPrivate Function CaptureForm(frm As Form) As Picture With frm Set CaptureForm = CaptureWindow(.hWnd, False, 0, 0, _ .ScaleX(.Width, vbTwips, vbPixels), _ .ScaleY(.Height, vbTwips, vbPixels)) End With End Function
'从屏幕上截图
picCopy.Width = Width
picCopy.Height = Height - 300 BitBlt picCopy.hDC, 0, 0, Width - 1, Height - 300, Me.hDC, 0, 0, &HCC0020
SavePicture picCopy.Image, "c:\aa.bmp"
End SubPrivate Sub Form_Load()
'在窗口中加一个PICTUREBOX控件,改名为picCopy
picCopy.Visible = False
picCopy.AutoRedraw = True
End Sub
Private Function CaptureWindow(ByVal hWndSrc As Long, _
ByVal bClient As Boolean, ByVal LeftSrc As Long, _
ByVal TopSrc As Long, ByVal WidthSrc As Long, _
ByVal HeightSrc As Long) As PicturePrivate Sub command1_Click()
Set Picture1.Picture = CaptureForm(Me)
End SubPrivate Function CaptureForm(frm As Form) As PictureWith frm
Set CaptureForm = CaptureWindow(.hWnd, False, 0, 0, _
.ScaleX(.Width, vbTwips, vbPixels), _
.ScaleY(.Height, vbTwips, vbPixels))
End With
End Function
那怎么办?
ByVal bClient As Boolean, ByVal LeftSrc As Long, _
ByVal TopSrc As Long, ByVal WidthSrc As Long, _
ByVal HeightSrc As Long) As PicturePrivate Sub command1_Click()
Set Picture1.Picture = CaptureForm(Me)
End SubPrivate Function CaptureForm(frm As Form) As Picture
With frm
Set CaptureForm = CaptureWindow(.hWnd, False, 0, 0, _
.ScaleX(.Width, vbTwips, vbPixels), _
.ScaleY(.Height, vbTwips, vbPixels))
End With
End Function
还有你的这个截取的是ACTIVE窗体么?