From: Sneha Menon on
Dear all,

I am working on a vb6 project where I am using webbrowser. Once the
url is loaded in the wb I want to take a snapshot of the webpage and
get it into a picturebox and use it for other purposes. Googled. Came
accross the phrase Convert HTML to Image, but could not reach any
useful material. (Found one in dotnet, html/webbrowser drawtoBitmap I
think). Is there any way to do that in VB6? Any ActiveX Ideas? API
stuff?. Please note:print screen type of screenshots wont serve the
purpose. Even in case other components or forms are partially covering
the wb, the snapshot should be complete.

Any Ideas, suggestions?

Regards.

Sneha

From: Eduardo on
Sneha Menon escribi�:
> Dear all,
>
> I am working on a vb6 project where I am using webbrowser. Once the
> url is loaded in the wb I want to take a snapshot of the webpage and
> get it into a picturebox and use it for other purposes. Googled. Came
> accross the phrase Convert HTML to Image, but could not reach any
> useful material. (Found one in dotnet, html/webbrowser drawtoBitmap I
> think). Is there any way to do that in VB6? Any ActiveX Ideas? API
> stuff?. Please note:print screen type of screenshots wont serve the
> purpose. Even in case other components or forms are partially covering
> the wb, the snapshot should be complete.
>
> Any Ideas, suggestions?

With help from:
http://www.vbforums.com/showthread.php?t=468596

' Add this code to a module:

' *********** Begin Module *********

Option Explicit

Public 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

Public Declare Function GetDC Lib "user32" _
(ByVal hWnd As Long) As Long

Private Declare Function GetClassName Lib "user32.dll" Alias _
"GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long

Private Declare Function EnumChildWindows Lib "user32.dll" ( _
ByVal hWndParent As Long, _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long _
) As Long

Private hWndIE As Long

Private Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As _
Long) As Long

Dim sClassName As String

sClassName = String(255, vbNullChar)
Call GetClassName(hWnd, sClassName, 255)
sClassName = Left$(sClassName, InStr(sClassName, vbNullChar) - 1)
If sClassName <> "Internet Explorer_Server" Then
EnumChildProc = 1
Else
hWndIE = hWnd
End If
End Function

Public Function GetBrowserHandle(ByVal hWndParent) As Long
hWndIE = 0
Call EnumChildWindows(hWndParent, AddressOf EnumChildProc, 1)
GetBrowserHandle = hWndIE
End Function

' *********** End Module *********

' Add a WebBrowser and a PictureBox to the Form
' and copy this code into the form's code module:

' *********** Begin Form *********

Private Sub CopyWebBrowserImageToPicture()
Dim iHwnd As Long
Dim iDC As Long

iHwnd = GetBrowserHandle(Me.hWnd)

iDC = GetDC(iHwnd)

Picture1.Width = WebBrowser1.Width
Picture1.Height = WebBrowser1.Height
Picture1.ScaleMode = vbPixels

BitBlt Picture1.hDC, 0, 0, Picture1.ScaleWidth, _
Picture1.ScaleHeight, iDC, 0, 0, vbSrcCopy

Set Picture1.Picture = Picture1.Image
End Sub


Private Sub Form_Load()
WebBrowser1.Navigate "http://www.yahoo.com"
Picture1.AutoRedraw = True
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp _
As Object, URL As Variant)

CopyWebBrowserImageToPicture
End Sub

' *********** End Form *********
From: Larry Serflaten on

"Eduardo" <mm(a)mm.com> wrote i

> > Is there any way to do that in VB6? Any ActiveX Ideas? API
> > stuff?. Please note:print screen type of screenshots wont serve the
> > purpose. Even in case other components or forms are partially covering
> > the wb, the snapshot should be complete.

> With help from:
> http://www.vbforums.com/showthread.php?t=468596


Did you try it? Unfortunately, it is no better than a screen snapshot.
The entire page has to be in view, or else it does not get copied...

LFS


From: Eduardo on
Larry Serflaten escribi�:

>>> Is there any way to do that in VB6? Any ActiveX Ideas? API
>>> stuff?. Please note:print screen type of screenshots wont serve the
>>> purpose. Even in case other components or forms are partially covering
>>> the wb, the snapshot should be complete.

> Did you try it? Unfortunately, it is no better than a screen snapshot.
> The entire page has to be in view, or else it does not get copied...

Emmm, sorry, I didn't pay much attention to the whole text of the post.
That code won't help actually, ignore it.
From: Mike Williams on
"Eduardo" <mm(a)mm.com> wrote in message news:h95v3n$age$1(a)aioe.org...

> Emmm, sorry, I didn't pay much attention to the whole
> text of the post. That code won't help actually, ignore it.

The following seems to work okay, although I haven't tested it fully and I
always have timing trouble when using any of the WebBrowser Control events
so the code to create the bitmap is in the click event of a button, which
should be clicked after the web page has visibly loaded. It obviously needs
a bit more work to solve the timing problem, but I can't seem to hit the
correct delay or find the right event that suits all web pages. Paste the
following into a Form containing a WebBrowser Control and a Picture Box and
a Command Button:

Mike

Option Explicit
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" (ByVal hwnd As Long, _
ByVal lpClassName As String, ByVal nMaxCount As Long) _
As Long
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CHILDREN = &H10&
Private Const PRF_CLIENT = &H4&
Private Const PRF_OWNED = &H20&
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2

Private Sub Form_Load()
Picture1.BorderStyle = vbBSNone
Picture1.AutoRedraw = True
Me.ScaleMode = vbTwips
WebBrowser1.Width = Screen.Width
WebBrowser1.Height = Screen.Height * 2
Picture1.Width = WebBrowser1.Width
Picture1.Height = WebBrowser1.Height
Picture1.Left = -Picture1.Width ' move off display
Picture1.Cls
Picture1.BorderStyle = vbBSNone
Picture1.AutoRedraw = True
WebBrowser1.Navigate "http://www.yahoo.co.uk"
Caption = "Click Button after web page has loaded . . ."
End Sub

Private Sub Command1_Click()
Dim myWindow As Long, childWindow As Long
Dim myClass As String, clsName As String * 256
Dim s1 As String
myClass = "Shell Embedding"
childWindow = GetWindow(Me.hwnd, GW_CHILD)
Do
GetClassName childWindow, clsName, 256
If Left$(clsName, Len(myClass)) = myClass Then
myWindow = childWindow
Exit Do
End If
childWindow = GetWindow(childWindow, GW_HWNDNEXT)
Loop While childWindow <> 0
If myWindow <> 0 Then
SendMessage myWindow, WM_PAINT, Picture1.hDC, 0
SendMessage myWindow, WM_PRINT, Picture1.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED
Picture1.Picture = Picture1.Image
s1 = "c:\temp\webpic1.bmp" ' or whatever is required
SavePicture Picture1.Picture, s1
Caption = "Web page saved as " & s1
End If
End Sub