使用SHDocVw时将IE窗口与其他窗口区分开 [英] Distinguishing IE windows from other windows when using SHDocVw

查看:112
本文介绍了使用SHDocVw时将IE窗口与其他窗口区分开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何区分IE Shell窗口和非IE Shell窗口?我有以下代码片段(删除了Lot的代码或无关的逻辑),这些代码使用ShellWindows对象扫描打开的窗口以查看用户正在浏览的URL,目的是在用户浏览到特定URL时执行某些操作:

How can I distinguish IE shell windows from non IE shell windows? I've got the following snippet of code (Lot's or extraneous logic removed) that uses the ShellWindows object to scan the open windows to see what URL the user is browsing, with the intention of doing something if they have browsed to a particular 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窗口感兴趣,不会打开该窗口打开的其他随机窗口(代码甚至允许允许您配置任务栏的窗口通过。)。

I'm only interested in Internet Explorer windows though, not other random windows that windows opens (The code is even letting the window that allows you to configure the taskbar to slip through).

推荐答案

仅Internet Explorer具有 HTMLDocument 作为 Document 对象,因此您可以检查以下内容:

Only Internet Explorer has an HTMLDocument as the Document object, so you can check this:

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

这篇关于使用SHDocVw时将IE窗口与其他窗口区分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆