home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Antipop_-_871035262002.psc / cBrowserEvents.cls < prev    next >
Encoding:
Visual Basic class definition  |  2002-05-26  |  7.2 KB  |  190 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cBrowserEvents"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Event BrowserNavigating(Browser As SHDocVw.InternetExplorer, ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
  16. Event DocumentComplete(Browser As SHDocVw.InternetExplorer, pDisp As Object, URL As Variant)
  17. Event DownLoadBegin(Browser As SHDocVw.InternetExplorer)
  18. Event DownLoadComplete(Browser As SHDocVw.InternetExplorer)
  19. Event FileDownload(Browser As SHDocVw.InternetExplorer, Cancel As Boolean)
  20. Event NavigateComplete(Browser As SHDocVw.InternetExplorer, ByVal pDisp As Object, URL As Variant)
  21. Event NavigateError(Browser As SHDocVw.InternetExplorer, ByVal pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
  22. Event NewWindow(Browser As SHDocVw.InternetExplorer, ppDisp As Object, Cancel As Boolean)
  23. Event OnFullScreen(Browser As SHDocVw.InternetExplorer, ByVal FullScreen As Boolean)
  24. Event ProgressChange(Browser As SHDocVw.InternetExplorer, ByVal Progress As Long, ByVal ProgressMax As Long)
  25. Event TitleChange(Browser As SHDocVw.InternetExplorer, ByVal Text As String)
  26. Event WindowClosing(Browser As SHDocVw.InternetExplorer, ByVal IsChildWindow As Boolean, Cancel As Boolean)
  27. Event BrowserCreated(Browser As SHDocVw.InternetExplorer)
  28. Event BrowserDestroyed()
  29.  
  30. Implements IBrowser ' Implement the IBrowser Interface Class
  31. Private m_OwnerBrCollClass As cBrowsers ' Internal ref to cBrowsers collection class
  32. Private m_oBrowser As SHDocVw.InternetExplorer
  33. Private WithEvents m_oShell As SHDocVw.ShellWindows
  34. Attribute m_oShell.VB_VarHelpID = -1
  35. Dim coll As New Collection ' Hold all of our instances in internal collection
  36. Private Sub Class_Initialize()
  37.     SyncCollection
  38. End Sub
  39. '#####################################################################
  40. '#Author    : Richard Friend,                                        #
  41. '#Date      : Wed Sep 2001 10:09:55                                  #
  42. '#Comments  :                                                        #
  43. '#####################################################################
  44. Private Function KeyInCollection(col As Collection, strKey As String)
  45.     On Error Resume Next
  46.     col.Item strKey
  47.     KeyInCollection = Err.Number = 0
  48. End Function
  49. 'Sycronise Both the Internal Events Collection
  50. 'And our public collection exposed
  51. Friend Sub SyncCollection()
  52.     
  53.     Dim oTemp As SHDocVw.InternetExplorer
  54.     Dim oo As cBrowser
  55.     Dim sTemp As String
  56.     Set m_oShell = Nothing 'Destroy ShellWindow object
  57.     Set coll = Nothing 'Destroy Collection
  58.     Set m_oShell = New SHDocVw.ShellWindows
  59.     If Not m_OwnerBrCollClass Is Nothing Then
  60.         m_OwnerBrCollClass.Clear
  61.     End If
  62.     For Each oTemp In m_oShell
  63.         Set oo = New cBrowser
  64.         Set oo.InterFace = Me
  65.         Set oo.Browser = oTemp
  66.         sTemp = ""
  67.         While KeyInCollection(coll, "_" & oo.Browser.hwnd & "_" & sTemp)
  68.             'This window has Child windows using the same HWND
  69.             sTemp = CStr(CLng(Val(sTemp)) + 1)
  70.             'Append Our Child Instane Number to the key
  71.         Wend
  72.         coll.Add oo, "_" & oo.Browser.hwnd & "_" & sTemp
  73.         If Not m_OwnerBrCollClass Is Nothing Then
  74.             m_OwnerBrCollClass.AddItem oTemp
  75.         End If
  76.     Next oTemp
  77.     
  78. End Sub
  79. Friend Sub SetOwnerBrowserCollection(pBrColl As cBrowsers)
  80.     Set m_OwnerBrCollClass = pBrColl
  81. End Sub
  82. Private Function GetNewestInstance() As SHDocVw.InternetExplorer
  83.     Dim oTempBr As SHDocVw.InternetExplorer
  84.     Dim oTempBr2 As cBrowser
  85.     Dim blnFound As Boolean
  86.     Dim lCount As Long
  87.     For Each oTempBr In m_oShell
  88.         blnFound = False
  89. '        Debug.Print oTempBr.hwnd
  90.         For Each oTempBr2 In coll
  91.             If oTempBr2.Browser.hwnd = oTempBr.hwnd Then
  92.                 blnFound = True
  93.             End If
  94.         Next oTempBr2
  95.         If Not blnFound Then
  96.             Set GetNewestInstance = oTempBr 'Newest instance
  97.             Exit For
  98.         End If
  99.     Next oTempBr
  100.     Set oTempBr2 = Nothing
  101. End Function
  102.  
  103. Private Sub Class_Terminate()
  104.     Set coll = Nothing
  105. End Sub
  106.  
  107. Private Sub IBrowser_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
  108.     RaiseEvent BrowserNavigating(m_oBrowser, pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel)
  109. End Sub
  110.  
  111. Private Sub IBrowser_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  112.     RaiseEvent DocumentComplete(m_oBrowser, pDisp, URL)
  113. End Sub
  114.  
  115. Private Sub IBrowser_DownloadBegin()
  116. '
  117.     RaiseEvent DownLoadBegin(m_oBrowser)
  118. End Sub
  119.  
  120. Private Sub IBrowser_DownloadComplete()
  121. '
  122.     RaiseEvent DownLoadComplete(m_oBrowser)
  123. End Sub
  124.  
  125. Private Sub IBrowser_FileDownload(Cancel As Boolean)
  126. '
  127.     RaiseEvent FileDownload(m_oBrowser, Cancel)
  128. End Sub
  129.  
  130. Private Sub IBrowser_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
  131. '
  132.     RaiseEvent NavigateComplete(m_oBrowser, pDisp, URL)
  133. End Sub
  134.  
  135. Private Sub IBrowser_NavigateError(ByVal pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
  136. '
  137.     RaiseEvent NavigateError(m_oBrowser, pDisp, URL, Frame, StatusCode, Cancel)
  138. End Sub
  139.  
  140. Private Sub IBrowser_NewWindow2(ppDisp As Object, Cancel As Boolean)
  141. '
  142.     RaiseEvent NewWindow(m_oBrowser, ppDisp, Cancel)
  143. End Sub
  144.  
  145. Private Sub IBrowser_OnFullScreen(ByVal FullScreen As Boolean)
  146. '
  147.     RaiseEvent OnFullScreen(m_oBrowser, FullScreen)
  148. End Sub
  149.  
  150. Private Sub IBrowser_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
  151. '
  152.     RaiseEvent ProgressChange(m_oBrowser, Progress, ProgressMax)
  153. End Sub
  154.  
  155. Private Sub IBrowser_SetBrowserInst(Browser As SHDocVw.IWebBrowser2)
  156.     Set m_oBrowser = Browser
  157. End Sub
  158.  
  159. Private Sub IBrowser_TitleChange(ByVal Text As String)
  160. '
  161.     RaiseEvent TitleChange(m_oBrowser, Text)
  162. End Sub
  163.  
  164. Private Sub IBrowser_WindowClosing(ByVal IsChildWindow As Boolean, Cancel As Boolean)
  165. '
  166.     RaiseEvent WindowClosing(m_oBrowser, IsChildWindow, Cancel)
  167. End Sub
  168.  
  169. Private Sub m_oShell_WindowRegistered(ByVal lCookie As Long)
  170.     Dim oTempBrowser As SHDocVw.InternetExplorer
  171.     Set oTempBrowser = GetNewestInstance
  172.     'Lets get the new browser in the ShellWindows collection
  173.     'By comparing it against our Internal collection
  174.     'We must do this before we update our internal collection
  175.     If oTempBrowser Is Nothing Then
  176.         'This occurs when you click to open a new window
  177.         'The windows have the same HWND!!!
  178.         'dont raise an event since the NewWindow2 event will raise!
  179.     Else
  180.         SyncCollection 'Update our collection before raising the event!
  181.         RaiseEvent BrowserCreated(oTempBrowser)
  182.     End If
  183.     
  184. End Sub
  185.  
  186. Private Sub m_oShell_WindowRevoked(ByVal lCookie As Long)
  187.     SyncCollection 'Update our collection
  188.     RaiseEvent BrowserDestroyed
  189. End Sub
  190.