簡體   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