Ejemplo n.º 1
0
 wnd[] _FindAll(WndList_ k, wnd wParent)
 {
     using (k) {
         using var ab = new ArrayBuilder_ <wnd>();
         _FindInList(wParent, k, w => ab.Add(w));                 //CONSIDER: ab could be part of _WndList. Now the delegate creates garbage.
         return(ab.ToArray());
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns index of matching element or -1.
        /// Returns -1 if using getAll.
        /// </summary>
        /// <param name="wParent">Parent window. Can be default(wnd) if inList is true and no DirectChild flag and not using winforms name.</param>
        /// <param name="a">List of wnd. Does not dispose it.</param>
        /// <param name="getAll">If not null, calls it for all matching and returns -1.</param>
        int _FindInList(wnd wParent, WndList_ a, Action <wnd> getAll = null)
        {
            Result = default;
            if (a.Type == WndList_.ListType.None)
            {
                return(-1);
            }
            bool inList    = a.Type != WndList_.ListType.ArrayBuilder;
            int  skipCount = _skipCount;

            try {             //will need to dispose something
                for (int index = 0; a.Next(out wnd w); index++)
                {
                    if (w.Is0)
                    {
                        continue;
                    }

                    if (inList)                       //else the enum function did this
                    {
                        if (!_flags.Has(WCFlags.HiddenToo))
                        {
                            if (!w.IsVisibleIn_(wParent))
                            {
                                continue;
                            }
                        }

                        if (_flags.Has(WCFlags.DirectChild) && !wParent.Is0)
                        {
                            if (w.ParentGWL_ != wParent)
                            {
                                continue;
                            }
                        }
                    }

                    if (_id != null)
                    {
                        if (w.ControlId != _id.Value)
                        {
                            continue;
                        }
                    }

                    if (_className != null)
                    {
                        if (!_className.Match(w.ClassName))
                        {
                            continue;
                        }
                    }

                    if (_name != null)
                    {
                        string s;
                        switch (_nameIs)
                        {
                        case _NameIs.text:
                            s = w.ControlText;
                            break;

                        case _NameIs.elmName:
                            s = w.NameElm;
                            break;

                        case _NameIs.wfName:
                            if (_wfControls == null)
                            {
                                try {
                                    _wfControls = new WinformsControlNames(wParent.Is0 ? w : wParent);
                                }
                                catch (AuWndException) {                                 //invalid parent window
                                    return(-1);
                                }
                                catch (AuException e) {                                 //probably process of higher UAC integrity level
                                    print.warning($"Failed to get winforms control names. {e.Message}");
                                    return(-1);
                                }
                            }
                            s = _wfControls.GetControlName(w);
                            break;

                        //case _NameIs.label:
                        //	s = w.NameLabel;
                        //	break;
                        default:
                            s = w.Name;
                            break;
                        }

                        if (!_name.Match(s))
                        {
                            continue;
                        }
                    }

                    if (_also != null && !_also(w))
                    {
                        continue;
                    }

                    if (getAll != null)
                    {
                        getAll(w);
                        continue;
                    }

                    if (skipCount-- > 0)
                    {
                        continue;
                    }

                    Result = w;
                    return(index);
                }
            }
            finally {
                if (_wfControls != null)
                {
                    _wfControls.Dispose(); _wfControls = null;
                }
            }

            return(-1);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Finds the specified control in a list of controls.
 /// Returns 0-based index, or -1 if not found.
 /// The <see cref="Result"/> property will be the control.
 /// </summary>
 /// <param name="a">List of controls, for example returned by <see cref="wnd.getwnd.Children"/>.</param>
 /// <param name="wParent">Direct or indirect parent window. Used only for flag DirectChild.</param>
 public int FindInList(IEnumerable <wnd> a, wnd wParent = default)
 {
     using var k = new WndList_(a);
     return(_FindInList(wParent, k));
 }
Ejemplo n.º 4
0
 /// <returns>If found, sets <see cref="Result"/> and returns true, else false.</returns>
 /// <inheritdoc cref="Find(wnd)"/>
 public bool Exists(wnd wParent)
 {
     using var k = new WndList_(_AllChildren(wParent));
     return(_FindInList(wParent, k) >= 0);
 }