2013-08-19 3 views
0

Я пытаюсь создать панель инструментов в Internet Explorer 8 & 9. Основная функциональность этого заключается в том, чтобы запустить собственный продукт при щелчке по значку и конвертировать документ соответствующим образом. Тем не менее, у меня возникли трудности с использованием mshtml.HTMLDocument. Пожалуйста, взгляните на мой код и посоветуйте.Internet Explorer 8/9 Add-On VB.Net - mshtml.HTMLDocument не работает. Код, прилагаемый

Спасибо за помощь

' 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 

вопрос здесь: Если TypeOf IE.Document ли mshtml.HTMLDocument. Он продолжает говорить, что документ не является HTML-документом. Буду признателен за любое предложение или рекомендацию.

UPDATE:

Изменились условия Если Если IE.Name = "Windows Internet Explorer" Тогда Если (IE.HWND = myhWnd) Тогда MsgBox (IE.locationURL) выше работает отлично однако его не выполняется код, после которого IE.StatusText = "JOB SUBMITTED ..."

+0

Вы можете сделать 'MsgBox (IE.Document.URL)' перед этой проверкой? Есть ли ошибка? Или URL выглядит реально? – Noseratio

+1

Да, я пробовал это ... он ничего не возвращал. Изменили условие if на следующее: Если IE.Name = "Windows Internet Explorer", то MsgBox (IE.locationURL). Это прекрасно работает, однако, он почему-то не запускает IE.StatusText .. – Albert

ответ

0

Я решил не проверять это, если TypeOf IE.Document Является mshtml.HTMLDocument. Это сработало Если IE.Name = "Windows Internet Explorer"