Exemplo n.º 1
0
        /// <summary>
        /// Get the state text of an accessible object.
        /// </summary>
        /// <param name="stateBit">
        /// One of the object state constants.
        /// http://msdn.microsoft.com/en-us/library/dd373609.aspx
        /// </param>
        /// <returns>The state text of an accessible object</returns>
        public static string GetStateText(MSAAStateConstants stateBit)
        {
            int maxLength            = 1024;
            var focusableStateText   = new StringBuilder(maxLength);
            var sizeableStateText    = new StringBuilder(maxLength);
            var moveableStateText    = new StringBuilder(maxLength);
            var invisibleStateText   = new StringBuilder(maxLength);
            var unavailableStateText = new StringBuilder(maxLength);
            var hasPopupStateText    = new StringBuilder(maxLength);

            if (stateBit == (MSAAStateConstants.STATE_SYSTEM_FOCUSABLE |
                             MSAAStateConstants.STATE_SYSTEM_SIZEABLE |
                             MSAAStateConstants.STATE_SYSTEM_MOVEABLE))
            {
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_FOCUSABLE,
                                           focusableStateText, (uint)focusableStateText.Capacity);
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_SIZEABLE,
                                           sizeableStateText, (uint)sizeableStateText.Capacity);
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_MOVEABLE,
                                           moveableStateText, (uint)moveableStateText.Capacity);
                return(focusableStateText + "," + sizeableStateText + "," + moveableStateText);
            }

            if (stateBit == (MSAAStateConstants.STATE_SYSTEM_FOCUSABLE |
                             MSAAStateConstants.STATE_SYSTEM_INVISIBLE))
            {
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_FOCUSABLE,
                                           focusableStateText, (uint)focusableStateText.Capacity);
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_INVISIBLE,
                                           invisibleStateText, (uint)invisibleStateText.Capacity);

                return(focusableStateText + "," + invisibleStateText);
            }
            if (stateBit == (MSAAStateConstants.STATE_SYSTEM_FOCUSABLE |
                             MSAAStateConstants.STATE_SYSTEM_UNAVAILABLE))
            {
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_FOCUSABLE,
                                           focusableStateText, (uint)focusableStateText.Capacity);
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_UNAVAILABLE,
                                           unavailableStateText, (uint)unavailableStateText.Capacity);

                return(focusableStateText + "," + unavailableStateText);
            }
            if (stateBit == (MSAAStateConstants.STATE_SYSTEM_HASPOPUP |
                             MSAAStateConstants.STATE_SYSTEM_UNAVAILABLE))
            {
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_HASPOPUP,
                                           hasPopupStateText, (uint)hasPopupStateText.Capacity);
                NativeMethods.GetStateText(MSAAStateConstants.STATE_SYSTEM_UNAVAILABLE,
                                           unavailableStateText, (uint)unavailableStateText.Capacity);

                return(hasPopupStateText + "," + unavailableStateText);
            }

            var stateText = new StringBuilder(maxLength);

            NativeMethods.GetStateText(stateBit, stateText, (uint)stateText.Capacity);
            return(stateText.ToString());
        }
 public static extern uint GetStateText(MSAAStateConstants dwStateBit,
                                        [Out] StringBuilder lpszStateBit, uint cchStateBitMax);