VB 截图 抓图

来源:互联网 发布:怎样安装app软件 编辑:程序博客网 时间:2024/05/01 19:36
VB 截图 抓图   

Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long

Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, _
    ByVal hMem As Long) As Long

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
    ByVal hObject As Long) As Long

Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) 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 Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long

Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, _
    ByVal nWidth As Long, ByVal nHeight As Long) As Long

Private Declare Function CloseClipboard Lib "user32" () As Long

Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, _
    ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As Long) As Long

Private Sub Command1_Click()
  Me.Visible = False
  SourceDC = CreateDC("DISPLAY", 0, 0, 0)
  DestDC = CreateCompatibleDC(SourceDC)
  Bhandle = CreateCompatibleBitmap(SourceDC, 800, 600)
  SelectObject DestDC, Bhandle
  BitBlt DestDC, 0, 0, 800, 600, SourceDC, 0, 0, &HCC0020
  Wnd = Screen.ActiveForm.hwnd
  OpenClipboard Wnd
  EmptyClipboard
  SetClipboardData 2, Bhandle
  CloseClipboard
  DeleteDC DestDC
  ReleaseDC Dhandle, SourceDC
  Me.Picture = Clipboard.GetData()
  Me.Visible = True
End Sub

Private Sub Command2_Click()
  Me.Picture = Me.Image
  ''保存捕捉的图片
  CommonDialog1.Filter = "BMP文件(*.bmp)|*.bmp|JPG文件(*.jpg)|*.jpg"
  CommonDialog1.ShowSave
  CommonDialog1.Flags = &H2 + &H4 + &H8
  If CommonDialog1.FileName <> "" Then
     SavePicture Me.Picture, CommonDialog1.FileName
  End If
End Sub

Private Sub Command3_Click()
  End
End Sub

 
原创粉丝点击