Show VB6 forms when clicking link on html webbrowser page

I am working with VB6 WebBrowser. Here I need to open the vb6 form when the user clicks on some link to the link WebBrowser, for example

In HTML

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

I do not know how to do that. I thought that someday this could be done by a third text file, for example, when a link is clicked, it will write cod like 002in a text file.

And in vb form, the timer will check the file once per second, when the timer detects what the file contains 002, it will display the form.

Is it possible to do this with this method? or something else shorter, can I rule out?

+4
source share
3

, :

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

BeforeNavigate2, URL- , #vb-*, :

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
+5

, href, , data attribute , , .

href void(0), , VB .

WebBrowser, VB Microsoft Internet Controls, Microsoft HTML Library, , mshtml.tlb.

, WebBrowser "WebBrowser1", "Form1", "Form2" "Form3", , WebBrowser,

Private HTMLdoc As MSHTML.HTMLDocument

' Create a Web Page  to test the navigation
' You can skip this phase after your test are successfully executed
Private Sub Form_Load()
    Dim HTML As String
    WebBrowser1.Navigate "about:blank"
    HTML = "<html>"
    HTML = HTML & "<title>Open a VB Form from a Link</title>"
    HTML = HTML & "<body>"
    HTML = HTML & "<a data-vb='Form1' href='javascript:void(0)'>Click To show Form1</a>"
    HTML = HTML & "</br>"
    HTML = HTML & "<a data-vb='Form2' href='javascript:void(0)'>Click To show Form2</a>"
    HTML = HTML & "</br>"
    HTML = HTML & "<a data-vb='Form3' href='javascript:void(0)'>Click To show Form3</a>"
    HTML = HTML & "</br>"
    HTML = HTML & "</body>"
    HTML = HTML & "</html>"
    WebBrowser1.Document.Write HTML
End Sub

' This will load and show the form specified in the data-vb attribute of the link
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    Dim frm As Form, FormName as String
    If Not (WebBrowser1.Document Is Nothing) Then
        Set HTMLdoc = WebBrowser1.Document
        FormName = vbNullString & HTMLdoc.activeElement.getAttribute("data-vb")
        If Not FormName = vbNullString Then    
            Set frm = Forms.Add(FormName)
            frm.Show
        End If
    End If
End Sub

:

:

HTMLdoc.activeElement.toString

, :

javascript:void(0), URL BeforeNavigate.

, HTMLDocument BeforeNavigate, :

HTMLdoc.activeElement.outerHTML

:

<A href="javascript:void(0)" data-vb="Form2">Click To show Form2</A>
+5

To do this with a button instead of a link, add a button to the document and some javascript:

<input type="button" id="MyButton1_id" style="cursor: pointer" name=MyButton1 value="Show It!">

<SCRIPT LANGUAGE="VBScript">
Sub MyButton1_OnClick()
   location.href = "event:button1_show"
End Sub
</SCRIPT>

Then in the event BeforeNavigate2:

Public Sub webBrowser_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)

  Select Case LCase$(URL)
    Case "event:button1_show"
      Cancel = True
      Form2.Show
    Case "event:other_stuff"
      'other stuff to do, etc
  End Select
End Sub
+2
source

Source: https://habr.com/ru/post/1682909/


All Articles