kevdog114

Is there any straight forward way of creating code to get a snapshot of another application


Re: Visual Basic Language screenshots

TaDa

Here's the basics once you have the Window Handle.

Code Snippet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Saves This forms picture

'You can use FindWindow or other APIs to get window handle for

'Other app windows...

ScreenCapture(Me.Handle.ToInt64)

Me.Show()

'ScreenCapture(GetDesktopWindow())

End Sub

Private Declare Function GetDesktopWindow Lib "user32" () As Integer

Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Integer) As Integer

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Integer) As Integer

Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer

Private Const SRCCOPY = &HCC0020

Private Structure RECT

Dim Left As Integer

Dim Top As Integer

Dim Right As Integer

Dim Bottom As Integer

End Structure

Private Sub ScreenCapture(ByVal hWnd As Integer)

'Create a bitmap big enough to hold picture

Dim Rec As RECT

GetWindowRect(hWnd, Rec)

Dim myImage As Image = New Bitmap(Rec.Right - Rec.Left, Rec.Bottom - Rec.Top)

'Get the graphics object for the bitmap

Dim gr1 As Graphics = Graphics.FromImage(myImage)

'Get the device Context from the graphics object

Dim dc1 As IntPtr = gr1.GetHdc()

'Get the DC of the window you want to capture

Dim dc2 As Integer = GetWindowDC(hWnd) '***Use GetDC if you only want Client Portion of window...

'Copy the Other windows DC into the one we created

BitBlt(dc1.ToInt64, 0, 0, Rec.Right - Rec.Left, Rec.Bottom - Rec.Top, dc2, 0, 0, SRCCOPY)

'cleanup

gr1.ReleaseHdc(dc1)

'Save the bitmap...

myImage.Save("C:\temp.bmp", System.Drawing.Imaging.ImageFormat.Bmp)

End Sub





Re: Visual Basic Language screenshots

kevdog114

Thanks tada, that worked perfectly!!!...