1

如何区分 IE shell 窗口和非 IE shell 窗口?我有以下代码片段(删除了很​​多或无关的逻辑),它使用 ShellWindows 对象扫描打开的窗口以查看用户正在浏览的 URL,如果他们浏览到特定的 URL,则打算做一些事情:

// 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 窗口感兴趣,而不是窗口打开的其他随机窗口(代码甚至让允许您配置任务栏的窗口滑过)。

4

1 回答 1

2

只有 Internet Explorer 有一个HTMLDocument作为Document对象,所以你可以检查一下:

if (shellWindow.Document is mshtml.HTMLDocument) // requires a reference to mshtml
{
    // this is Internet Explorer
}
于 2014-01-14T09:20:03.727 回答