在VB6和VB.NET中进行图象捕获
来源:互联网 发布:逆战刷帮豆软件手机版 编辑:程序博客网 时间:2024/06/05 17:48
在VB6和VB.NET中进行图象捕获
VB6中进行图象捕获
'----------------------------------------------------------------------------
'
'Author:lihonggen0
'Date:2002-6-19
'功能:抓屏
'----------------------------------------------------------------------------
Private Type POINTAPI
x As Long
y As Long
End Type
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 GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Sub Command1_Click()
Dim hdc As Long
Dim sw As Integer
Dim sh As Integer
Dim CurPos As POINTAPI
Dim Cur As Long
Me.Hide
DoEvents
Picture1.AutoRedraw = True
hdc = GetDC(0)
GetCursorPos CurPos
Cur = GetCursor
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height
sw = Screen.Width / Screen.TwipsPerPixelX
sh = Screen.Height / Screen.TwipsPerPixelY
BitBlt Picture1.hdc, 0, 0, sw, sh, hdc, 0, 0, vbSrcCopy
Me.Show
DrawIcon Picture1.hdc, CurPos.x - 10, CurPos.y - 10, Cur
ReleaseDC 0, hdc
Picture1.AutoRedraw = False
End Sub
'参考
'http://support.microsoft.com/?kbid=210108
http://support.microsoft.com/?id=161299
http://support.microsoft.com/?id=161299
VB.NET中进行图象捕获 ,需要先引用一些API,以下是声明:
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = &HCC0020
将以下代码添加到Button1_Click事件中:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
hDC = GetDC(0)
hMDC = CreateCompatibleDC(hDC)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
PictureBox1.Image = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
End Sub
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=180394
- 在VB6和VB.NET中进行图象捕获
- 在VB6和VB.NET中进行图象捕获
- 抓屏,VB.NET中进行屏幕图象的捕获
- 在VB6和VB.net中设置桌面墙纸
- VB6和VB.NET中对光标的编程
- VB6和VB.NET中对光标的编程
- VB6和VB.NET中对光标的编程
- [VB.NET]VB6写的DLL在vb.net中怎么调用啊 谢谢
- 在VB.NET中进行抓屏
- 【转】VB6和VB.NET的区别
- VB6.0和VB.Net对照表
- VB6.0和VB.NET区别
- VB6和VB.NET的区别
- [VB.NET]在vb.net中有没有类似vb6控件数组的方法控制一组控件?
- vb6 轉 vb.net
- 在VB6和VB.NET下分别获取汉字的字节
- *、VB.net 和 VB6 在一些方法上的转换技巧
- vb.net捕获和抛出异常
- SQL Server 存储过程的分页方案比拼
- SQL Server中发送邮件的新方式
- Thinstall.VS Package Editor Version 2008.01.10.23.10 by gyfhgyfh
- 陌生人
- 2008十大应用热点猜想 SOA+BPM 居首
- 在VB6和VB.NET中进行图象捕获
- 动态加载js
- SQL SERVER 与ACCESS、EXCEL的数据转换
- 从VB 6到VB.NET——窗体特殊应用
- DIY中文版VS2008
- USB基础知识(上)
- VB6和VB.NET中对光标的编程
- .NET环境下水晶报表使用总结
- C#面向对象设计模式纵横谈 学习笔记9 Composite 组合(结构型模式)