vb抓图怎么放进picturebox

vb抓图怎么放进picturebox,第1张

Option Explicit

Private Declare Sub keybd_event Lib "user32" _

(ByVal bVk As Byte, _

ByVal bScan As Byte, _

ByVal dwFlags As Long, _

ByVal dwExtraInfo As Long)

Private Sub Command1_Click()

keybd_event vbKeySnapshot, 0&, 0&, 0&

DoEvents

Picture1Picture = ClipboardGetData(vbCFBitmap)

End Sub

这些不用你担心,这要你把Com导入进去,然后申明DllImport调用哪个方法。

其他的系统会自动做转换的,就是说C++类型会自己转化成C#类型的。

>

'添加如下声明

Private

Declare

Function

BringWindowToTop

Lib

"user32"

(ByVal

hwnd

As

Long)

As

Long

Private

Declare

Function

GetWindowRect

Lib

"user32"

(ByVal

hwnd

As

Long,

lpRect

As

RECT)

As

Long

Private

Declare

Function

GetWindowDC

Lib

"user32"

(ByVal

hwnd

As

Long)

As

Long

Private

Declare

Function

ReleaseDC

Lib

"user32"

(ByVal

hwnd

As

Long,

ByVal

hdc

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

Type

RECT

Left

As

Long

Top

As

Long

Right

As

Long

Bottom

As

Long

End

Type

'添加这个函数

Private

Sub

GetWndPic(Wnd

As

Long,

Pic

As

PictureBox)

Dim

R

As

RECT,

DC

As

Long

GetWindowRect

Wnd,

R

'获取指定窗口的左上角、右下角位置(以便获取其大小)

DC

=

GetWindowDC(Wnd)

'得到dc

With

Pic

AutoRedraw

=

True:

BorderStyle

=

0

ParentScaleMode

=

vbPixels

Move

Left,

Top,

RRight

-

RLeft,

RBottom

-

RTop

'使PictureBox适合大小

BringWindowToTop

Wnd

'目标窗口提到前面(非置顶)

BitBlt

hdc,

0,

0,

Width,

Height,

DC,

0,

0,

vbSrcCopy

'复制绘图

End

With

ReleaseDC

Wnd,

DC

'释放

End

Sub

'调用示例(把句柄131454的程序窗口截图放到Picture1中)

GetWndPic

131454,

Picture1

CWnd::GetDlgItem

CWnd GetDlgItem( int nID ) const;

void CWnd::GetDlgItem( int nID, HWND phWnd ) const;

返回值:

指向给定的控件或子窗口的指针,如果没有控件具有nID给出的整数ID,则返回NULL。

返回的指针可能是临时的,不能被保存以供将来使用。

参数: nID 指定了要获取的控件或子窗口的标识符。

phWnd 指向子窗口的指针。

说明:

这个函数获得对话框或其它窗口中指定控件或子窗口的指针。

返回的指针通常被强制转换为nID所标识的控件类型。

以上就是关于vb抓图怎么放进picturebox全部的内容,包括:vb抓图怎么放进picturebox、C#调用VC6做的com组件dll问题、vb 怎么获取指定句柄窗口的截图等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9320823.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存