永发信息网

VB如何保存本窗体的截图 就像按alt+prtscr 保存窗体截图,但不要用发送按键 求大神解 ⊙

答案:2  悬赏:70  手机版
解决时间 2021-03-08 00:16
  • 提问者网友:浪荡绅士
  • 2021-03-07 08:31
VB如何保存本窗体的截图
就像按alt+prtscr
保存窗体截图,但不要用发送按键
求大神解
⊙▽⊙
最佳答案
  • 五星知识达人网友:琴狂剑也妄
  • 2021-03-07 08:46
'添加如下声明
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
全部回答
  • 1楼网友:像个废品
  • 2021-03-07 09:41
搜一下:VB如何保存本窗体的截图 就像按alt+prtscr 保存窗体截图,但不要用发送按键 求大神解 ⊙
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯