Image capture in VB6 and vb.net

Source: Internet
Author: User
Tags integer

Image capture in VB6 and vb.net

Image capture in VB6

'----------------------------------------------------------------------------

'

' Author:lihonggen0

' Date:2002-6-19

' Function: Grab screen

'----------------------------------------------------------------------------

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

' Reference

' http://support.microsoft.com/?kbid=210108
http://support.microsoft.com/?id=161299


Vb. NET to capture the image, you need to refer to some APIs, the following is the declaration:

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

Add the following code to the Button1_Click event:

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.