在VB6和VB.NET中进行图象捕获

在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

 

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

 

时间: 2024-10-31 19:32:42

在VB6和VB.NET中进行图象捕获的相关文章

VB6和VB.NET中对光标的编程

编程 在VB6中利用API对光标进行编程: Option ExplicitPrivate Type POINTAPI    X As Long    Y As LongEnd TypePrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Declare Function ShowCursor Lib "user32" (ByVal bShow A

在VB.NET中进行抓屏

'Author:wgscd '功能:抓屏 'QQ153964481 'Date:2005-4-12 '*********************************  Public Class Form1     Inherits System.Windows.Forms.Form #Region " Windows 窗体设计器生成的代码 "     Public Sub New()         MyBase.New()         '该调用是 Windows 窗体设计器所

求大神:vb.net中在有背景图的情况下如何提高透明图片的切换速度

问题描述 求大神:vb.net中在有背景图的情况下如何提高透明图片的切换速度 情况:在一张地图上有多个交叉口(大概100个),要在上面显示红绿灯图片(图片为正方形,中间是红或绿的圆,圆以外区域透明),现要求每秒变换一次图片颜色.版本:.net framework 3.5采用方法::将图片放入label(picturebox也试过)控件中,每秒切换一次遇到问题:图片切换速度很慢,所有红绿灯不是同时变换,而是一个接一个的往下变,渐变效果非常明显预计原因(猜测):图片在变换时为了显示图片的透明部分会去

vb.net 实现 甘特图能表达SQL中数据

问题描述 怎么实现vb.net的甘特图能表示出SQL中数据的图 解决方案 解决方案二:你需要的是第三方的图表控件解决方案三:第三方控件代码看不懂大神我该下载什么样的控件比较合适解决方案四:怎么回事呢求解!!!

VB.net中能否实现相当于VB6中的异或绘图功能?如何实现?请高手指点!

问题描述 VB.net中能否实现相当于VB6中的异或绘图功能?如何实现?请高手指点!

Vb6.0 Variant 在 Vb.net 中 Object 的问题

问题描述 Vb6.0代码如下:ConstDATASIZE=459DimglngEnrollDataAsVariantDimvniiAsLongDimvByte()AsByteastrBuff=Rs.Fields("TEMP")'2进制字段vByte=astrBuffForvnii=0ToDATASIZE-1glngEnrollData(vnii)=vByte(vnii*5+1)glngEnrollData(vnii)=glngEnrollData(vnii)*256+vByte(vni

Vb6.0 Variant 在 Vb.net 中 Object 赋值问题

问题描述 Vb6.0代码如下:ConstDATASIZE=459DimglngEnrollDataAsVariantDimvniiAsLongDimvByte()AsByteastrBuff=Rs.Fields("TEMP")'2进制字段vByte=astrBuffForvnii=0ToDATASIZE-1glngEnrollData(vnii)=vByte(vnii*5+1)glngEnrollData(vnii)=glngEnrollData(vnii)*256+vByte(vni

从VB6到VB.NET的变化综述 (转)

随着Microsoft .NET平台的发布,Visual Basic开始成为一种完全面向对象的语言,简称为VB.NET.虽然有了一些根本性的变化,开发者从VB6到VB.NET的学习热情依然相当高,即使对于有经验的编程人员也是如此.本文中,我将列出Visual Basic语言中的变化,并在适当的地方举例说明.这里所列出的可能不完全,但是已经包括了大部分的功能.如果你是一个想要转到VB.NET上去的 VB程序员,这篇文章就一定要读一读. ASP.NET Beta 1版本可以从http://www.a

从VB6到VB.NET的变化综述(转)

从VB6到VB.NET的变化综述 当创建ASP.NET页面时,需要使用一种与兼容 .NET的编程语言,如C#.VB.NET或JScript.NET.但是从VB6/VBScript 到VB.NET有许多重要的变化,这正是本文所涉及的内容. 另外,如果想获得更多有关的信息,我强烈推荐你阅读Microsoft的文章:为Visual Basic 6.0应用程序升级到Visual Basic.NET做好准备. 引言随着Microsoft .NET平台的发布,Visual Basic开始成为一种完全面向对象