展开全部
'添加如下声明
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
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
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询