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. 屏幕捕获的代码屏幕捕获Android的任何屏幕
- 3. 捕获android屏幕
- 4. 屏幕捕获API
- 5. 在Linux上的屏幕捕获
- 6. 从Windows服务的屏幕捕获
- 7. 屏幕上的键盘捕获活动屏幕
- 8. 在Android的屏幕捕获
- 9. iOS:在屏幕上捕获CAEmitterLayer粒子
- 10. 作为UIImage在iPhone上捕获屏幕?
- 11. C#:从Windows服务捕获屏幕
- 12. 从主机虚拟机屏幕捕获
- 13. ASP.NET/ActiveX/Silverlight屏幕捕获
- 14. 屏幕捕获闪存
- 15. 屏幕捕获问题
- 16. 捕获屏幕截图
- 17. 如何捕获pygame屏幕?
- 18. Silverlight 4屏幕捕获
- 19. ASP.NET - 捕获屏幕截图
- 20. 使用SDL捕获屏幕?
- 21. GLUT屏幕捕获在C
- 22. 快速iphone屏幕捕获
- 23. 无法捕获屏幕
- 24. VB.NET窗口屏幕捕获(ALT + PRINTSCREEN)
- 25. 的屏幕捕捉
- 26. 无法从intent.getParcelableExtra(Intent.EXTRA_STREAM)获取捕获的屏幕截图的URI!
- 27. 捕获屏幕内存到位图(visual c + + 6.0)
- 28. 将GLSurfaceView的屏幕捕获到位图
- 29. Eclipse中的Android屏幕捕获问题
- 30. C#捕获的Direct 3D屏幕
我还没有尝试过任何东西(但在红宝石很多) – 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