Internet Explorer Object in VB

hello, I'm using Internet Explorer object, actually i've added my button in the Internet Explorer Toolbar. By pressing my button i want to get the contents(html contents) which are displaying in browser, or get the local path of that html document from Temporary Internet Files folder.
thanks the code is as follows.



Option Explicit

' ····----==== Interfaces ====----····

Implements IObjectWithSite
Implements olelib2.IOleCommandTarget

' ····----==== Private Fields ====----····

Private m_oSite As IUnknown
Private m_oIE As InternetExplorer

' ····----==== APIs ====----····

Private Type INTERNET_CACHE_ENTRY_INFO
   dwStructSize As Long
   lpszSourceUrlName As Long
   lpszLocalFileName As Long
   CacheEntryType  As Long
   dwUseCount As Long
   dwHitRate As Long
   dwSizeLow As Long
   dwSizeHigh As Long
   LastModifiedTime As Currency
   ExpireTime As Currency
   LastAccessTime As Currency
   LastSyncTime As Currency
   lpHeaderInfo As Long
   dwHeaderInfoSize As Long
   lpszFileExtension As Long
   dwExemptDelta  As Long
   '
   Buffer(0 To 1023) As Byte
End Type

Const NORMAL_CACHE_ENTRY As Long = &H1

Private Declare Function FindFirstUrlCacheEntry Lib "wininet" _
   Alias "FindFirstUrlCacheEntryA" ( _
   ByVal lpszUrlSearchPattern As String, _
   lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
   lpdwFirstCacheEntryInfoBufferSize As Long) As Long

Private Declare Function FindNextUrlCacheEntry Lib "wininet" _
   Alias "FindNextUrlCacheEntryA" ( _
   ByVal hEnumHandle As Long, _
   lpNextCacheEntryInfo As Any, _
   lpdwNextCacheEntryInfoBufferSize As Long) As Long

Private Declare Function FindCloseUrlCache Lib "wininet" ( _
   ByVal hEnumHandle As Long) As Long

Private Declare Function DeleteUrlCacheEntry Lib "wininet" _
   Alias "DeleteUrlCacheEntryA" ( _
   ByVal lpszUrlName As String) As Long

Private Declare Function lstrcpyA Lib "kernel32" ( _
  ByVal RetVal As String, _
  ByVal Ptr As Long) As Long
                       
Private Declare Function lstrlenA Lib "kernel32" ( _
  ByVal Ptr As Any) As Long

' ····----==== IObjectWithSite Methods ====----····

Private Sub IObjectWithSite_GetSite(riid As olelib.UUID, ppvSite As stdole.IUnknown)
Dim oUnk As olelib.IUnknown

   ' Get the IUnknown interface
   Set oUnk = m_oSite
   
   ' Query for the interface
   oUnk.QueryInterface riid, ppvSite

End Sub

Private Sub IObjectWithSite_SetSite(ByVal pUnkSite As stdole.IUnknown)
   
   ' Store the site
   Set m_oSite = pUnkSite
   
   If pUnkSite Is Nothing Then
      Set m_oIE = Nothing
   Else
      ' Get the InternetExplorer object
      Set m_oIE = GetIE(pUnkSite)
   End If
   
End Sub

' ····----==== IOleCommandTarget methods ====----····

Private Sub IOleCommandTarget_Exec(pguidCmdGroup As olelib.UUID, ByVal nCmdID As Long, ByVal nCmdexecopt As olelib.OLECMDEXECOPT, pvaIn As Variant, pvaOut As Variant)

   ' Clean the temporary folder
   'CleanTemporaryFolder
   
    m_oIE.StatusText = "My Button is pressed."

    MsgBox "m_oIE.Document" & m_oIE.Document
    MsgBox "m_oIE.LocationName" & m_oIE.LocationName
    MsgBox "m_oIE.LocationURL" & m_oIE.LocationURL
    MsgBox "m_oIE.Name" & m_oIE.Name
    MsgBox "m_oIE.Path" & m_oIE.Path
    MsgBox "m_oIE.hWnd" & m_oIE.hWnd
    MsgBox "m_oIE.Parent" & m_oIE.Parent
    MsgBox "m_oIE.Application" & m_oIE.Application
    MsgBox "m_oIE.AddressBar" & m_oIE.AddressBar

End Sub


Private Sub IOleCommandTarget_QueryStatus(pguidCmdGroup As olelib.UUID, ByVal cCmds As Long, prgCmds As olelib.OLECMD, pCmdText As olelib.OLECMDTEXT)

   ' Always enabled
   prgCmds.cmdf = OLECMDF_ENABLED
   
End Sub

' ····----==== Other methods ====----····

Private Function GetIE( _
   ByVal ServiceProvider As olelib.IServiceProvider) As IWebBrowserApp
Dim IID_IWebBrowserApp As olelib.UUID
 
   CLSIDFromString IIDSTR_IWebBrowserApp, IID_IWebBrowserApp
   
   ServiceProvider.QueryService IID_IWebBrowserApp, _
                                IID_IWebBrowserApp, _
                                GetIE
         
End Function

Private Sub CleanTemporaryFolder()
Dim lHandle As Long
Dim tEI As INTERNET_CACHE_ENTRY_INFO
Dim sURL As String

   tEI.dwStructSize = Len(tEI)

   lHandle = FindFirstUrlCacheEntry(vbNullString, tEI, Len(tEI))
   
   If lHandle <> 0 Then
     
      Do
         
         If (tEI.CacheEntryType And NORMAL_CACHE_ENTRY) <> 0 Then
            sURL = StringFromPointer(tEI.lpszSourceUrlName)
            m_oIE.StatusText = "Deleting " & sURL
            'MsgBox ""
            'DeleteUrlCacheEntry sURL
            DoEvents
         End If
         
      Loop While FindNextUrlCacheEntry(lHandle, tEI, Len(tEI))
     
      FindCloseUrlCache lHandle
     
   End If
   'MsgBox "StringFromPointer(tEI.Buffer)" & StringFromPointer(tEI.Buffer)
   'MsgBox "StringFromPointer(tEI.CacheEntryType)" & StringFromPointer(tEI.CacheEntryType)
   'MsgBox "StringFromPointer(tEI.dwExemptDelta)" & StringFromPointer(tEI.dwExemptDelta)
   'MsgBox "StringFromPointer(tEI.dwHeaderInfoSize)" & StringFromPointer(tEI.dwHeaderInfoSize)
   'MsgBox "StringFromPointer(tEI.dwHitRate)" & StringFromPointer(tEI.dwHitRate)
   'MsgBox "StringFromPointer(tEI.dwSizeHigh)" & StringFromPointer(tEI.dwSizeHigh)
   'MsgBox "StringFromPointer(tEI.dwSizeLow)" & StringFromPointer(tEI.dwSizeLow)
   'MsgBox "StringFromPointer(tEI.dwStructSize)" & StringFromPointer(tEI.dwStructSize)
   'MsgBox "StringFromPointer(tEI.ExpireTime)" & StringFromPointer(tEI.ExpireTime)
   'MsgBox "StringFromPointer(tEI.LastAccessTime)" & StringFromPointer(tEI.LastAccessTime)
   'MsgBox "StringFromPointer(tEI.LastModifiedTime)" & StringFromPointer(tEI.LastModifiedTime)
   'MsgBox "StringFromPointer(tEI.LastSyncTime)" & StringFromPointer(tEI.LastSyncTime)
   'MsgBox "StringFromPointer(tEI.lpHeaderInfo)" & StringFromPointer(tEI.lpHeaderInfo)
   'MsgBox "StringFromPointer(tEI.lpszFileExtension)" & StringFromPointer(tEI.lpszFileExtension)
   'MsgBox "StringFromPointer(tEI.lpszSourceUrlName)" & StringFromPointer(tEI.lpszSourceUrlName)
   'MsgBox "StringFromPointer(tEI.lpszLocalFileName)" & StringFromPointer(tEI.lpszLocalFileName)
   
   
   m_oIE.StatusText = "Done"
End Sub

Private Function StringFromPointer(ByVal Ptr As Long) As String

   StringFromPointer = Space$(lstrlenA(Ptr))
   lstrcpyA StringFromPointer, Ptr
   
End Function
LVL 5
NaeemgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>By pressing my button i want to get the contents(html contents) which are displaying in browser
This can be done easily by editing Registry, see:

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/ext/extensions.asp
Many more useful resources at: http:Q_20721021.html

Will this helps?
NaeemgAuthor Commented:
thanks for ur cooperation,. but i've done registry entries. and also got object of IE.
I want to get the html contents of that IE broswer.
thanks
Erick37Commented:
Did you try:

ie.document.body.outerHTML

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NaeemgAuthor Commented:
hello, i also want to save those html contents to file on harddisk.
can anyone help?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.