免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 回復 發帖

VB6 螢幕截圖

Option Explicit

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 CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData 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 Sub Command1_Click()
  Call ScrnCap(0, 0, 800, 600) '?用函?,4????左上,右下坐?
    Image1.Picture = Clipboard.GetData()
    'Printer.PaintPicture Picture1.Picture, 0, 0

End Sub

Sub ScrnCap(Lt As Integer, top As Integer, Rt As Integer, Bot As Integer) '屏幕截?核心函?
  Dim rWidth, rHeight, SourceDC, DestDC, BHandle, Wnd, DHandle
  rWidth = Rt - Lt
  rHeight = Bot - 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, Lt, top, &HCC0020
  Wnd = Screen.ActiveForm.hwnd
OpenClipboard Wnd
  EmptyClipboard
SetClipboardData 2, BHandle
  CloseClipboard
  DeleteDC DestDC
  ReleaseDC DHandle, SourceDC
End Sub



-----------------------------------------------------------

SendKeys "^{PRTSC}", True '把屏幕截图复制到Clipboard
Picture1.Picture = Clipboard.GetData(vbCFDIB
返回列表