コード例 #1
1
        public bool checkHandle()
        {
            Guid guid = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
            object obj = null;
            int retVal = AccessibleObjectFromWindow(handle, (uint)OBJID.WINDOW, ref guid, ref obj);
            iAccessible = (IAccessible)obj;

            //The AccWindowName returned is Add-ons Manager - Mozilla Firefox
            //There is a special child id called CHILDID_SELF (this constant equals 0) that, when used with a function like get_accChild, returns the element itself rather than a child.

            string accWindowName = iAccessible.get_accName(0);
            string accWindowVal = iAccessible.get_accValue(0);

            Console.WriteLine("IAccessible Name : " + accWindowName);
            Console.WriteLine("IAccessible value : " + accWindowVal);
            Console.WriteLine("IAccessible Role is : " + iAccessible.get_accRole(0));

            Console.WriteLine("IAccessible Type: " + iAccessible.GetType());
            Console.WriteLine("IAccessible Focus is: " + iAccessible.accFocus);
            Console.WriteLine("IAccessible Selection is " + iAccessible.get_accState());
            //iAccessible.accSelect((int)OBJID.SELFLAG_TAKEFOCUS, 0);
            if (!accWindowName.Contains("Mozilla Firefox"))
                return false;

            getChild(iAccessible,false);

            //End of for window
            Console.WriteLine("End of checkHandle");
            iAccessible = null;
            return false;
        }
コード例 #2
0
ファイル: TabFocusManager.cs プロジェクト: res0o43m/Redaction
        private IAccessible GetObjectByName(object Control, string ChildControl)
        {
            object[]    Children;
            IAccessible Result = null;

            IAccessible Parent = Control as IAccessible;

            if (Parent != null)
            {
                System.Diagnostics.Debug.WriteLine(Parent.get_accName(0));
                if (Parent.get_accName(0) == ChildControl)
                {
                    Result = Parent;
                }
                else
                {
                    Children = GetAccessibleChildren(Parent);
                    for (long i = 0; i <= Children.Length - 1; i++)
                    {
                        Result = GetObjectByName(Children[i], ChildControl);
                        if (Result != null)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("control skipped for being null");
            }
            return(Result);
        }
コード例 #3
0
        /* String[] GetPrinterList()
         * get the printers can be selected in the dialog.
         */
        public static String[] GetPrinterList()
        {
            if (_paccPrintList != null)
            {
                try
                {
                    long childrenCount = _paccPrintList.accChildCount;

                    String[] res = new string[childrenCount - 1];

                    //the first is "Add Printer", it is not an actual printer, so ignore it.
                    //start from the 2nd printer.
                    for (int i = 2; i <= childrenCount; i++)
                    {
                        object childID = (object)i;

                        //get name for each printer, add it to the array.
                        res[i - 2] = _paccPrintList.get_accName(childID);
                    }

                    return(res);
                }
                catch
                {
                }
            }

            return(null);
        }
コード例 #4
0
        public static IAccessible GetAccessibleObjectByNameAndRole(IAccessible iaccWindow, string accName, AccRole accRole)
        {
            IAccessible objReturn  = default(IAccessible);
            int         childCount = iaccWindow.accChildCount;

            object[] windowChildren = new object[childCount];
            int      pcObtained;
            int      result = AccessibleChildren(iaccWindow, 0, childCount, windowChildren, out pcObtained);
            string   name   = "";
            int      role;

            for (int i = 0; i < windowChildren.Count(); i++)
            {
                if (windowChildren[i].GetType() != typeof(int) && windowChildren[i].GetType() != typeof(string))
                {
                    IAccessible child = windowChildren[i] as IAccessible;
                    role = (int)child.get_accRole(CHILDID_SELF);
                    name = child.get_accName(CHILDID_SELF);
                    if (accName.Equals(name, StringComparison.CurrentCultureIgnoreCase) && role == accRole.GetHashCode())
                    {
                        return(child);
                    }
                    objReturn = GetAccessibleObjectByNameAndRole(child, accName, accRole);
                    if (objReturn != default(IAccessible))
                    {
                        return(objReturn);
                    }
                }
            }
            return(objReturn);
        }
コード例 #5
0
        /// <summary>
        /// Returns the name of the UI element
        /// </summary>
        /// <param name="pacc"> Accessible Parent </param>
        /// <param name="varChild">Child Variant</param>
        /// <returns>Name of UI Element</returns>
        public static string GetUIElementName(IAccessible pacc, int varChild)
        {
            int    numRetry = 3;
            bool   retried  = false;
            string name     = string.Empty;

            if (null == pacc)
            {
                return(name);
            }

            do
            {
                try
                {
                    name = pacc.get_accName(varChild);
                }
                catch (COMException comEx)
                {
                    // 0x80010001 OLE Server is busy, do 3 retry
                    if (comEx.ErrorCode == -2147418111)
                    {
                        retried = true;
                        numRetry--;
                    }
                }
            }while (numRetry > 0 && retried);

            return(name);
        }
コード例 #6
0
        public bool checkHandle()
        {
            Guid   guid   = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
            object obj    = null;
            int    retVal = AccessibleObjectFromWindow(handle, (uint)OBJID.WINDOW, ref guid, ref obj);

            iAccessible = (IAccessible)obj;

            //The AccWindowName returned is Add-ons Manager - Mozilla Firefox
            //There is a special child id called CHILDID_SELF (this constant equals 0) that, when used with a function like get_accChild, returns the element itself rather than a child.

            string accWindowName = iAccessible.get_accName(0);
            string accWindowVal  = iAccessible.get_accValue(0);

            Console.WriteLine("IAccessible Name : " + accWindowName);
            Console.WriteLine("IAccessible value : " + accWindowVal);
            Console.WriteLine("IAccessible Role is : " + iAccessible.get_accRole(0));

            Console.WriteLine("IAccessible Type: " + iAccessible.GetType());
            Console.WriteLine("IAccessible Focus is: " + iAccessible.accFocus);
            Console.WriteLine("IAccessible Selection is " + iAccessible.get_accState());
            //iAccessible.accSelect((int)OBJID.SELFLAG_TAKEFOCUS, 0);
            if (!accWindowName.Contains("Mozilla Firefox"))
            {
                return(false);
            }

            getChild(iAccessible, false);

            //End of for window
            Console.WriteLine("End of checkHandle");
            iAccessible = null;
            return(false);
        }
コード例 #7
0
        /// <summary>
        /// Given a control, generates the complete path that the script language uses to identify it.
        /// This is reliably useful only if all parents have meaningful and sufficiently unique names.
        /// </summary>
        /// <param name="cLeaf"></param>
        /// <returns></returns>
        public static string AccessPath(Control cLeaf)
        {
            StringBuilder sb = new StringBuilder();

            // Build the string from the back, as a sequence of role:name pairs separated by /
            for (Control c = cLeaf; c != null; c = c.Parent)
            {
                if (sb.Length != 0)
                {
                    sb.Insert(0, "/");
                }
                System.Reflection.PropertyInfo pi = c.GetType().GetProperty("AccessibleRootObject");
                if (pi == null)
                {
                    AccessibleObject ao = c.AccessibilityObject;
                    sb.Insert(0, ao.Name);
                    sb.Insert(0, ":");
                    sb.Insert(0, ao.Role);
                }
                else
                {
                    IAccessible acc = (IAccessible)pi.GetValue(c, new object[0]);
                    sb.Insert(0, acc.get_accName(null));
                    sb.Insert(0, ":");
                    sb.Insert(0, InterpretRole(acc.get_accRole(null)));
                }
            }
            return(sb.ToString());
        }
コード例 #8
0
        private void root_MouseDown(object sender, MouseEventArgs e)
        {
            Control          c           = sender as Control;
            AccessibleObject ao          = c.AccessibilityObject;
            Point            screenPoint = c.PointToScreen(new Point(e.X, e.Y));
            StringBuilder    sb          = new StringBuilder();

            System.Reflection.PropertyInfo pi = c.GetType().GetProperty("AccessibleRootObject");
            if (pi == null)
            {
                AccessibleObject aoPrev = null;                 // Some HitTests keep returning the leaf object.
                for (AccessibleObject aoCur = ao.HitTest(screenPoint.X, screenPoint.Y);
                     aoCur != null && aoCur != ao && aoCur != aoPrev;
                     aoCur = aoCur.HitTest(screenPoint.X, screenPoint.Y))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("/");
                    }
                    sb.Append(aoCur.Role);
                    sb.Append(":");
                    sb.Append(aoCur.Name);
                    aoPrev = aoCur;
                }
            }
            else
            {
                IAccessible acc = (IAccessible)pi.GetValue(c, new object[0]);

                for (IAccessible accCurr = (IAccessible)acc.accHitTest(screenPoint.X, screenPoint.Y);
                     accCurr != null;
                     accCurr = accCurr.accHitTest(screenPoint.X, screenPoint.Y) as IAccessible)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("/");
                    }
                    sb.Append(InterpretRole(accCurr.get_accRole(null)));
                    sb.Append(":");
                    sb.Append(accCurr.get_accName(null));
                }
            }

            string leafPath = sb.ToString();

            m_output.WriteStartElement("click");
            m_output.WriteAttributeString("path", AccessPath(sender as Control));
            m_output.WriteAttributeString("at", "(" + e.X + "," + e.Y + ")");
            if (leafPath.Length > 0)
            {
                m_output.WriteAttributeString("child", leafPath);
            }
            m_output.WriteEndElement();
            m_output.WriteWhitespace("\n");
            m_output.Flush();
        }
コード例 #9
0
        private void SetAccessibleProperties()
        {
            //Here we are consuming the COM Exceptions which happens in case
            //the property/Method we need is not available with IAccessible Object.

            try
            {
                _name = _accessible.get_accName(0);
            }
            catch (Exception ex)
            {
            }

            try
            {
                _value = _accessible.get_accValue(0);
            }
            catch (Exception ex)
            {
            }

            try
            {
                uint stateId = Convert.ToUInt32(_accessible.get_accState(0));
                _state = MSAA.GetStateText(stateId);
            }
            catch (Exception ex)
            {
            }

            try
            {
                uint roleId = Convert.ToUInt32(_accessible.get_accRole(0));
                _role = MSAA.GetRoleText(roleId);
            }
            catch (Exception ex)
            {
            }


            _handle = MSAA.GetHandle(_accessible);

            try
            {
                _defaultAction = _accessible.get_accDefaultAction(0);
            }
            catch (Exception ex)
            {
            }

            SetLocation(_accessible);
        }
コード例 #10
0
        internal string GetAccessibleName(int item)
        {
            string name = null;

            IAccessible acc = AccessibleObject;

            if (acc != null)
            {
                name = acc.get_accName(item);
                name = string.IsNullOrEmpty(name) ? null : name;
            }

            return(name);
        }
コード例 #11
0
        internal static string GetName(IAccessible accObj, int childId)
        {
            string bstr = null;

            try
            {
                bstr = accObj.get_accName(childId);
            }
            catch (Exception exception)
            {
                if (!IsOleAccException(exception) || !IsOleAccExceptionMaskable(exception))
                {
                    throw;
                }
            }
            return(FixBstr(bstr) ?? string.Empty);
        }
コード例 #12
0
ファイル: QqWindowHelper.cs プロジェクト: WillPerfect/TestTk
        public IAccessible GetMsgChild(IAccessible paccContainer)
        {
            try
            {
                string name = (string)paccContainer.get_accName(Win32.CHILDID_SELF);
                if (name == "消息")
                {
                    return(paccContainer);
                }
                else
                {
                    if (paccContainer.accChildCount > 0)
                    {
                        object[] rgvarChildren = new object[paccContainer.accChildCount];
                        int      pcObtained;
                        Win32.AccessibleChildren(paccContainer, 0, paccContainer.accChildCount, rgvarChildren, out pcObtained);
                        foreach (object child in rgvarChildren)
                        {
                            if (child is IAccessible)
                            {
                                IAccessible ret = GetMsgChild((IAccessible)child);
                                if (ret != null)
                                {
                                    return(ret);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
コード例 #13
0
 string?IAccessibleInternal.get_accName(object childID)
 => publicIAccessible.get_accName(childID);
コード例 #14
0
ファイル: Accessible.cs プロジェクト: victor0225/NeuralAction
 public void UpdateName()
 {
     Name = IAccessible.get_accName(ChildId);
 }
コード例 #15
0
 string UnsafeNativeMethods.IAccessibleInternal.get_accName(object childID)
 {
     IntSecurity.UnmanagedCode.Assert();
     return(publicIAccessible.get_accName(childID));
 }
コード例 #16
0
 private string name()
 {
     return(iAccessible.get_accName(0));
 }
コード例 #17
0
        private void getChild(IAccessible iAccessible, bool done)
        {
            if (iAccessible == null)
            {
                Console.WriteLine(" The iAccessible object is null");
                return;
            }
            string accWindowName = iAccessible.get_accName(0);
            string accWindowVal  = iAccessible.get_accValue(0);

            IAccessible[] childs = new IAccessible[iAccessible.accChildCount];

            int obtained = 0;

            AccessibleChildren(iAccessible, 0, iAccessible.accChildCount - 1, childs, out obtained);
            int i = 0;

            foreach (IAccessible child in childs)
            {
                if (child != null && child.GetType().IsCOMObject)
                {
                    Console.WriteLine("The value of i : " + i);
                    i++;
                    if (child == null)
                    {
                        Console.WriteLine("Child is NULL");
                        continue;
                    }
                    string cname  = child.get_accName(0);
                    string cvalue = child.get_accValue(0);
                    string cdesc  = child.get_accDescription(0);
                    int    crole  = child.get_accRole(0);


                    if (cname != null && cname.Trim() != "")
                    {
                        Console.WriteLine("Name is : " + cname);
                    }
                    else
                    {
                        Console.WriteLine("Name is : null");
                    }
                    if (cvalue != null && cvalue.Trim() != "")
                    {
                        Console.WriteLine("Value is : " + cvalue);
                    }
                    else
                    {
                        Console.WriteLine("Value is : null");
                    }

                    if (cdesc != null && cdesc.Trim() != "")
                    {
                        Console.WriteLine("Description is : " + cdesc);
                    }
                    else
                    {
                        Console.WriteLine("Description is : null");
                    }
                    if (crole != null)
                    {
                        Console.WriteLine("Role is : " + crole);
                    }
                    else
                    {
                        Console.WriteLine("Role is : null");
                    }
                    if (cname != null && cname.Contains("Firebug"))
                    {
                        Console.WriteLine("Firebug");
                    }
                    getChild(child, true);
                }
            }
        }
コード例 #18
0
        private void getChild(IAccessible iAccessible,bool done)
        {
            if (iAccessible == null)
            {
                Console.WriteLine(" The iAccessible object is null");
                return;
            }
            string accWindowName = iAccessible.get_accName(0);
            string accWindowVal = iAccessible.get_accValue(0);

            IAccessible[] childs = new IAccessible[iAccessible.accChildCount];

            int obtained = 0;

            AccessibleChildren(iAccessible, 0, iAccessible.accChildCount - 1, childs, out obtained);
            int i = 0;
            foreach (IAccessible child in childs)
            {
                if (child != null && child.GetType().IsCOMObject)
                {
                    Console.WriteLine("The value of i : " + i);
                    i++;
                    if (child == null)
                    {
                        Console.WriteLine("Child is NULL");
                        continue;
                    }
                    string cname = child.get_accName(0);
                    string cvalue = child.get_accValue(0);
                    string cdesc = child.get_accDescription(0);
                    int crole = child.get_accRole(0);

                    if (cname != null && cname.Trim() != "")
                        Console.WriteLine("Name is : " + cname);
                    else
                        Console.WriteLine("Name is : null");
                    if (cvalue != null && cvalue.Trim() != "")
                        Console.WriteLine("Value is : " + cvalue);
                    else
                        Console.WriteLine("Value is : null");

                    if (cdesc != null && cdesc.Trim() != "")
                        Console.WriteLine("Description is : " + cdesc);
                    else
                        Console.WriteLine("Description is : null");
                    if (crole != null)
                        Console.WriteLine("Role is : " + crole);
                    else
                        Console.WriteLine("Role is : null");
                    if (cname!=null && cname.Contains("Firebug"))
                    {
                        Console.WriteLine("Firebug");

                    }
                    getChild(child,true);
                }

            }
        }
コード例 #19
0
        //private static string GetClassNameOfWindow(IntPtr hwnd)
        //{
        //    string className = "";
        //    StringBuilder classText = null;
        //    try
        //    {
        //        int cls_max_length = 1000;
        //        classText = new StringBuilder("", cls_max_length + 5);
        //        GetClassName(hwnd, classText, cls_max_length + 2);

        //        if (!String.IsNullOrEmpty(classText.ToString()) && !String.IsNullOrWhiteSpace(classText.ToString()))
        //            className = classText.ToString();

        //        classText.Clear();

        //    }
        //    catch (Exception ex)
        //    {
        //        className = ex.Message;
        //    }
        //    finally
        //    {
        //        classText = null;
        //    }
        //    return className;
        //}

        private static string windowEventCallback2(IntPtr hWinEventHook, uint eventType,
                                                   IntPtr hwnd,
                                                   int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            //C++ code
            //IAccessible* pAcc = NULL;
            IAccessible pAcc = null;

            string result = null;

            //VARIANT varChild;
            object varChild;


            //HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, pAcc, varChild);
            uint hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, out pAcc, out varChild);

            if ((hr == 0) && (pAcc != null))
            {
                //BSTR bstrName, bstrValue;
                //pAcc->get_accValue(varChild, &bstrValue);
                //pAcc->get_accName(varChild, &bstrName);

                string bstrName  = "";
                string bstrValue = "";

                try
                {
                    if (varChild != null)
                    {
                        //bstrName = pAcc.accValue[varChild];
                        bstrValue = pAcc.get_accValue(varChild);
                        bstrName  = pAcc.get_accName(varChild);
                        //bstrValue = pAcc.accName[varChild];
                    }
                }
                catch (Exception e)
                {
                    //Console.WriteLine(e.Message);
                }

                if (bstrValue != null && !bstrValue.Equals(""))
                {
                    //Console.WriteLine(bstrValue);
                }

                //string className = "";

                //if (isIEServerWindow(hwnd))
                //{
                //    //Console.WriteLine("CEVA");
                //}

                //GetClassNameOfWindow(hwnd);

                StringBuilder sb = new StringBuilder(200);
                GetClassName(hwnd, sb, 100);
                sb.Clear();



                //if (classText != null)
                //{

                //    Console.WriteLine(classText);
                //    //if (!String.IsNullOrEmpty(classText) &&
                //    //!String.IsNullOrWhiteSpace(classText))
                //    //    className = classText;

                //}

                //if (className.Equals("Chrome_WidgetWin_1") && bstrValue != null && !bstrValue.Equals(""))
                //{
                //    Console.WriteLine(className + " -> " + bstrValue);
                //    //result = bstrValue;
                //}

                //if (className.Equals("MozillaWindowClass") && !bstrValue.Equals(""))
                //{
                //    //Console.WriteLine(className + " -> " + bstrValue);
                //    //result = bstrValue;
                //}

                //if (className.Equals("OperaWindowClass") && !bstrValue.Equals(""))
                //{
                //    //Console.WriteLine(className + " -> " + bstrValue);
                //    //result = bstrValue;
                //}

                //pAcc->Release();
            }
            //C++ code

            return(result);
        }
コード例 #20
0
        private void GetEmbeddedObjectText(object embeddedObject, StringBuilder sbText)
        {
            string text;

            IAccessible acc = embeddedObject as IAccessible;

            if (acc != null)
            {
                text = acc.get_accName(NativeMethods.CHILD_SELF);
                if (!string.IsNullOrEmpty(text))
                {
                    sbText.Append(text);
                    return;
                }
            }

            // Didn't get IAccessible (or didn't get a name from it).
            // Try the IDataObject technique instead...

            int         hr         = NativeMethods.S_FALSE;
            IDataObject dataObject = null;
            IOleObject  oleObject  = embeddedObject as IOleObject;

            if (oleObject != null)
            {
                // Try IOleObject::GetClipboardData (which returns an IDataObject) first...
                hr = oleObject.GetClipboardData(0, out dataObject);
            }

            // If that didn't work, try the embeddedObject as a IDataObject instead...
            if (hr != NativeMethods.S_OK)
            {
                dataObject = embeddedObject as IDataObject;
            }

            if (dataObject == null)
            {
                return;
            }

            // Got the IDataObject. Now query it for text formats. Try Unicode first...

            bool fGotUnicode = true;

            UnsafeNativeMethods.FORMATETC fetc = new UnsafeNativeMethods.FORMATETC();
            fetc.cfFormat = DataObjectConstants.CF_UNICODETEXT;
            fetc.ptd      = IntPtr.Zero;
            fetc.dwAspect = DataObjectConstants.DVASPECT_CONTENT;
            fetc.lindex   = -1;
            fetc.tymed    = DataObjectConstants.TYMED_HGLOBAL;

            UnsafeNativeMethods.STGMEDIUM med = new UnsafeNativeMethods.STGMEDIUM();
            med.tymed          = DataObjectConstants.TYMED_HGLOBAL;
            med.pUnkForRelease = IntPtr.Zero;
            med.hGlobal        = IntPtr.Zero;

            hr = dataObject.GetData(ref fetc, ref med);

            if (hr != NativeMethods.S_OK || med.hGlobal == IntPtr.Zero)
            {
                // If we didn't get Unicode, try for ANSI instead...
                fGotUnicode   = false;
                fetc.cfFormat = DataObjectConstants.CF_TEXT;

                hr = dataObject.GetData(ref fetc, ref med);
            }

            // Did we get anything?
            if (hr != NativeMethods.S_OK || med.hGlobal == IntPtr.Zero)
            {
                return;
            }

            //lock the memory, so data can be copied into
            IntPtr globalMem = UnsafeNativeMethods.GlobalLock(med.hGlobal);

            try
            {
                //error check for the memory pointer
                if (globalMem == IntPtr.Zero)
                {
                    return;
                }

                unsafe
                {
                    //get the string
                    if (fGotUnicode)
                    {
                        text = new string((char *)globalMem);
                    }
                    else
                    {
                        text = new string((sbyte *)globalMem);
                    }
                }

                sbText.Append(text);
            }
            finally
            {
                //unlock the memory
                UnsafeNativeMethods.GlobalUnlock(med.hGlobal);
                UnsafeNativeMethods.ReleaseStgMedium(ref med);
            }
        }
コード例 #21
0
 private static string GetName(IAccessible acc, int idChild)
 {
     try
     {
         return FixBstr(acc.get_accName(idChild));
     }
     catch (Exception e)
     {
         if (HandleIAccessibleException(e))
         {
             throw;
         }
         return "";
     }
 }