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