| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2087 人关注过本帖
标题:vb如何截图
只看楼主 加入收藏
香蕉0
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2010-10-22
结帖率:100%
收藏
 问题点数:0 回复次数:2 
vb如何截图
我用这段代码可以截图,但图片是整个屏幕的,我只要截取程序本身界面的图片就好,这段代码要如何改

程序代码:
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 RasterOpConstants) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Dim ctCi As Long

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000 '*****每隔 1000 毫秒(1秒)保存一次
Picture1.AutoRedraw = True: Picture1.ScaleMode = vbPixels
Picture1.Move 0, 0, Screen.Width, Screen.Height
Picture1.Visible = False
Me.Caption = "自动定时截屏"
Command1.Caption = "开始截屏"
End Sub

Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled Then Command1.Caption = "暂停截屏" Else Command1.Caption = "开始截屏"
End Sub

Private Sub Timer1_Timer()
Dim nDC As Long, dl As Long, nPath As String, nName As String

nPath = "d:\MyPic" '*****保存的目的文件夹
If Dir(nPath, 23) = "" Then MkDir nPath

nDC = GetWindowDC(0)
'dl 返回非零表示成功,零表示失败
dl = BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleWidth, nDC, 0, 0, vbSrcCopy)
ctCi = ctCi + 1
nName = ctCi
dl = 5 - Len(nName)
If dl > 0 Then nName = String(dl, "0") & nName
SavePicture Picture1.Image, nPath & "\P-" & nName & ".bmp" '***** P- 表示文件前缀
End Sub



搜索更多相关主题的帖子: 图片 
2011-01-23 14:21
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
程序代码:
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 RasterOpConstants) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Dim ctCi As Long

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000 '*****每隔 1000 毫秒(1秒)保存一次
Picture1.AutoRedraw = True: Picture1.ScaleMode = vbPixels
Picture1.Move 0, 0, Me.Width, Me.Height'---------改动了这里
Picture1.Visible = False
Me.Caption = "自动定时截屏"
Command1.Caption = "开始截屏"
End Sub

Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled Then Command1.Caption = "暂停截屏" Else Command1.Caption = "开始截屏"
End Sub

Private Sub Timer1_Timer()
Dim nDC As Long, dl As Long, nPath As String, nName As String

nPath = "d:\MyPic" '*****保存的目的文件夹
If Dir(nPath, 23) = "" Then MkDir nPath

nDC = GetWindowDC(Me.hwnd)'---------改动了这里
'dl 返回非零表示成功,零表示失败
dl = BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleWidth, nDC, 0, 0, vbSrcCopy)
ctCi = ctCi + 1
nName = ctCi
dl = 5 - Len(nName)
If dl > 0 Then nName = String(dl, "0") & nName
SavePicture Picture1.Image, nPath & "\P-" & nName & ".bmp" '***** P- 表示文件前缀
End Sub

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2011-01-23 16:20
香蕉0
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2010-10-22
收藏
得分:0 
万分感谢
2011-01-23 17:44
快速回复:vb如何截图
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034891 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved