/// <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
     {
         Running.WindowEnumerator enumerator = new Running.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);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Try to find the main window handle from application proxy through windows desktop by enumerate window handles.
        /// The operations fails if more than 1 powerpoint window is open and there is no trust for programaticaly access for VBE.
        /// </summary>
        /// <param name="applicationProxy">application proxy</param>
        /// <returns>main window handle</returns>
        public static int TryGetHostApplicationWindowHandleFromDesktop(object applicationProxy)
        {
            if (null == applicationProxy)
            {
                throw new ArgumentNullException("applicationProxy");
            }

            try
            {
                int result = 0;
                Running.WindowEnumerator enumerator = new Running.WindowEnumerator("PP", "FrameClass");
                IntPtr[] handles = enumerator.EnumerateWindows(2000);

                // if we have only one - we dont need to find out more
                if (null != handles && handles.Length == 1)
                {
                    return((int)handles[0]);
                }

                foreach (IntPtr item in handles)
                {
                    object proxyApplication = GetAccessibleObject(item);
                    if (null != proxyApplication)
                    {
                        try
                        {
                            bool equals = Equal(applicationProxy, proxyApplication);
                            if (equals)
                            {
                                result = (int)item;
                            }
                            break;
                        }
                        catch
                        {
                            throw;
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(proxyApplication);
                        }
                    }
                }

                return(result);
            }
            catch (Exception exception)
            {
                NetOffice.Core.Default.Console.WriteException(exception);
                return(0);
            }
        }
Exemplo n.º 3
0
        private int TryGetHostApplicationWindowHandleFromDesktop(WordApi.Document document)
        {
            try
            {
                int result = 0;
                Running.WindowEnumerator enumerator = new Running.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);
            }
        }