Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

hooking into HTMLDocumentEvents2 in design mode

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hiren Patel - 29 Sep 2003 14:36 GMT
Hi can anybody help me.

I am trying to hook into HTMLDocumentEvents2_Events on a mshtml web browser
hosted in a windows form with the designMode turned on in the document. When
I don't hook into the events I am able to write inside the document but when
I hook into any event then when ever I type on the keyboard nothing gets
reflected back to the html document.

If someone has an answer to this problem. I would very gratefull for their
assistance

Thanks in advance

Hiren
Charles Law - 29 Sep 2003 16:31 GMT
Hi Hiren

This is caused by one of the (several) bugs in the WebBrowser control. The
solution follows. You will have to create your own class, as shown, that
implements the HTMLDocumentEvents2 interface. If you do this in VB.NET V2003
then the IDE will insert all the necessary methods for you.

Use the function below to hook the interface in the WebBrowser control. Make
sure you call this after you have initialised the control as it requires a
valid document to work. In the DocumentComplete event is a good place.

<code>
Private m_DocEvents2Cookie As Integer = -1

Private Sub EnableDocEvents()

   Dim icp As UCOMIConnectionPoint
   Dim icpc As UCOMIConnectionPointContainer
   Dim g As Guid

   g = GetType(mshtml.HTMLDocumentEvents2).GUID

   icpc = DirectCast(AxWebBrowser1.Document, UCOMIConnectionPointContainer)
   icpc.FindConnectionPoint(g, icp)

   If m_DocEvents2Cookie <> -1 Then
       icp.Unadvise(m_DocEvents2Cookie)
       m_DocEvents2Cookie = -1
   End If

   icp.Advise(New DocumentEvents2, m_DocEvents2Cookie)

   ' Wait until the browser has settled before returning
   Do Until AxWebBrowser1.ReadyState =
SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
       Application.DoEvents()
   Loop

End Sub

Public Class DocumentEvents2
   Implements mshtml.HTMLDocumentEvents2

   ' Implement each required sub and function
   ' Make sure to return True from every function by default
   ...

End Class
</code>

You can then write your own event handling code in the new class.

HTH

Charles

> Hi can anybody help me.
>
[quoted text clipped - 10 lines]
>
> Hiren

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.