I’m writing a small application that will launch Internet Explorer and will open a unknown list or URLs, either as new windows or as new tabs within existing windows (depending on the setting for that particular site). The websites being launched can be in any internet zone. I am able to use the SHDocVw methods to open new Windows and tabs.
I’m trying to figure out a way to track the last opened Internet Explorer reference, so that I can use that reference to open tabs.
I’m running into the situation where, due to “loosely-coupled Internet Explorer” (LCIE) and IE protected mode, the IE instance that I launch gets shut down and another automatically launched (IE virtual tab switching). This causes me to lose the reference that I had to the original IE and when I try opening a tab it fails.
I would like to use the ShellWindows FindWindowSW method to get a specific Window (based on the ShellWindows cookie value), but I can’t get it to work. Could someone point me in the right direction?
private InternetExplorer GetLastExplorer(int cookie)
{
object _m = Type.Missing;
const int SWC_BROWSER = 0x00000001;
const int SWFO_COOKIEPASSED = 4;
int pHWND;
_shellWindows.FindWindowSW(cookie, ref _m, SWC_BROWSER, out pHWND, 5);
foreach (InternetExplorer window in _shellWindows)
{
if (window.HWND == pHWND)
return window;
}
return null;
}
I couldn’t get this to work, and had to take a different approach. I ended up doing the following to get the last opened IE instance: