简体   繁体   中英

Distinguishing IE windows from other windows when using SHDocVw

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.
    }
}

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).

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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