/// <summary> /// Searches for a specified window environment to get the desired pane. /// -- Might throw an HolodeckExceptions.MismatchingWindowEnvironmentException /// </summary> /// <param name="hWnd">the current window to match against the specified environment</param> /// <param name="environment">the WindowEnvironment to match against</param> /// <returns>the handler to the matched window (specified by the environment), or null if no such window was found</returns> protected static IntPtr FindHolodeckPane2 (IntPtr hWnd, WindowEnvironment environment) { try { IntPtr window = MatchEnvironment (GetWindowInfo (hWnd), environment); if (window != IntPtr.Zero) { // We've found the window we were looking for. return window; } else { // We shouldn't've gotten here... Being here means the environments matched, but there was no searchedHandle set to true in the environment variable. throw new HolodeckExceptions.MismatchingWindowEnvironmentException ("Bad WindowEnvironment setting. No searchedHandle was specified."); } } catch (HolodeckExceptions.MismatchingWindowEnvironmentException) { // The environment didn't match for this window. Carry on to check its child windows. } Holodeck.WindowInfo[] array = Holodeck.Base.EnumChildWindows (hWnd); foreach (Holodeck.WindowInfo tempInfo in array) { IntPtr window = FindHolodeckPane2 (tempInfo.hWnd, environment); if (window != IntPtr.Zero) { return window; } } return IntPtr.Zero; }
/// <summary> /// Matches a specific window environment against a specified window and its childs /// -- Might throw a HolodeckExceptions.MismatchingWindowEnvironmentException /// </summary> /// <param name="info">the window info to match against the window environment</param> /// <param name="environment">the window environment to match against</param> /// <returns>the handler to the matched window (specified by the environment), or null if no such window was found</returns> protected static IntPtr MatchEnvironment (WindowInfo info, WindowEnvironment environment) { IntPtr searchedHandle = IntPtr.Zero; WindowInfo[] array = EnumChildWindows (info.hWnd); bool matchTitle = (!environment.checkTitle || (environment.checkTitle && (info.title == environment.title))); bool matchChildSize = (((environment.childs == null) && (array.Length == 0)) || (environment.childs.Length == array.Length)); if (matchTitle && matchChildSize) { if (environment.searchedHandle) { // We might have found our window, but we also need to check the child environments. // Store our handle in searchedHandle for now. searchedHandle = info.hWnd; } if (environment.childs != null) { for (int i = 0; i < array.Length; i++) { IntPtr retHandle = MatchEnvironment (array[i], environment.childs[i]); // MatchEnvironment might throw an exception, but we don't need to worry about it here if (retHandle != IntPtr.Zero) { searchedHandle = retHandle; } } } // If we got here, that means that all the child environments matched as well. // searchHandle is not IntPtr.Zero if we've found our window. return searchedHandle; } else { // We need to throw this to differentiate from matching sub-environments that do not contain the searched window handle. throw new HolodeckExceptions.MismatchingWindowEnvironmentException ("The window doesn't match the specified environment"); } }
/// <summary> /// Searches for a specified window environment to get the desired pane. /// -- Might throw a HolodeckExceptions.MismatchingWindowEnvironmentException /// </summary> /// <param name="environment">the WindowEnvironment to match against</param> /// <returns>a handle to the found pane; or IntPtr, if there were no matching pane</returns> public static IntPtr FindHolodeckPane(WindowEnvironment environment) { return FindHolodeckPane2 (Holodeck.Base.GetMainWindowHandle (), environment); }
/// <summary> /// Matches a specific window environment against a specified window and its childs /// -- Might throw a HolodeckExceptions.MismatchingWindowEnvironmentException /// </summary> /// <param name="info">the window info to match against the window environment</param> /// <param name="environment">the window environment to match against</param> /// <returns>the handler to the matched window (specified by the environment), or null if no such window was found</returns> protected static IntPtr MatchEnvironment(WindowInfo info, WindowEnvironment environment) { IntPtr searchedHandle = IntPtr.Zero; WindowInfo[] array = EnumChildWindows (info.hWnd); bool matchTitle = (!environment.checkTitle || (environment.checkTitle && (info.title == environment.title))); bool matchChildSize = (((environment.childs == null) && (array.Length == 0)) || (environment.childs.Length == array.Length)); if (matchTitle && matchChildSize) { if (environment.searchedHandle) { // We might have found our window, but we also need to check the child environments. // Store our handle in searchedHandle for now. searchedHandle = info.hWnd; } if (environment.childs != null) { for (int i = 0; i < array.Length; i++) { IntPtr retHandle = MatchEnvironment (array[i], environment.childs[i]); // MatchEnvironment might throw an exception, but we don't need to worry about it here if (retHandle != IntPtr.Zero) { searchedHandle = retHandle; } } } // If we got here, that means that all the child environments matched as well. // searchHandle is not IntPtr.Zero if we've found our window. return searchedHandle; } else { // We need to throw this to differentiate from matching sub-environments that do not contain the searched window handle. throw new HolodeckExceptions.MismatchingWindowEnvironmentException ("The window doesn't match the specified environment"); } }
/// <summary> /// Searches for a specified window environment to get the desired pane. /// -- Might throw an HolodeckExceptions.MismatchingWindowEnvironmentException /// </summary> /// <param name="hWnd">the current window to match against the specified environment</param> /// <param name="environment">the WindowEnvironment to match against</param> /// <returns>the handler to the matched window (specified by the environment), or null if no such window was found</returns> protected static IntPtr FindHolodeckPane2(IntPtr hWnd, WindowEnvironment environment) { try { IntPtr window = MatchEnvironment (GetWindowInfo (hWnd), environment); if (window != IntPtr.Zero) { // We've found the window we were looking for. return window; } else { // We shouldn't've gotten here... Being here means the environments matched, but there was no searchedHandle set to true in the environment variable. throw new HolodeckExceptions.MismatchingWindowEnvironmentException ("Bad WindowEnvironment setting. No searchedHandle was specified."); } } catch (HolodeckExceptions.MismatchingWindowEnvironmentException) { // The environment didn't match for this window. Carry on to check its child windows. } Holodeck.WindowInfo[] array = Holodeck.Base.EnumChildWindows (hWnd); foreach (Holodeck.WindowInfo tempInfo in array) { IntPtr window = FindHolodeckPane2 (tempInfo.hWnd, environment); if (window != IntPtr.Zero) { return window; } } return IntPtr.Zero; }
/// <summary> /// Searches for a specified window environment to get the desired pane. /// -- Might throw a HolodeckExceptions.MismatchingWindowEnvironmentException /// </summary> /// <param name="environment">the WindowEnvironment to match against</param> /// <returns>a handle to the found pane; or IntPtr, if there were no matching pane</returns> public static IntPtr FindHolodeckPane (WindowEnvironment environment) { return FindHolodeckPane2 (Holodeck.Base.GetMainWindowHandle (), environment); }