Is there any event triggered when a new window is added to the desktop
See the question and my original answer on StackOverflowAs Damien said in his comment, you can use UI automation, like this in a C# sample console app:
class Program
{
static void Main(string[] args)
{
Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement, TreeScope.Subtree, (sender, e) =>
{
AutomationElement src = sender as AutomationElement;
if (src != null)
{
Console.WriteLine("Class : " + src.Current.ClassName);
Console.WriteLine("Title : " + src.Current.Name);
Console.WriteLine("Handle: " + src.Current.NativeWindowHandle);
}
});
Console.WriteLine("Press any key to quit...");
Console.ReadKey(true);
}
}