I have been using IHTML2Element for quite some time to thumbnail a WebBrowser screen’s image and it
works fine…except now xsl/xml rendered HTML is not available in IHTML2Element. I have developed code
to go after the memory address of the Desktop Window and have successfully thumb nailed the desktop
screen from memory with a form on it hosting a WebBrowser control on it. This is not a screen scrap
or copy from screen operation I have the desktop windows memory address and I am using StretchBlt from
that address in memory to a thumbnail.
Being able to use IHTMLElement to thumbnail WebBrowser controls allows me to create thumbnails of hosted
webBrowser without displaying them. This is what I am looking to do only now from finding the address
where webBrowser controls are fully rendered in memory.
I thought I could just use Me.WebBrowser1.handle and that would point to where the rendered HTML lives…
but that did not work.
The following code below works fine for the Desktop window:
Try
'Handle for the desktop window
Dim AddrDesktopWindow As IntPtr
If AddrDesktopWindow = 0 Then AddrDesktopWindow = GetDesktopWindow
'getWindow Size
Dim rcWindow As RECT
GetWindowRect(AddrDesktopWindow, rcWindow)
Dim WinHeight As Integer = rcWindow.Right - rcWindow.Left
Dim WinWidth As Integer = rcWindow.Bottom - rcWindow.Top
Dim PB1 As Graphics = Me.PictureBox1.CreateGraphics
Dim AddrOfPB1 As IntPtr = PB1.GetHdc
Dim AddrOfPictureBox1 As IntPtr = Me.PictureBox1.Handle
'create a compatible DC
Dim AddrCreateCompatibleDC As IntPtr = CreateCompatibleDC(IntPtr.Zero)
'create a memory bitmap in the DC just created, the size of the window we're capturing
Dim AddrCreateCompatibleBitmap As IntPtr = CreateCompatibleBitmap(AddrOfPB1, WinWidth, WinHeight)
'Prepare DC as a Bitmap using selectObject to configure the DC
SelectObject(AddrCreateCompatibleDC, AddrCreateCompatibleBitmap)
'copy the screen image into the DC
BitBlt(AddrCreateCompatibleDC, 0, 0, WinWidth, WinHeight, GetWindowDC(AddrDesktopWindow), 0, 0, SRCCOPY)
'Clone image of PictureBox1 to Picturebox2 when the IMAGE is in the Device Context
'#### BitBlt(AddrOfPB1, 0, 0, WinWidth, WinHeight, AddrCreateCompatibleDC, 0, 0, SRCCOPY)
StretchBlt(AddrOfPB1, 0, 0, 100, 100, AddrCreateCompatibleDC, 0, 0, WinWidth, WinHeight, TernaryRasterOperations.SRCCOPY)
PB1.ReleaseHdc(AddrOfPB1)
CType(PB1, IDisposable).Dispose()
DeleteDC(AddrCreateCompatibleDC)
DeleteObject(AddrCreateCompatibleBitmap)
Catch ex As System.NullReferenceException
MsgBox("--- NullReferenceException ---" & " " & _
vbCrLf & "Message --- " & ex.Message & " " & _
vbCrLf & "Source --- " & ex.Source & " " & _
vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _
vbCrLf & "TargetSite --- " & ex.TargetSite.ToString)
' Code reacting to NullReferenceException
Catch ex As Exception
' Code reacting to any exception
MsgBox(vbCrLf & "Message --- " & ex.Message & " " & _
vbCrLf & "Source --- " & ex.Source & " " & _
vbCrLf & "StackTrace --- " & ex.StackTrace & " " & _
vbCrLf & "TargetSite --- " & ex.TargetSite.ToString)
End Try
End Sub
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).