Search code examples
javascripthtmlvb6webbrowser-control

Show VB6 forms when click a link in html page of webbrowser


I am working with VB6 WebBrowser, Here i need to open a vb6 form when user click any particular link of WebBrowser's link like

In HTML

<html>
<head>
<body>
<a href="--show vb6 form--">Click To show VB6 Form2</a>
</body>
</html>

I do't have any idea how to do it. I thought sometime it can be done a third text file like when the link clicked will write a cod like 002 in a text file.

And the in vb form a Timer will check once a second the file, when timer detect the file contains 002 it will show the form.

Can be do this by this method? or anything else shorter i can except?


Solution

  • Pick a better naming scheme like:

    <a href="#vb-showform2">Click To show VB6 Form2</a>
    <a href="#vb-waffles">Waffles</a>
    

    Then intercept link clicks via the BeforeNavigate2 event, look at the url and if it matches #vb-* run your code:

    Private Sub WebBrowserCtrl_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    
        '// get #vb-XXX command from url
        Dim pos As Long: pos = InStrRev(URL, "#vb-")
    
        If pos Then
            Cancel = True '// stop default navigation
    
            URL = Mid$(URL, pos + 4)
    
            Select Case LCase$(URL)
                Case "showform2": Form2.Show
                '...
                Case "waffles":   MsgBox "Waffles."
                Case Else:        MsgBox "Unknown Command " & URL
            End Select
        End If
    
    End Sub