3
A
回答
8
此代碼將從窗口或整個桌面(虛擬屏幕)捕獲屏幕截圖並將其繪製到自定義picturebox。
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32"() As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd 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 ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Private Const SM_XVIRTUALSCREEN = 76
Private Const SM_YVIRTUALSCREEN = 77
Private Const SM_CYVIRTUALSCREEN = 79
Private Const SM_CXVIRTUALSCREEN = 78
Private Sub GetScreenshot(Optional ByVal hWnd As Long = 0)
Dim hDC As Long
Dim WindowRect As RECT
Dim Left As Long
Dim Top As Long
Dim Width As Long
Dim Height As Long
If hWnd = 0 Then
'Get the DC of the desktop
hDC = GetWindowDC(GetDesktopWindow)
'Get the virtual screen coordinates (this handles multiple monitors too :)
Left = GetSystemMetrics(SM_XVIRTUALSCREEN)
Top = GetSystemMetrics(SM_YVIRTUALSCREEN)
Width = GetSystemMetrics(SM_CXVIRTUALSCREEN)
Height = GetSystemMetrics(SM_CYVIRTUALSCREEN)
Else
'Get the DC of the window we want to capture
hDC = GetWindowDC(hWnd)
'Get the window coordinates
GetWindowRect hWnd, WindowRect
Left = 0
Top = 0
Width = WindowRect.Right - WindowRect.Left
Height = WindowRect.Bottom - WindowRect.Top
End If
'BitBlt into our own DC
BitBlt picScreen.hDC, 0, 0, Width, Height, hDC, Left, Top, vbSrcCopy
'Delete our reference to the windows's DC
ReleaseDC hWnd, hDC
End Function
請注意在捕獲桌面時使用GetSystemMetrics()
。這使得它可以在使用多個顯示器而不是just the primary monitor時獲得完整的虛擬屏幕尺寸。
相關問題
- 1. 捕獲屏幕
- 2. 捕獲屏幕
- 3. Visual Basic中的屏幕尺寸
- 4. 屏幕捕獲的代碼屏幕捕獲Android的任何屏幕
- 5. 登錄屏幕中的屏幕捕獲
- 6. 捕獲android屏幕
- 7. PowerShell屏幕捕獲
- 8. windows屏幕捕獲
- 9. 屏幕捕獲API
- 10. HTML5捕獲屏幕
- 11. cocos2d的屏幕捕獲,並從UIImage的
- 12. 在Linux上的屏幕捕獲
- 13. OSX上的Autopy屏幕捕獲
- 14. 使用DirectX捕獲Windows上的屏幕
- 15. 從Windows服務的屏幕捕獲
- 16. 屏幕上的鍵盤捕獲活動屏幕
- 17. 在Android的屏幕捕獲
- 18. cmd的Visual Basic捕獲輸出
- 19. 捕獲屏幕圖像而不捕獲屏幕捕獲垃圾郵件
- 20. iOS:在屏幕上捕獲CAEmitterLayer粒子
- 21. 作爲UIImage在iPhone上捕獲屏幕?
- 22. DirectX從Windows服務捕獲屏幕
- 23. 從主機虛擬機屏幕捕獲
- 24. C#:從Windows服務捕獲屏幕
- 25. 會話0捕獲屏幕
- 26. 捕獲屏幕截圖
- 27. 屏幕捕獲在IOS中
- 28. 捕獲MKMapView屏幕截圖
- 29. 屏幕捕獲問題
- 30. ASP.NET - 捕獲屏幕截圖
我還沒有嘗試過任何東西(但在紅寶石很多) – marscom 2012-03-13 02:41:29
做[任何](http://www.developerfusion.com/code/181/capture-screenshot/)[的](http://www.codeproject .com /文章/ 27269 /截圖 - 桌面 - 編程方式 - 在)[這些](https://www.google.co.uk/search?hl=en&q=vb6+capture+screenshot&meta=)不回答你的問題? – Deanna 2012-03-13 13:01:49
哦,ARGB是octects的正常順序,並且是Windows原生的。 – Deanna 2012-03-13 13:03:54