问题
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).
回答1:
Only Internet Explorer as 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
}
来源:https://stackoverflow.com/questions/21095520/distinguishing-ie-windows-from-other-windows-when-using-shdocvw