示例#1
0
 /// <summary>
 /// Retrieves the value of a property supported by the UI Automation provider.
 /// (Inherited from IRawElementProviderSimple.)
 /// A provider should return NotSupported only if it is explicitly hiding the
 /// property value and the request is not to be passed through to other
 /// providers.
 /// </summary>
 /// <param name="propertyId">The property identifier.</param>
 /// <returns>The property value, or a null if the property is not supported
 /// by this provider, or NotSupported if it is not supported at all.</returns>
 public Object GetPropertyValue(int propertyId)
 {               // see method doc for non-null example
     if (propertyId == AutomationElementIdentifiers.NameProperty.Id ||
         propertyId == AutomationElementIdentifiers.AutomationIdProperty.Id ||
         propertyId == AutomationElementIdentifiers.ClassNameProperty.Id)
     {
         return("RootSite");
     }
     else if (propertyId == AutomationElementIdentifiers.BoundingRectangleProperty.Id)
     {                   // use hwnd to get bounding rectangle
         Rectangle tempRect = new Rectangle();
         return(GetWindowRect(m_providerHwnd, tempRect));
     }
     else if (propertyId == AutomationElementIdentifiers.ControlTypeProperty.Id)
     {
         return(System.Windows.Automation.ControlType.DataGrid.Id);
     }
     else if (propertyId == AutomationElementIdentifiers.FrameworkIdProperty.Id)
     {
         return("FDO");
     }
     else if (propertyId == AutomationElementIdentifiers.HasKeyboardFocusProperty.Id)
     {                   // use hwnd to determine if this RootSite has focus
                         // Can it ever have it, or does it have it if a child has it?
         IntPtr controlHwnd = GetFocus();
         return(controlHwnd == m_providerHwnd);
     }
     else if (propertyId == AutomationElementIdentifiers.IsContentElementProperty.Id)
     {                         // use hwnd to determine if this RootSite has content (normally true)
         uint   GW_CHILD  = 5; // from C:\Program Files\PlatformSDK\Include\WinUser.h
         IntPtr childHwnd = GetWindow(m_providerHwnd, GW_CHILD);
         return(childHwnd != null);
     }
     else if (propertyId == AutomationElementIdentifiers.IsControlElementProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsEnabledProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsGridPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsKeyboardFocusableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsRangeValuePatternAvailableProperty.Id
              )
     {
         return(true);
     }
     else if (propertyId == AutomationElementIdentifiers.IsDockPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsExpandCollapsePatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsGridItemPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsInvokePatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsMultipleViewPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsPasswordProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsRequiredForFormProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsScrollItemPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsScrollPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsSelectionItemPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsSelectionPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsTableItemPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsTablePatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsTextPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsTogglePatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsTransformPatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsValuePatternAvailableProperty.Id ||
              propertyId == AutomationElementIdentifiers.IsWindowPatternAvailableProperty.Id
              )
     {
         return(false);
     }
     else if (propertyId == AutomationElementIdentifiers.IsOffscreenProperty.Id)
     {                   // use hwnd to determine if this RootSite is off-screen
                         /* The value is true if the element is entirely scrolled out of view (for example, an item in
                          * a list box) or collapsed out of view (for example, an item in a tree view or menu, or a
                          * minimized window). If the element has a clickable point that can cause it to be focused,
                          * it is considered to be onscreen.
                          * The value of the property is not affected by occlusion by other windows, or by whether the
                          * element is visible on a specific monitor.
                          * When the value is true for a container, it is also true for the container element's descendants.
                          */
         return(IsWindowVisible(m_providerHwnd));
     }
     else if (propertyId == AutomationElementIdentifiers.NativeWindowHandleProperty.Id)
     {
         return(m_providerHwnd);
     }
     else if (propertyId == AutomationElementIdentifiers.ProcessIdProperty.Id)
     {                   // use hwnd to find the ProcessID likely "flex"
         IntPtr  procId;
         IntPtr  threadId = GetWindowThreadProcessId(m_providerHwnd, out procId);
         Process proc     = Process.GetProcessById((int)procId);
         return(proc.ProcessName);
     }
     else if (propertyId == AutomationElementIdentifiers.RuntimeIdProperty.Id)
     {                                                                        // use hwnd to find the Runtime Id
         return(new int[] { AutomationInteropProvider.AppendRuntimeId, 20 }); // group ID = 20
     }
     else if (propertyId == AutomationElementIdentifiers.StructureChangedEvent.Id)
     {                            // use hwnd to listen for events that indicate a row was added/deleted
         return(m_ivb.IsDirty()); // (bool) returns true or false
     }
     else if (propertyId == AutomationElementIdentifiers.ClickablePointProperty.Id ||
              propertyId == AutomationElementIdentifiers.CultureProperty.Id ||
              propertyId == AutomationElementIdentifiers.HelpTextProperty.Id ||
              propertyId == AutomationElementIdentifiers.ItemStatusProperty.Id ||
              propertyId == AutomationElementIdentifiers.ItemTypeProperty.Id ||
              propertyId == AutomationElementIdentifiers.LabeledByProperty.Id ||                     // Slices have labels
              propertyId == AutomationElementIdentifiers.LayoutInvalidatedEvent.Id ||
              propertyId == AutomationElementIdentifiers.LocalizedControlTypeProperty.Id ||                     // Yes?
              propertyId == AutomationElementIdentifiers.MenuClosedEvent.Id ||
              propertyId == AutomationElementIdentifiers.MenuOpenedEvent.Id ||
              propertyId == AutomationElementIdentifiers.OrientationProperty.Id ||
              propertyId == AutomationElementIdentifiers.ToolTipClosedEvent.Id ||
              propertyId == AutomationElementIdentifiers.ToolTipOpenedEvent.Id
              )
     {                   // These do not apply to a RootSite
         return(AutomationElementIdentifiers.NotSupported);
     }
     else
     {
         return(null);
     }
 }