Beispiel #1
0
        private void FindByIdentifierActiveX(ControlIdentifier identifier, ref IntPtr handle, ref string name, ref string theText, ref string typeNameSpace, ref string typeName, ref int currentIndex, ref string uniqueId, ref bool foundControl)
        {
            bool   found        = false;
            IntPtr parentHandle = IntPtr.Zero;

            if (Ax.Items.Count > 0)
            {
                lock (Ax.AxItemsLock)
                {
                    object control = null;
                    int    item;
                    int    items = Ax.Items.Count;
                    for (item = 0; item < items; item++)
                    {
                        if (Ax.Items[item].Handle == handle)
                        {
                            parentHandle = Ax.Items[item].ParentHandle;
                            name         = Ax.Items[item].Name;
                            uniqueId     = Ax.Items[item].UniqueId;
                            control      = Ax.Items[item].Control;
                            found        = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return;
                    }

                    if (identifier.ParentHandle == parentHandle || (identifier.ParentHandle == IntPtr.Zero && parentHandle == handle))
                    {
                    }
                    else
                    {
                        return;
                    }

                    if (identifier.Name != null)
                    {
                        if (name != identifier.Name)
                        {
                            return;
                        }
                    }

                    if (identifier.TechnologyType != null)
                    {
                        if ("Windows ActiveX" != identifier.TechnologyType)
                        {
                            return;
                        }
                    }

                    if (identifier.TypeNameSpace != null)
                    {
                        typeNameSpace = Ax.Items[item].TypeNameSpace;   //Lazy load it only if we need it
                        if (typeNameSpace == null)
                        {
                            return;
                        }
                        else
                        {
                            if (!Regex.IsMatch(typeNameSpace, identifier.TypeNameSpace))
                            {
                                return;
                            }
                        }
                    }

                    if (identifier.TypeName != null)
                    {
                        typeName = Ax.Items[item].TypeName; //Lazy load it only if we need it
                        if (typeName == null)
                        {
                            return;
                        }
                        else
                        {
                            if (!Regex.IsMatch(typeName, identifier.TypeName))
                            {
                                return;
                            }
                        }
                    }

                    if (identifier.ModuleName != null)
                    {
                        if (Path.GetFileName(NM.GetWindowModuleFileName(handle)) != identifier.ModuleName)
                        {
                            return;
                        }
                    }

                    if (identifier.AssemblyName != null)
                    {
                        return;
                    }

                    if (identifier.ChildOf != IntPtr.Zero)
                    {
                        if (!NM.IsChild(identifier.ChildOf, handle))
                        {
                            return;
                        }
                    }

                    if (identifier.SiblingOf != IntPtr.Zero)
                    {
                        if (!NM.IsSibling(identifier.SiblingOf, handle))
                        {
                            return;
                        }
                    }

                    if (identifier.ParentOf != IntPtr.Zero)
                    {
                        if (!NM.IsChild(handle, identifier.ParentOf))
                        {
                            return;
                        }
                    }

                    theText = GetWindowTextViaWindowMessage(handle);
                    if (identifier.Text != null)
                    {
                        if (theText == null)
                        {
                            return;
                        }
                        else
                        {
                            if (!Regex.IsMatch(theText, identifier.Text))
                            {
                                return;
                            }
                        }
                    }

                    if (identifier.AccessibilityObjectName != null)
                    {
                        return;
                    }

                    currentIndex++;
                    if (identifier.Index > 0)
                    {
                        if (currentIndex != identifier.Index)
                        {
                            return;
                        }
                    }

                    //Make sure the type name space and type name are populated
                    typeName      = Ax.Items[item].TypeName;
                    typeNameSpace = Ax.Items[item].TypeNameSpace;

                    //we have a match
                    foundControl = true;
                }
            }
        }