2014-01-13 55 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)。 –