SKY外语计算机学习

标题: VB_屏幕捕获 [打印本页]

作者: fieldmax    时间: 2012-4-28 21:47
标题: VB_屏幕捕获
本帖最后由 sky_yx 于 2015-12-30 14:23 编辑

  1. Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
  2. Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
  3. Private Declare Function EmptyClipboard Lib "user32" () As Long
  4. Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
  5. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  6. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  7. 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
  8. 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
  9. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  10. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
  11. Private Declare Function CloseClipboard Lib "user32" () As Long
  12. Dim p1 As String
  13. Sub ScrnCap(Lt, Top, Rt, Bot)
  14. rWidth = Rt - Lt
  15. rHeight = Bot - Top
  16. SourceDC = CreateDC("DISPLAY", 0, 0, 0)
  17. DestDC = CreateCompatibleDC(SourceDC)
  18. BHandle = CreateCompatibleBitmap(SourceDC, rWidth, rHeight)
  19. SelectObject DestDC, BHandle
  20. BitBlt DestDC, 0, 0, rWidth, rHeight, SourceDC, Lt, Top, &HCC0020
  21. Wnd = Screen.ActiveForm.hwnd
  22. OpenClipboard Wnd
  23. EmptyClipboard
  24. SetClipboardData 2, BHandle
  25. CloseClipboard
  26. DeleteDC DestDC
  27. ReleaseDC DHandle, SourceDC
  28. End Sub
  29. '以下的示例把屏幕图象捕捉后,放到Picture1 中。
  30. Sub Command1_Click()
  31. ScrnCap 400, 300, 500, 400
  32. Picture1.Picture = Clipboard.GetData()
  33. End Sub
  34. Private Sub Command2_Click()
  35. ScrnCap 400, 300, 500, 400
  36. Picture2.Picture = Clipboard.GetData()
  37. For i = 1 To Picture1.Width Step 15
  38.     For j = 1 To Picture1.Height Step 15
  39.         If Picture1.Point(i, j) <> Picture2.Point(i, j) Then
  40.             MsgBox "图像改变"
  41.             Exit Sub
  42.         End If
  43.     Next j
  44. Next i
  45. End Sub
复制代码







欢迎光临 SKY外语计算机学习 (http://skywj.com/) Powered by Discuz! X2.5