/// <summary> /// Try to detect the visibilty of host application main window. /// The implementation try to find a visible Outlook application main window and returns true if found. /// </summary> /// <param name="defaultResult">fallback result if its failed</param> /// <returns>true if application is visible, otherwise false</returns> protected override bool TryGetApplicationVisible(bool defaultResult) { try { NetOffice.Tools.WndUtils.WindowEnumerator enumerator = new NetOffice.Tools.WndUtils.WindowEnumerator("rctrl_renwnd32"); IntPtr[] handles = enumerator.EnumerateWindows(2000); if (null != handles) { // once again, no linq possible here to keep .Net2 support foreach (IntPtr item in handles) { if (enumerator.IsVisible(item)) { return(true); } } } return(false); } catch (System.Exception exception) { NetOffice.Core.Default.Console.WriteException(exception); return(defaultResult); } }
private int TryGetHostApplicationWindowHandleFromDesktop(WordApi.Document document) { try { int result = 0; NetOffice.Tools.WndUtils.WindowEnumerator enumerator = new NetOffice.Tools.WndUtils.WindowEnumerator("OpusApp"); IntPtr[] handles = enumerator.EnumerateWindows(2000); foreach (IntPtr item in handles) { object proxyDocument = GetAccessibleObject(item); if (null != proxyDocument) { try { bool equals = Equal(document.UnderlyingObject, proxyDocument); if (equals) { result = (int)item; } break; } catch { throw; } finally { Marshal.ReleaseComObject(proxyDocument); } } } return(result); } catch (Exception exception) { NetOffice.Core.Default.Console.WriteException(exception); return(0); } }
/// <summary> /// Try to detect the visibilty of host application main window. /// The implementation try to find a visible Outlook application main window and returns true if found. /// </summary> /// <param name="defaultResult">fallback result if its failed</param> /// <returns>true if application is visible, otherwise false</returns> protected override bool TryGetApplicationVisible(bool defaultResult) { try { NetOffice.Tools.WndUtils.WindowEnumerator enumerator = new NetOffice.Tools.WndUtils.WindowEnumerator("rctrl_renwnd32"); IntPtr[] handles = enumerator.EnumerateWindows(2000); if (null != handles) { // once again, no linq possible here to keep .Net2 support foreach (IntPtr item in handles) { if (enumerator.IsVisible(item)) return true; } } return false; } catch (System.Exception exception) { NetOffice.Core.Default.Console.WriteException(exception); return defaultResult; } }
private int TryGetHostApplicationWindowHandleFromDesktop(WordApi.Document document) { try { int result = 0; NetOffice.Tools.WndUtils.WindowEnumerator enumerator = new NetOffice.Tools.WndUtils.WindowEnumerator("OpusApp"); IntPtr[] handles = enumerator.EnumerateWindows(2000); foreach (IntPtr item in handles) { object proxyDocument = GetAccessibleObject(item); if (null != proxyDocument) { try { bool equals = Equal(document.UnderlyingObject, proxyDocument); if (equals) result = (int)item; break; } catch { throw; } finally { Marshal.ReleaseComObject(proxyDocument); } } } return result; } catch (Exception exception) { NetOffice.Core.Default.Console.WriteException(exception); return 0; } }