2014-01-13 53 views
0

如何區分IE外殼窗口與非IE外殼窗口?我有下面的代碼段(刪除了Lot或無關的邏輯),它使用ShellWindows對象來掃描打開的窗口,以查看用戶正在瀏覽的URL,並打算在瀏覽到特定URL時執行某些操作:使用SHDocVw區分IE窗口與其他窗口

// Shell Windows object obtained in another method 
private ShellWindows shellWindows = new ShellWindows(); 

... 
// iterate through all windows 
foreach (SHDocVw.IWebBrowser2 shellWindow in shellWindows) 
{ 
    // We only want to process the windows that are Internet explorer windows not file browsers etc 
    if (shellWindow is SHDocVw.InternetExplorer) // <--- This isn't filtering as I'd expect it to. 
    { 
     // THIS IS AN IE BROWSER WINDOW DO SOMETHING WITH IT. 
    } 
} 

我只是在Internet Explorer窗口興趣,雖然,沒有其他隨機的窗戶,窗戶打開(代碼甚至讓,使您可以配置任務欄漏網之魚窗口)。

+0

據推測,沒有那些漏網之魚窗戶被導航到特殊的URL。你爲什麼關心他們是什麼樣的人? –

+0

我正在訂閱所有這些文檔上的事件,並且我還需要聽取IE瀏覽URL以及這意味着每次發生任何事情時都會運行檢查。 –

回答

1

只有Internet Explorer作爲一個HTMLDocument爲Document對象,所以你可以檢查此:

if (shellWindow.Document is mshtml.HTMLDocument) // requires a reference to mshtml 
{ 
    // this is Internet Explorer 
} 
+0

...但只有當HTML頁面實際加載到瀏覽器中時(與其他Active Document服務器相反,例如Acrobat Reader或MS Word)。 –