Pulkit Gaur

dream - do - deserve

Ultra fast Screen Capture

Filed under: Visual Basic at 13:09:40 On 2006-06-29

This is one of the fastest and smallest method to capture screen.

I am putting this in visual basic to make easily understandable to newbees.


Visual basic timer object reports time 0 seconds for this operation !

Here goes the code.

'API Declarations

Private Declare Function CreateDCAsNull Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, lpDeviceName As Any, lpOutput As Any, lpInitData As Any) 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 DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

'Sub To be called
'For example Use : dumpScreenToPicturebox(picture1)

Public Sub dumpScreenToPicturebox(targetPictureBox As Control)

lngDesktopDC = CreateDCAsNull("DISPLAY", ByVal 0&, ByVal 0&, ByVal 0&)
BitBlt targetPictureBox.hdc, 0, 0, Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, lngDesktopDC, 0, 0, vbSrcCopy

End Sub

Hope it was useful !Cool

Leave a Comment


Required, hidden