首页 > 编程 > .NET > 正文

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

2024-07-10 13:07:08
字体:
来源:转载
供稿:网友

最大的网站源码资源下载站,

在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

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表