'This function captures a screenshot of a window.
You have to pass the handle to the internet explorer page.
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 Function ScreenCapture(ByVal hWnd As Integer) As Image
'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...
Return myImage
End Function
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only