C# 使用SHDocVw时区分IE窗口与其他窗口

C# 使用SHDocVw时区分IE窗口与其他窗口,c#,internet-explorer,com,shdocvw,C#,Internet Explorer,Com,Shdocvw,如何区分IE外壳窗口和非IE外壳窗口?我得到了以下代码片段(删除了大量或无关逻辑),它使用ShellWindows对象扫描打开的窗口,以查看用户正在浏览的URL,如果用户浏览到某个特定URL,则打算执行以下操作: // Shell Windows object obtained in another method private ShellWindows shellWindows = new ShellWindows(); ... // iterate through all windows

如何区分IE外壳窗口和非IE外壳窗口?我得到了以下代码片段(删除了大量或无关逻辑),它使用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.
    }
}
//在另一个方法中获取了Shell Windows对象
私有ShellWindows ShellWindows=新的ShellWindows();
...
//遍历所有窗口
foreach(shellWindows中的SHDocVw.IWebBrowser2 shellWindow)
{
//我们只想处理Internet explorer窗口,而不是文件浏览器等

如果(shellWindow是SHDocVw.InternetExplorer)/只有Internet Explorer具有作为
文档的对象,那么您可以检查:

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

想必,没有一个通过的窗口被导航到那个特殊的URL。为什么你关心它们是什么类型的呢?我订阅了所有这些文档上的事件,我还需要听IE从URL导航,这意味着每次发生任何事情时我都在运行检查……但只有当HTML页面实际加载时插入浏览器(与其他活动文档服务器不同,例如Acrobat Reader或MS Word)。