473,395 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Creating thumbnail of AxSHDocVw.AxWebBrowser

Ben
Hi all,

I am trying to write a little app that will generate a thumbnail image
of a website. Having searched the web I have found various bits of code
that appear to do the job and have written my app which works but only
sometimes! :(

The problem is - sometimes it returns a black image instead of the nice
screen shot. For example it sometimes works on the msn web site, never
works with the google web site and sometimes does not work with other
sites I try to thumbnail. The app is going to run as a console app- so
the webbrowser is not displayed on the screen. I am using the
AxSHDocVw.AxWebBrowser control to load the html page and waiting until
it has loaded the html.

Any pointers, help would be greatly appriciated

Cheers,

Ben

Here is the code I use to capture

Private Function GetHtmlBody() As IHTMLElement2

Dim wb2 As IWebBrowser2 = CType(m_IE.GetOcx(), IWebBrowser2)
Application.DoEvents()
Dim htmlDocument2 As IHTMLDocument2 = CType(wb2.Document,
IHTMLDocument2)
Application.DoEvents()
Return CType(htmlDocument2.body, IHTMLElement2)
End Function


Private Function CaptureImage() As Bitmap

Dim htmlDocument As IHTMLElement2 = GetHtmlBody()
Application.DoEvents()
Dim W As Integer = htmlDocument.scrollWidth

Dim H As Integer = htmlDocument.scrollHeight
Application.DoEvents()
If Not (m_IE.Height = H + 30) Or Not (m_IE.Width = W + 30) Then
m_IE.Height = H + 30

m_IE.Width = W + 30
End If

' Setup bitmap
Dim bitmapimg As Bitmap = New Bitmap(W, H, PixelFormat.Format24bppRgb)

Dim graphics_imgraphics As Graphics = Graphics.FromImage(bitmapimg)

Dim memdc As IntPtr = graphics_imgraphics.GetHdc()

Dim hbitmap As IntPtr = bitmapimg.GetHbitmap()

SelectObject(memdc, hbitmap)

Const PW_CLIENTONLY As Integer = &H1

Const WM_PRINT As Integer = &H317

Const PRF_NONCLIENT As Integer = &H2

Const PRF_CLIENT As Integer = &H4

Const PRF_ERASEBKGND As Integer = &H8

Const PRF_CHILDREN As Integer = &H10

Const PRF_OWNED As Integer = &H20

Const WM_PAINT As Integer = &HF

Dim rv As Integer

rv = SendMessage(m_IE.Handle, WM_PAINT, memdc, 0)

rv = SendMessage(m_IE.Handle, WM_PRINT, memdc, PRF_CHILDREN +
PRF_CLIENT + PRF_OWNED)
' Save image

Dim bitmapimg2 As Bitmap = Bitmap.FromHbitmap(hbitmap)

' Cleanup
DeleteObject(hbitmap)

graphics_imgraphics.ReleaseHdc(memdc)

graphics_imgraphics.Dispose()

bitmapimg.Dispose()
Return bitmapimg2
End Function

Jul 25 '06 #1
0 1283

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Elliott | last post by:
I have created an application that loads assemblies (plugins). These plugins are windows forms that have an embedded browser. private AxSHDocVw.AxWebBrowser browser; If I comment out...
3
by: Simon CJC | last post by:
Hello I use AxSHDocVw.AxWebBrowser in a windows application. But sometimes the url I browsed in AxSHDocVw.AxWebBrowser contains error caused by javascript. Can I prevent javascript from running in...
3
by: MPR | last post by:
Hi guys; I'm using an AxSHDocVw.AxWebBrowser control to show a web page. I need to know if i can ( and how? ) i do the following things: 1 - I need to follow 1 link in the webpage diplayed...
0
by: sagar.jawale | last post by:
Hi, In my c# windows application, i am using AxSHDocVw.AxWebBrowser. I am displaying a generated receipt html in this browser. Also, for printing the same html, i am using the following command...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.