繁体   English   中英

使用 SHDocVw 时区分 IE 窗口和其他窗口

[英]Distinguishing IE windows from other windows when using SHDocVw

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM