HTMLViewer to Canvas - Webkit vs Native

After getting my JSON query working properly the other day I’ve come across another problem I can’t seem to solve.

I have a window with a HTMLViewer on it. On open I’m loading a URL


I have a push button on the window as well as a canvas. I’m trying to capture an image of the HTMLViewer and place it into the canvas.

This is the code in my push button:

// Set up the varables for screen Width/Height Dim htmlwinwidth As Integer Dim htmlwinheigth As Integer htmlwinwidth = self.Width htmlwinheigth = self.Height // Set the canvas1 to the same size as the road map screen Canvas1.Width = HTMLViewer1.Width Canvas1.Height = HTMLViewer1.Height // Fill the canvas backdrop with the map from the htmlviewer Canvas1.Backdrop = GetMapFromHTMLViewer(htmlwinwidth,htmlwinheigth,HTMLViewer1)

This is my code for GetMapFromHTMLViewer method:

[code] Private Function GetMapFromHTMLViewer(MapWidth as Integer, MapHeight as Integer, MapViewer as HTMLViewer) As Picture
//Declare all the Windows Junk
Declare Function GetDC Lib “User32” (HWND As Integer) As Integer
Declare Function BitBlt Lib “GDI32” (DCdest As Integer, xDest As Integer, yDest As Integer, nWidth As Integer, nHeight As Integer, _
DCdource As Integer, xSource As Integer, ySource As Integer, rasterOp As Integer) As Boolean
Declare Function ReleaseDC Lib “User32” (HWND As Integer, DC As Integer) As Integer

//Let's get two constants...winxp and under didn't have captureblt so we'll hafta use srccopy :-)
Const CAPTUREBLT = &h40000000
Const SRCCOPY = &HCC0020

//Create a Picture object to hold our hooked screenshot
Dim screenCap As New Picture(winGoogleMap.HTMLViewer1.Width, winGoogleMap.HTMLViewer1.Height, 24)
//Get the "Real" HTMLViewer Handle for Capture..Xojo returns a bogus 'pseudo handle'
Dim HTMLViewerDC as Integer = GetDC(winGoogleMap.HTMLViewer1.Handle)

//Grab that snapshot of the HTMLViewer
Call BitBlt(screenCap.Graphics.Handle(1),0,0,winGoogleMap.HTMLViewer1.Width ,   winGoogleMap.HTMLViewer1.Height , HTMLViewerDC, -2, -2, SRCCOPY or CAPTUREBLT)
//Function may be called lets release the object to prevent memory leak...
Call ReleaseDC(winGoogleMap.HTMLViewer1.Handle, HTMLViewerDC)
//Return our "Snapshot"
Return screenCap

End Function

Preface: Yes, I found much of this code on the forums and works great but not perfect for my use.

If I have my HTMLViewer set to the NATIVE type I am able to get a good picture placed into my canvas. If I switch it to Webkit I’m left with a white box the size of my HTMLViewer.

Why have can’t I use NATIVE? When accessing the google maps site I’m not able to get the pin drop to show with Native. Using webkit I get the pin drop. I’m using the pin drop to have a user verify where they entered an address then doing a query to get the lat/lon to enter into a database to do some reporting. I’ve entered lat/lon on the code above only because I’m testing right now but eventually it’ll be dynamic.

Any thoughts on why I can’t get a graphics object from a HTMLViewer when it is set to Webkit?

I have exactly the same issue. Can anyone have any idea?

This post is more than two years old. It would have been more beneficial for everyone involved if you had started your own thread, posted the code you’ve tried, and what has and hasn’t worked for you.

Thanks for your comment.

I just tried to follow the workaround Michel Bujardet posted, it works really well!

Thank you.