vb.netinternet-explorerwinapiieaddon

Internet Explorer 8/9 Add-On VB.Net - mshtml.HTMLDocument not working. Code enclosed


I'm trying to create a toolbar in Internet Explorer 8 & 9. The main functionality of this is to launch a in-house product when clicked on the icon and convert document accordingly. However, I'm having some difficulty using mshtml.HTMLDocument. Please take a look at my code and advise.

Thanks for helping out

' Get the hWnd value of the IE window that the macro button was clicked within
    myhWnd = GetForegroundWindow()
    MsgBox(myhWnd)
    ' for all IE window within the shell window, by the way this
    ' includes Windows Explorer as well as IE windows!

    Dim IE As New SHDocVw.InternetExplorer
    Dim SWs As New SHDocVw.ShellWindows

    For Each IE In SWs
        Doc = IE.Document  ' Set the active document

        Functions.OutputDebugString("setting active document for printing using set Doc in main")
        If TypeOf IE.Document Is mshtml.HTMLDocument Then ' if the document is IE then proceed because EXPLORER window returns in the same group - (This is where I'm having trouble. It keep saying 'Document is not an HTML)
            MsgBox("I'm here")
            If (IE.HWND = myhWnd) Then  ' ENABLE IT AFTER TESTING

                Functions.OutputDebugString("JOB SUBMITTED TO QUEUE NOW. PLEASE WAIT.DO NOT CLICK BUTTON AGAIN TO INCREASE SPEED OF OPERATION...")
                IE.StatusText = "JOB SUBMITTED TO QUEUE NOW. PLEASE WAIT.DO NOT CLICK BUTTON AGAIN TO INCREASE SPEED OF OPERATION..."

                Functions.OutputDebugString("Verifying if the page is still downloading or not.. Do not process if its still downloading, wait in loop for 500 mili seconds")
                If Not (IE.Busy = True) Then ' if IE is not currently downloading page then proceed
loopBackfromBusy:
                    Functions.OutputDebugString("Check in registry about exclusing    access to printer")
                    processFlag = saveFileName(IE.LocationName, Doc.url) ' pass the    document URL to give user more informative error messages.
                    Functions.OutputDebugString("Form_Load() - process flag = ")
                    If processFlag = True Then ' if no other window is printing then   proceed

                        Functions.OutputDebugString("FILE SUBMITTED FOR PRINTING in   form load")
                        IE.StatusText = "FILE SUBMITTED TO PRINTER FOR PRINTING. DO NOT CLICK BUTTON AGAIN AND WAIT FOR OPERATION FINISH..."

                        Functions.OutputDebugString("Initializing printer settings using initializeValues()")
                        intilizeValues(Doc.title) ' initialize printer settings and set everything ready for printer

                        DefaultPrinter = Printer.PrinterName ' store current default printr name
                        MsgBox(PrinterName)
                        Functions.OutputDebugString("Changing current default printer to Print Driver.. Note that this name is case sensitive and must be available on user machine or this software will not work correctly...")
                        SetDefaultPrinterMyWinNT(PrinterName) ' set the default printer to KC

                        Functions.OutputDebugString("Fired printing using default IE command")
                        IE.ExecWB(17, 0) '.... print the document silently

 Else
            MsgBox("Document is not an HTML document")
End If

The issue is here : If TypeOf IE.Document Is mshtml.HTMLDocument . It keep saying document is not an HTML document. I'll appreciate any suggestion or recommendation.

UPDATE :

Have changed the If condition to If IE.Name = "Windows Internet Explorer" Then If (IE.HWND = myhWnd) Then MsgBox(IE.locationURL) The above works fine however its not executing the code after which is IE.StatusText = "JOB SUBMITTED..."


Solution

  • I decided not to check via this If TypeOf IE.Document Is mshtml.HTMLDocument. This worked If IE.Name = "Windows Internet Explorer"