Esempio n. 1
0
        private static IDisposableSequence GetActiveExcelApplicationProxiesFromDesktop()
        {
            try
            {
                WindowEnumerator enumerator = new WindowEnumerator("XLMAIN");
                IntPtr[]         handles    = enumerator.EnumerateWindows(2000);
                if (null == handles || handles.Length == 0)
                {
                    return(new DisposableObjectList(null));
                }

                return(ExcelApplicationWindow.GetApplicationProxiesFromHandle(handles));
            }
            catch (Exception exception)
            {
                DebugConsole.Default.WriteException(exception);
                throw;
            }
        }
Esempio n. 2
0
        private static object GetActiveExcelApplicationProxyFromDesktop()
        {
            try
            {
                WindowEnumerator enumerator = new WindowEnumerator("XLMAIN");
                IntPtr[]         handles    = enumerator.EnumerateWindows(2000);
                if (null == handles || handles.Length == 0)
                {
                    return(null);
                }

                object proxy = ExcelApplicationWindow.GetApplicationProxyFromHandle(handles[0]);
                return(proxy);
            }
            catch (Exception exception)
            {
                DebugConsole.Default.WriteException(exception);
                throw;
            }
        }
Esempio n. 3
0
        private static IDisposableSequence <ProxyInformation> GetUnknownAccessibleProxiesFromPath(int maximumResultCount)
        {
            RunningWindowTableItemCollection result = new RunningWindowTableItemCollection();

            WindowEnumerator enumerator =
                new WindowEnumerator(String.Empty);

            IntPtr[] mainWindows = enumerator.EnumerateWindows(10000);
            if (null != mainWindows)
            {
                foreach (IntPtr item in mainWindows)
                {
                    DoAccTest(result, item, item, maximumResultCount);
                    EnumChildWindows(result, item, item, maximumResultCount);
                    if (result.Count >= maximumResultCount)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
Esempio n. 4
0
        private static IDisposableSequence <ProxyInformation> GetKnownAccessibleProxiesFromPath(IEnumerable <AccessibleWindowTarget> targets, int maximumResultCount)
        {
            if (null == targets)
            {
                throw new ArgumentNullException("targets");
            }

            RunningWindowTableItemCollection result = new RunningWindowTableItemCollection();

            if (maximumResultCount <= 0)
            {
                return(result);
            }

            foreach (AccessibleWindowTarget target in targets)
            {
                WindowEnumerator enumerator =
                    new WindowEnumerator(
                        target.MainClassName, target.MainClassNameEnd, (WindowEnumerator.FilterMode)Convert.ToInt32(target.NameCompare));
                IntPtr[] mainHandles = enumerator.EnumerateWindows(_mainWindowTimeoutMilliseconds);
                if (null == mainHandles)
                {
                    continue;
                }
                foreach (IntPtr item in mainHandles)
                {
                    ChildWindowBatchEnumerator childEnumerator =
                        new ChildWindowBatchEnumerator(item);

                    foreach (string subItem in target.ChildPath)
                    {
                        childEnumerator.SearchOrder.Add(
                            new ChildWindowBatchEnumerator.SearchCriteria(subItem));
                    }
                    IntPtr[] childHandles = childEnumerator.EnumerateWindows(_childWindowTimeoutMilliseconds);
                    if (null == childHandles)
                    {
                        continue;
                    }

                    foreach (IntPtr childHandle in childHandles)
                    {
                        object accObject = Win32.AccessibleObjectFromWindow(childHandle);
                        if (null != accObject && accObject is MarshalByRefObject)
                        {
                            object targetProxy = null;
                            if (!String.IsNullOrEmpty(target.AccPropertyName))
                            {
                                targetProxy = TryInvokeProperty(accObject, target.AccPropertyName);
                                Marshal.ReleaseComObject(accObject);
                            }
                            else
                            {
                                targetProxy = accObject;
                            }

                            if (null != targetProxy)
                            {
                                string             itemComponentName = TypeDescriptor.GetComponentName(targetProxy);
                                COMTypes.ITypeInfo typeInfo          = RunningObjectTable.TryCreateTypeInfo(targetProxy);
                                string             library           = RunningObjectTable.GetParentLibraryGuid(typeInfo).ToString();
                                string             id            = GetTypeGuid(typeInfo).ToString();
                                string             itemClassName = TypeDescriptor.GetClassName(targetProxy);
                                string             itemCaption   = itemClassName;
                                if (!String.IsNullOrWhiteSpace(itemClassName) && !String.IsNullOrWhiteSpace(itemComponentName))
                                {
                                    itemCaption = String.Format("{0} {1}", itemComponentName, itemClassName);
                                }

                                IntPtr procID = Win32.GetWindowThreadProcessId(childHandle);
                                ProxyInformation.ProcessElevation procElevation =
                                    ProcessElevation.ConvertToProcessElevation(ProcessElevation.IsProcessElevated(procID));

                                ProxyInformation info = new ProxyInformation(targetProxy,
                                                                             itemCaption, id, itemClassName, itemComponentName, library, procID, procElevation);

                                result.Add(info);
                                if (null != typeInfo)
                                {
                                    RunningObjectTable.ReleaseTypeInfo(typeInfo);
                                }

                                if (result.Count >= maximumResultCount)
                                {
                                    return(result);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }