Need a way to distinguish between ShDocVw.InternetExplorer tab objects

3k Views Asked by At

I'm using ShDocVw interop assembly to get to InternetExplorer objects.

foreach(InternetExplorer IE in new ShellWindowsClass())
{
   Console.Log(IE.HWND.ToString() + Environment.NewLine);
}

The result is - all the tabs of same window report HWND equals MainWindowHandle of that window`s process. In fact, I cannot find any distinct information in these objects that would differentiate them from one another.

And i need to correlate these instances to real tabs in order to match them to windows events (window focus change mostly). Would be great to find a link between this object and corresponding Frame Tab or TabWindowClass window instance.

Any ideas how to achieve this?

1

There are 1 best solutions below

0
On

Okay, this is not perfect, but here's what i came up with:

  1. Get HWND from InternetExplorer object, this is handle of the window.
  2. Use EnumChildWindows or FindWindowEx to traverse its chlidren and find child windows having class Frame Tab. You'll get an IntPtr tabHandle - the handle of the tab. I personally like FindWindowEx better here, since it will not use a callback, but iterate in a loop...
  3. Then, use FindWindowEx again on the tabHandle discovered in #2 to get to a child with class TabWindowClass. You'll get IntPtr tabTitleHandle - this is the window that holds tab window title (which includes location name + " - internet explorer smth", i write "smth" because this text can vary, as MSIE distribution can be customized).
  4. Use GetWindowText on tabTitleHandle to get the window title.
  5. Now, iterate through InternetExplorer objects in ShellWindowsClass collection, first of all check PID - we only need to compare instances created by the same process, then, check if window title you got in #4 .StartsWith(IE.LocationName + " - "). Note the " - ", since we can assume there will be some text identifying the browser itself, but since it can be customized - can't really guess it. If window title starts with the location name, we'll assume they corellate.

As i said, this is not perfect (since the final match is made by title), but it's the best i got so far. Hope it will help. And i am still waiting for the perfect solution, keep digging guys! ;)