Need the ability to distinguish between objects of the ShDocVw.InternetExplorer tab

I am using the ShDocVw interop assembly to access InternetExplorer .

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

Result - all tabs of one report of the HWND window are equal to MainWindowHandle this window process. In fact, I cannot find any separate information in these objects that would distinguish them from each other.

And I need to match these instances with real tabs in order to match them with Windows events (mainly window focus change). It would be great to find a relationship between this object and the corresponding instance of the Frame Tab or TabWindowClass .

Any ideas how to achieve this?

+4
source share
1 answer

Ok, this is not perfect, but here is what I came up with:

  • Get HWND from an InternetExplorer object, this is a window handle .
  • Use EnumChildWindows or FindWindowEx to traverse its chlidren and find child windows with the Frame Tab class. You will get IntPtr tabHandle - the tab handle . I personally like FindWindowEx here better, since it will not use a callback, but it repeats in a loop ...
  • Then again use FindWindowEx on the tabHandle found in # 2 to jump to the child with the TabWindowClass class. You will get IntPtr tabTitleHandle - this is the window that contains the title of the tab window (which includes the location name + "- Internet explorer smth", I write "smth" because this text can change because MSIE distribution can be configured).
  • Use GetWindowText on tabTitleHandle to get the window title.
  • Now iterating through the InternetExplorer objects in the ShellWindowsClass collection, first of all, checking the PID - we only need to compare the instances created by the same process, and then check if the header title is in # 4 .StartsWith(IE.LocationName + " - ") . Pay attention to the "-", because we can assume that there will be some text defining the browser itself, but since it can be configured, it cannot guess about it. If the window title starts with the name of the location, we assume that they match.

As I said, this is not ideal (as the final match is made by name), but this is the best I have received so far. Hope this helps. And I'm still waiting for the perfect solution, keep digging guys!;)

+4
source

All Articles