1

IE シェル ウィンドウと非 IE シェル ウィンドウを区別するにはどうすればよいですか? 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 ウィンドウにのみ興味があり、ウィンドウが開く他のランダムなウィンドウには興味がありません (コードは、タスクバーを設定できるウィンドウをすり抜けることさえ可能にしています)。

4

1 に答える 1

2

オブジェクトとしてHTMLDocumentを持つのは Internet Explorer だけなDocumentので、これを確認できます。

if (shellWindow.Document is mshtml.HTMLDocument) // requires a reference to mshtml
{
    // this is Internet Explorer
}
于 2014-01-14T09:20:03.727 に答える