重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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
创新互联公司成立于2013年,是专业互联网技术服务公司,拥有项目网站设计、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元盐津做网站,已为上家服务,为盐津各地企业和个人服务,联系电话:18980820575
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
'窗口上要放一个图片框和一个时钟控件。办法是把屏幕拷贝到图片框,再把图片框的Image保存到文件。
Private Sub Form_Load()
If Dir("D:\截图", vbDirectory) = "" Then MkDir "D:\截图"
Timer1.Enabled = False
Timer1.Interval = 1000
Picture1.Move 0, 0, Screen.Width, Screen.Height
Picture1.AutoRedraw = True
Picture1.Visible = False
End Sub
Private Sub Command1_Click()
Me.WindowState = vbMinimized '开始后把窗口最小化,否则自己也会拷贝进去
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Static imgIndex As Long
imgIndex = imgIndex + 1
BitBlt Picture1.hDC, 0, 0, Screen.Width \ Screen.TwipsPerPixelX, Screen.Height \ Screen.TwipsPerPixelY, GetDC(0), 0, 0, vbSrcCopy
SavePicture Picture1.Image, "D:\截图\" imgIndex ".bmp"
End Sub
VB.NT用的是触发事件,一按就会触发,要不你加个timer控件,延迟一秒
标题的问题:你先把图片保存,再加载
这是截屏代码,程序运行后3秒截屏,并在vb上显示且保存图片在d:\zt文件夹里。对于GetDC(GetActiveWindow), 0, 0, vbSrcCopy '抓屏中的0,0是截取的坐标,你可以调整坐标来控制截取的区域,0,0为全屏
Private Declare Function GetDC Lib "user32" (ByVal hwnd 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 Declare Function GetActiveWindow Lib "user32" () As Long
Dim a
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
On Error Resume Next
MkDir "d:\zt" '建文件夹
Me.AutoRedraw = True
End Sub
Private Sub Timer1_Timer()
a = a + 1
If a = 3 Then '三秒后开始抓屏
Me.Hide
BitBlt Me.hDC, 0, 0, Screen.Width, Screen.Height, _
GetDC(GetActiveWindow), 0, 0, vbSrcCopy '抓屏
Me.Show
Dim sFile As String
sFile = "d:\zt\" Format(Now, "yyyymmddhhmmss") ".BMP"
SavePicture Me.Image, sFile '保存Me.hDC
Timer1.Enabled = False
End If
End Sub
[DllImport("user32.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
先找到你要截图的那个窗体的 句柄 然后根据这个句柄得到改窗体的DC 创建一个bitmap 然后填充 得到的bitmap后 显示到picturebox里面