Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. MSHTML Advanced Hosting Interfaces VB.Net

MSHTML Advanced Hosting Interfaces VB.Net

Scheduled Pinned Locked Moved Visual Basic
csharpcomhtmlhosting
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gene Sivorot
    wrote on last edited by
    #1

    I am trying to convert the C# example of MSHTML Advanced Hosting Interfaces to VB.Net. The article can be found under C# programming -> Com Interop -> Using MSHTML Advanced Hosting Interfaces, or at http://www.codeproject.com/csharp/advhost.asp Anyways, this is the translated code but it doesn't seem to work. Any help would be greatly appreciated. I tried to convert the code from C# to VB.Net but it doesn't seem to be working. The application won't pick up the Button Clicked Events. I have an html file called start.htm with two buttons...Open FileNew File. I'm not sure exactly what is wrong but here is my code. Imports MsHtmHstInterop Imports MSHTML Imports AxSHDocVw Public Class frmChild Inherits System.Windows.Forms.Form Implements IDocHostUIHandler 'Windows Form Designer generated code, including protected webStart as AxWebBrowser Protected Sub InitializeBrowsers() Dim o As Object Dim theLoc As String = Application.StartupPath webStart.Navigate("about:blank", o, o, o, o) Dim cDoc As ICustomDoc = CType(webStart.Document, ICustomDoc) cDoc.SetUIHandler(CType(Me, IDocHostUIHandler)) webStart.Navigate(theLoc & "\html\start.htm", o, o, o) End Sub Private Sub WebBrowser_DocumentComplete(ByVal sender As Object, _ ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) _ Handles webStart.DocumentComplete ' Get the document Dim doc As IHTMLDocument2 = CType(webStart.Document, IHTMLDocument2) ' Get references to the buttons Dim btnOpen As HTMLButtonElement = CType(doc.all.item("btnOpen", Nothing), HTMLButtonElement) Dim btnNew As HTMLButtonElement = CType(doc.all.item("btnNew", Nothing), HTMLButtonElement) ' Attach the event handlers with the events interface AddHandler CType(btnOpen, HTMLButtonElementEvents2_Event).onclick, _ New HTMLButtonElementEvents2_onclickEventHandler(AddressOf Me.ButtonOpen_onclick) AddHandler CType(btnNew, HTMLButtonElementEvents2_Event).onclick, _ New HTMLButtonElementEvents2_onclickEventHandler(AddressOf Me.ButtonNew_onclick) End Sub Private Function ButtonOpen_onclick(ByVal e As IHTMLEventObj) As Boolean MsgBox("Alert from the app: Received HTMLElement btnOpen.onclick Event!") Return True End Function Private Function ButtonNew_onclick(ByVal e As IHTMLEventObj) As Boolean MsgBox("Alert from the app: Received HTMLElement btnNew.onclick Event!") Return True End Function ''''''''''''''''''''''''''''''''''''' ' IDocHostUIHandler implementation ' ''''''''''''''''''''''''''''''''''''' Sub EnableModeless(ByVal fEnable As

    T 1 Reply Last reply
    0
    • G Gene Sivorot

      I am trying to convert the C# example of MSHTML Advanced Hosting Interfaces to VB.Net. The article can be found under C# programming -> Com Interop -> Using MSHTML Advanced Hosting Interfaces, or at http://www.codeproject.com/csharp/advhost.asp Anyways, this is the translated code but it doesn't seem to work. Any help would be greatly appreciated. I tried to convert the code from C# to VB.Net but it doesn't seem to be working. The application won't pick up the Button Clicked Events. I have an html file called start.htm with two buttons...Open FileNew File. I'm not sure exactly what is wrong but here is my code. Imports MsHtmHstInterop Imports MSHTML Imports AxSHDocVw Public Class frmChild Inherits System.Windows.Forms.Form Implements IDocHostUIHandler 'Windows Form Designer generated code, including protected webStart as AxWebBrowser Protected Sub InitializeBrowsers() Dim o As Object Dim theLoc As String = Application.StartupPath webStart.Navigate("about:blank", o, o, o, o) Dim cDoc As ICustomDoc = CType(webStart.Document, ICustomDoc) cDoc.SetUIHandler(CType(Me, IDocHostUIHandler)) webStart.Navigate(theLoc & "\html\start.htm", o, o, o) End Sub Private Sub WebBrowser_DocumentComplete(ByVal sender As Object, _ ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) _ Handles webStart.DocumentComplete ' Get the document Dim doc As IHTMLDocument2 = CType(webStart.Document, IHTMLDocument2) ' Get references to the buttons Dim btnOpen As HTMLButtonElement = CType(doc.all.item("btnOpen", Nothing), HTMLButtonElement) Dim btnNew As HTMLButtonElement = CType(doc.all.item("btnNew", Nothing), HTMLButtonElement) ' Attach the event handlers with the events interface AddHandler CType(btnOpen, HTMLButtonElementEvents2_Event).onclick, _ New HTMLButtonElementEvents2_onclickEventHandler(AddressOf Me.ButtonOpen_onclick) AddHandler CType(btnNew, HTMLButtonElementEvents2_Event).onclick, _ New HTMLButtonElementEvents2_onclickEventHandler(AddressOf Me.ButtonNew_onclick) End Sub Private Function ButtonOpen_onclick(ByVal e As IHTMLEventObj) As Boolean MsgBox("Alert from the app: Received HTMLElement btnOpen.onclick Event!") Return True End Function Private Function ButtonNew_onclick(ByVal e As IHTMLEventObj) As Boolean MsgBox("Alert from the app: Received HTMLElement btnNew.onclick Event!") Return True End Function ''''''''''''''''''''''''''''''''''''' ' IDocHostUIHandler implementation ' ''''''''''''''''''''''''''''''''''''' Sub EnableModeless(ByVal fEnable As

      T Offline
      T Offline
      Todd Smith
      wrote on last edited by
      #2

      Somewhere in there you need to connect to the browser instance to receive events. At least that's what I had to do under ATL. I don't see that anywhere in your code. I think I use AtlAdvise and AtlUnadvise? Todd Smith

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups