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?
Okay, this is not perfect, but here's what i came up with:
HWND
fromInternetExplorer
object, this is handle of the window.EnumChildWindows
orFindWindowEx
to traverse its chlidren and find child windows having classFrame Tab
. You'll get anIntPtr tabHandle
- the handle of the tab. I personally likeFindWindowEx
better here, since it will not use a callback, but iterate in a loop...FindWindowEx
again on thetabHandle
discovered in #2 to get to a child with classTabWindowClass
. You'll getIntPtr 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).GetWindowText
ontabTitleHandle
to get the window title.InternetExplorer
objects inShellWindowsClass
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! ;)