VB中,如何将VB程序窗口截图并保存在某个位置?
如题,比如说,一个VB程序,经过操作后,想把成果用图片的形势保存下来欣赏。可以用WINDOWS的截屏键,但是太麻烦还要打开画图剪切。能不能编写某功能,使程序窗口内的内容保...
如题,比如说,一个VB程序,经过操作后,想把成果用图片的形势保存下来欣赏。可以用WINDOWS的截屏键,但是太麻烦还要打开画图剪切。能不能编写某功能,使程序窗口内的内容保存为一图片(假如是JPG,保存在C:\AAA)?类似于游戏,网络游戏里有截屏键,可以保存游戏画面的,我也想在VB上实现这个保存程序画面的功能。
请高手大师们亲自用VB编一下,否则不成功我是不会放分的。 展开
请高手大师们亲自用VB编一下,否则不成功我是不会放分的。 展开
2个回答
2013-12-05
展开全部
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetDC 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 Const SRCCOPY = &HCC0020
Sub ScreenSave(FilePath As String)
Dim lngDesktopHwnd As Long
Dim lngDesktopDC As Long
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
lngDesktopHwnd = GetDesktopWindow
lngDesktopDC = GetDC(lngDesktopHwnd)
'filePath为截屏要保存的路径
FilePath = "E:\a.jpg"
Me.Visible = False
Me.WindowState = 2
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height
'这里注释是测试用,正常使用时设置FALSE
' Picture1.Visible = False
Call BitBlt(Picture1.hdc, 0, 0, Screen.Width, Screen.Height, lngDesktopDC, 0, 0, SRCCOPY)
Picture1.Picture = Picture1.Image
Call ReleaseDC(lngDesktopHwnd, lngDesktopDC)
Me.Visible = True
SavePicture Picture1, FilePath '保存图片
End Sub
Private Sub Command1_Click()
ScreenSave "FilePath"
End Sub
Private Declare Function GetDC 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 Const SRCCOPY = &HCC0020
Sub ScreenSave(FilePath As String)
Dim lngDesktopHwnd As Long
Dim lngDesktopDC As Long
Picture1.AutoRedraw = True
Picture1.ScaleMode = vbPixels
lngDesktopHwnd = GetDesktopWindow
lngDesktopDC = GetDC(lngDesktopHwnd)
'filePath为截屏要保存的路径
FilePath = "E:\a.jpg"
Me.Visible = False
Me.WindowState = 2
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height
'这里注释是测试用,正常使用时设置FALSE
' Picture1.Visible = False
Call BitBlt(Picture1.hdc, 0, 0, Screen.Width, Screen.Height, lngDesktopDC, 0, 0, SRCCOPY)
Picture1.Picture = Picture1.Image
Call ReleaseDC(lngDesktopHwnd, lngDesktopDC)
Me.Visible = True
SavePicture Picture1, FilePath '保存图片
End Sub
Private Sub Command1_Click()
ScreenSave "FilePath"
End Sub
2013-12-05
展开全部
VB难死了 考试都没过
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询