首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB 怎样在指定位置截屏,该如何解决

2012-01-31 
VB 怎样在指定位置截屏怎样在指定位置截取指定大小的图象[解决办法]Public Function SnapScreen(Optional

VB 怎样在指定位置截屏
怎样在指定位置截取指定大小的图象

[解决办法]
Public Function SnapScreen(Optional Left As Long = 0, Optional Top As Long = 0, Optional Right As Variant, Optional Bottom As Variant) As Long
On Error GoTo ErrHandle:
Dim rWidth As Long
Dim rHeight As Long
Dim SourceDC As Long
Dim DestDC As Long
Dim BHandle As Long
Dim Wnd As Long
Dim DHandle As Long
If IsMissing(Right) Then Right = Screen.Width / Screen.TwipsPerPixelX
If IsMissing(Bottom) Then Bottom = Screen.Height / Screen.TwipsPerPixelY
rWidth = Abs(Right - Left)
rHeight = Abs(Bottom - Top)
SourceDC = CreateDC( "DISPLAY ", 0, 0, 0)
DestDC = CreateCompatibleDC(SourceDC)
BHandle = CreateCompatibleBitmap(SourceDC, rWidth, rHeight)
SelectObject DestDC, BHandle
BitBlt DestDC, 0, 0, rWidth, rHeight, SourceDC, Left, Top, vbSrcCopy
Wnd = GetDesktopWindow
OpenClipboard Wnd
EmptyClipboard
SetClipboardData 2, BHandle
CloseClipboard
DeleteDC DestDC
ReleaseDC DHandle, SourceDC
Set mResultContainer.Picture = Clipboard.GetData
SnapScreen = Rnd * 100000
Exit Function
ErrHandle:
SnapScreen = 0
End Function

热点排行