vb 怎么获取指定句柄窗口的截图

如何获取指定句柄窗口的指定点的颜色呢... 如何获取指定句柄窗口的 指定点 的颜色呢 展开
 我来答
伯镶柏7k
推荐于2018-05-09 · TA获得超过2768个赞
知道小有建树答主
回答量:754
采纳率:0%
帮助的人:0
展开全部
'添加如下声明
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
.Parent.ScaleMode = vbPixels
.Move .Left, .Top, R.Right - R.Left, R.Bottom - R.Top '使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
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式