/// <summary> /// Find the DirectUI window for MSAA (Accessible) /// </summary> /// <param name="browserWindowDetails">The browser WindowDetails</param> /// <returns>WindowDetails for the DirectUI window</returns> public static WindowDetails GetDirectUI(WindowDetails browserWindowDetails) { if (browserWindowDetails == null) { return(null); } WindowDetails tmpWD = browserWindowDetails; // Since IE 9 the TabBandClass is less deep! if (IEVersion() < 9) { tmpWD = tmpWD.GetChild("CommandBarClass"); if (tmpWD != null) { tmpWD = tmpWD.GetChild("ReBarWindow32"); } } if (tmpWD != null) { tmpWD = tmpWD.GetChild("TabBandClass"); } if (tmpWD != null) { tmpWD = tmpWD.GetChild("DirectUIHWND"); } return(tmpWD); }
/// <summary> /// Does the supplied window have a IE part? /// </summary> /// <param name="someWindow"></param> /// <returns></returns> public static bool IsIEWindow(WindowDetails someWindow) { if ("IEFrame".Equals(someWindow.ClassName)) { return(true); } if (configuration.WindowClassesToCheckForIE != null && configuration.WindowClassesToCheckForIE.Contains(someWindow.ClassName)) { return(someWindow.GetChild("Internet Explorer_Server") != null); } return(false); }
/// <summary> /// Return true if the supplied window has a sub-window which covers more than the supplied percentage /// </summary> /// <param name="someWindow">WindowDetails to check</param> /// <param name="minimumPercentage">min percentage</param> /// <returns></returns> public static bool IsMostlyIEWindow(WindowDetails someWindow, int minimumPercentage) { WindowDetails ieWindow = someWindow.GetChild("Internet Explorer_Server"); if (ieWindow != null) { Rectangle wholeClient = someWindow.ClientRectangle; Rectangle partClient = ieWindow.ClientRectangle; int percentage = (int)(100*((float)(partClient.Width * partClient.Height)) / ((float)(wholeClient.Width * wholeClient.Height))); LOG.InfoFormat("Window {0}, ie part {1}, percentage {2}", wholeClient, partClient, percentage); if (percentage > minimumPercentage) { return true; } } return false; }
/// <summary> /// Helper Method to get the IHTMLDocument2 /// </summary> /// <param name="mainWindow"></param> /// <returns></returns> private static IHTMLDocument2 getHTMLDocument(WindowDetails mainWindow) { WindowDetails ieServer; if ("Internet Explorer_Server".Equals(mainWindow.ClassName)) { ieServer = mainWindow; } else { ieServer = mainWindow.GetChild("Internet Explorer_Server"); } if (ieServer == null) { LOG.WarnFormat("No Internet Explorer_Server for {0}", mainWindow.Text); return(null); } IHTMLDocument2 document2 = null; uint windowMessage = User32.RegisterWindowMessage("WM_HTML_GETOBJECT"); if (windowMessage == 0) { LOG.WarnFormat("Couldn't register WM_HTML_GETOBJECT"); return(null); } LOG.DebugFormat("Trying WM_HTML_GETOBJECT on {0}", ieServer.ClassName); UIntPtr response; User32.SendMessageTimeout(ieServer.Handle, windowMessage, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 5000, out response); if (response != UIntPtr.Zero) { document2 = (IHTMLDocument2)Accessible.ObjectFromLresult(response, typeof(IHTMLDocument).GUID, IntPtr.Zero); if (document2 == null) { LOG.Error("No IHTMLDocument2 found"); return(null); } } else { LOG.Error("No answer on WM_HTML_GETOBJECT."); return(null); } return(document2); }
/// <summary> /// Return true if the supplied window has a sub-window which covers more than the supplied percentage /// </summary> /// <param name="someWindow">WindowDetails to check</param> /// <param name="minimumPercentage">min percentage</param> /// <returns></returns> public static bool IsMostlyIEWindow(WindowDetails someWindow, int minimumPercentage) { WindowDetails ieWindow = someWindow.GetChild("Internet Explorer_Server"); if (ieWindow != null) { Rectangle wholeClient = someWindow.ClientRectangle; Rectangle partClient = ieWindow.ClientRectangle; int percentage = (int)(100 * ((float)(partClient.Width * partClient.Height)) / ((float)(wholeClient.Width * wholeClient.Height))); LOG.InfoFormat("Window {0}, ie part {1}, percentage {2}", wholeClient, partClient, percentage); if (percentage > minimumPercentage) { return(true); } } return(false); }
/// <summary> /// Does the supplied window have a IE part? /// </summary> /// <param name="someWindow"></param> /// <returns></returns> public static bool IsIEWindow(WindowDetails someWindow) { if ("IEFrame".Equals(someWindow.ClassName)) { return true; } if (configuration.WindowClassesToCheckForIE != null && configuration.WindowClassesToCheckForIE.Contains(someWindow.ClassName)) { return someWindow.GetChild("Internet Explorer_Server") != null; } return false; }
/// <summary> /// Helper Method to get the IHTMLDocument2 /// </summary> /// <param name="mainWindow"></param> /// <returns></returns> private static IHTMLDocument2 getHTMLDocument(WindowDetails mainWindow) { WindowDetails ieServer; if ("Internet Explorer_Server".Equals(mainWindow.ClassName)) { ieServer = mainWindow; } else { ieServer = mainWindow.GetChild("Internet Explorer_Server"); } if (ieServer == null) { LOG.WarnFormat("No Internet Explorer_Server for {0}", mainWindow.Text); return null; } IHTMLDocument2 document2 = null; uint windowMessage = User32.RegisterWindowMessage("WM_HTML_GETOBJECT"); if (windowMessage == 0) { LOG.WarnFormat("Couldn't register WM_HTML_GETOBJECT"); return null; } LOG.DebugFormat("Trying WM_HTML_GETOBJECT on {0}", ieServer.ClassName); UIntPtr response; User32.SendMessageTimeout(ieServer.Handle, windowMessage, IntPtr.Zero, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 5000, out response); if (response != UIntPtr.Zero) { document2 = (IHTMLDocument2)Accessible.ObjectFromLresult(response, typeof(IHTMLDocument).GUID, IntPtr.Zero); if (document2 == null) { LOG.Error("No IHTMLDocument2 found"); return null; } } else { LOG.Error("No answer on WM_HTML_GETOBJECT."); return null; } return document2; }