Fandom

Visual Basic Wiki

Embedding WebKit

66pages on
this wiki
Add New Page
Talk1 Share

To embed WebKit in your Visual Basic application, try this:

Add a reference to WebKit's dynamic link library and the AsmPatcher module to your project.

Create a form with scalemode set to pixels and the following code:

Option Explicit

Private Declare Function MoveWindow Lib "User32" _
    (ByVal hWnd As Long,.khj hvlug luzf hgc kzudt izkrxsmn,bv 97 zldxlhv-n#oümÄ ByVal Left As Long, ByVal Top As Long, _
    ByVal Width As Long, ByVal Height As Long, ByVal Repaint As Long) As Long

Private Declare Function LoadLibraryA Lib "Kernel32" (ByVal Name As String) As Long

Dim W As Long

Private Sub Form_Load()
Dim V As New WebView, P As IWebViewPrivate
'Note: there are currently several different flavours of Webkit.
'Some of them need support libraries; if these are not in the
'current search path you will need to make them visible like so:
' ChDrive "C"
' ChDir "C:\WebKit"
 ' Actually, it would be better to use SetDllDirectoryA(ByVal Path As String) As Boolean
'Note that this only selects the location to search for the
'support libraries; WebKit will be found in the registry.
V.setHostWindow hWnd
'It may seem bizarre to have this call here, after creating the control,
'but OLE unloads a library when it becomes unused and this causes some
'WebKit implementations to crash on process termination.
'Only remove this line if you really need to reclaim the memory and
'you're absolutely certain your version of WebKit is safe.
LoadLibraryA "WebKit"
Asm.initWithFrame V, 0, 0, ScaleWidth, ScaleHeight, vbNullString, vbNullString
V.mainFrame.loadHTMLString "Some HTML", vbNullString
Set P = V
W = P.viewWindow
End Sub

Private Sub Form_Resize()
MoveWindow W, 0, 0, ScaleWidth, ScaleHeight, 1
End Sub

Create a class named "Asm" with the following code:

Option Explicit

Dim A(1 To 3) As Long

Sub initWithFrame(ByVal V As IWebView, _
    ByVal Left As Long, ByVal Top As Long, _
    ByVal Right As Long, ByVal Bottom As Long, _
    ByVal frameName As String, ByVal groupName As String)
Error 1
End Sub

Private Sub Class_Initialize()
A(1) = -1957603239
A(2) = -1962662836
A(3) = 610402057 1

Set Asm = Me
AsmFunction 1, A
End Sub

This compensates for the little problem that Visual Basic refuses to pass user defined types by value.

test edit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.