Tools Links Login

Screenshot Without Using Clipboard Or DIB

Seen many posts using api for printscreen keypress, but what about the info on clipboard? Seen others that copy clipboard to temp var, and set back after, but why waste resources and processing when you can do it the right way? Also seen classes using DIB, wayyy slow. This = best way! =D
This uses two tricks that arent very known, so here you go! When using GetDC(0) as our source, we actually capture the screen, and when using picture.image=picture.picture.

Original Author: DanDaMan

Assumptions

Always make sure the Picturebox has AutoRedraw enabled. Create a Command1, and in it call ScreenShot()

Returns

A screenshot in the app folder called screenshot.bmp

API Declarations

Bitblt and GetDC

Code

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 GetDC Lib "USER32" (ByVal hwnd As Long) As Long
Private Sub ScreenShot()
  'Important Precursors
  'All these can be set in form load
  'The Picturebox can also be Visible=False
  'and this will still work
  Picture1.Width = Screen.Width
  Picture1.Height = Screen.Height
  Picture1.AutoRedraw = True
  BitBlt Picture1.hDC, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, GetDC(0), 0, 0, vbSrcCopy
  Picture1.Picture = Picture1.Image
  SavePicture Picture1.Picture, App.Path & "/screen.bmp"
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 112 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.