Distinguishing IE windows from other windows when using SHDocVw

余生颓废 提交于 2019-12-12 05:27:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!