Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / Accessible.cs / 1 / Accessible.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Wraps some of IAccessible to support Focus and top-level window creates
//
// History:
// 06/02/2003 : BrendanM Ported to WCP
//
//---------------------------------------------------------------------------
using System.Windows.Automation;
using System;
using Accessibility;
using System.Text;
using System.Diagnostics;
using MS.Win32;
// PRESHARP: In order to avoid generating warnings about unkown message numbers and unknown pragmas.
#pragma warning disable 1634, 1691
namespace MS.Internal.Automation
{
internal class Accessible
{
internal Accessible(IAccessible acc, object child)
{
Debug.Assert(acc != null, "null IAccessible");
_acc = acc;
_child = child;
}
// Create an Accessible object; may return null
internal static Accessible Create( IntPtr hwnd, int idObject, int idChild )
{
IAccessible acc = null;
object child = null;
if( UnsafeNativeMethods.AccessibleObjectFromEvent( hwnd, idObject, idChild, ref acc, ref child ) != 0 /*S_OK*/ || acc == null )
return null;
// Per SDK must use the ppacc and pvarChild from AccessibleObjectFromEvent
// to access information about this UI element.
return new Accessible( acc, child );
}
internal int State
{
get
{
try
{
return (int)_acc.get_accState(_child);
}
catch (Exception e)
{
if (IsCriticalMSAAException(e))
// PRESHARP will flag this as a warning 56503/6503: Property get methods should not throw exceptions
// Since this Property is internal, we CAN throw an exception
#pragma warning suppress 6503
throw;
return UnsafeNativeMethods.STATE_SYSTEM_UNAVAILABLE;
}
}
}
internal IntPtr Window
{
get
{
if (_hwnd == IntPtr.Zero)
{
try
{
if (UnsafeNativeMethods.WindowFromAccessibleObject(_acc, ref _hwnd) != 0/*S_OK*/)
{
_hwnd = IntPtr.Zero;
}
}
catch( Exception e )
{
if (IsCriticalMSAAException(e))
// PRESHARP will flag this as a warning 56503/6503: Property get methods should not throw exceptions
// Since this Property is internal, we CAN throw an exception
#pragma warning suppress 6503
throw;
_hwnd = IntPtr.Zero;
}
}
return _hwnd;
}
}
// miscellaneous functions used with Accessible
internal static bool CompareClass(IntPtr hwnd, string szClass)
{
return ProxyManager.GetClassName(NativeMethods.HWND.Cast(hwnd)) == szClass;
}
internal static bool IsComboDropdown(IntPtr hwnd)
{
return CompareClass(hwnd, "ComboLBox");
}
internal static bool IsStatic(IntPtr hwnd)
{
return CompareClass(hwnd, "Static");
}
private bool IsCriticalMSAAException(Exception e)
{
// Some OLEACC proxies produce out-of-memory for non-critical reasons:
// notably, the treeview proxy will raise this if the target HWND no longer exists,
// GetWindowThreadProcessID fails and it therefore won't be able to allocate shared
// memory in the target process, so it incorrectly assumes OOM.
// Some Native impls (media player) return E_POINTER, which COM Interop translates
// into NullRefException; need to ignore those too.
// should ignore those
return !(e is OutOfMemoryException)
&& !(e is NullReferenceException)
&& Misc.IsCriticalException(e);
}
private IntPtr _hwnd;
private IAccessible _acc;
private Object _child;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Wraps some of IAccessible to support Focus and top-level window creates
//
// History:
// 06/02/2003 : BrendanM Ported to WCP
//
//---------------------------------------------------------------------------
using System.Windows.Automation;
using System;
using Accessibility;
using System.Text;
using System.Diagnostics;
using MS.Win32;
// PRESHARP: In order to avoid generating warnings about unkown message numbers and unknown pragmas.
#pragma warning disable 1634, 1691
namespace MS.Internal.Automation
{
internal class Accessible
{
internal Accessible(IAccessible acc, object child)
{
Debug.Assert(acc != null, "null IAccessible");
_acc = acc;
_child = child;
}
// Create an Accessible object; may return null
internal static Accessible Create( IntPtr hwnd, int idObject, int idChild )
{
IAccessible acc = null;
object child = null;
if( UnsafeNativeMethods.AccessibleObjectFromEvent( hwnd, idObject, idChild, ref acc, ref child ) != 0 /*S_OK*/ || acc == null )
return null;
// Per SDK must use the ppacc and pvarChild from AccessibleObjectFromEvent
// to access information about this UI element.
return new Accessible( acc, child );
}
internal int State
{
get
{
try
{
return (int)_acc.get_accState(_child);
}
catch (Exception e)
{
if (IsCriticalMSAAException(e))
// PRESHARP will flag this as a warning 56503/6503: Property get methods should not throw exceptions
// Since this Property is internal, we CAN throw an exception
#pragma warning suppress 6503
throw;
return UnsafeNativeMethods.STATE_SYSTEM_UNAVAILABLE;
}
}
}
internal IntPtr Window
{
get
{
if (_hwnd == IntPtr.Zero)
{
try
{
if (UnsafeNativeMethods.WindowFromAccessibleObject(_acc, ref _hwnd) != 0/*S_OK*/)
{
_hwnd = IntPtr.Zero;
}
}
catch( Exception e )
{
if (IsCriticalMSAAException(e))
// PRESHARP will flag this as a warning 56503/6503: Property get methods should not throw exceptions
// Since this Property is internal, we CAN throw an exception
#pragma warning suppress 6503
throw;
_hwnd = IntPtr.Zero;
}
}
return _hwnd;
}
}
// miscellaneous functions used with Accessible
internal static bool CompareClass(IntPtr hwnd, string szClass)
{
return ProxyManager.GetClassName(NativeMethods.HWND.Cast(hwnd)) == szClass;
}
internal static bool IsComboDropdown(IntPtr hwnd)
{
return CompareClass(hwnd, "ComboLBox");
}
internal static bool IsStatic(IntPtr hwnd)
{
return CompareClass(hwnd, "Static");
}
private bool IsCriticalMSAAException(Exception e)
{
// Some OLEACC proxies produce out-of-memory for non-critical reasons:
// notably, the treeview proxy will raise this if the target HWND no longer exists,
// GetWindowThreadProcessID fails and it therefore won't be able to allocate shared
// memory in the target process, so it incorrectly assumes OOM.
// Some Native impls (media player) return E_POINTER, which COM Interop translates
// into NullRefException; need to ignore those too.
// should ignore those
return !(e is OutOfMemoryException)
&& !(e is NullReferenceException)
&& Misc.IsCriticalException(e);
}
private IntPtr _hwnd;
private IAccessible _acc;
private Object _child;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ToolStripItemGlyph.cs
- DataQuery.cs
- ConfigErrorGlyph.cs
- TreeNodeBindingCollection.cs
- InkCanvasAutomationPeer.cs
- SQLString.cs
- FaultHandlingFilter.cs
- ErrorStyle.cs
- HMACSHA256.cs
- DBConcurrencyException.cs
- TransportManager.cs
- FillErrorEventArgs.cs
- SafeFileMappingHandle.cs
- ProfilePropertyMetadata.cs
- PipelineComponent.cs
- TypedRowHandler.cs
- ElapsedEventArgs.cs
- Int64Converter.cs
- DesignerHelpers.cs
- Guid.cs
- BounceEase.cs
- EntityDataSourceValidationException.cs
- DiagnosticsConfigurationHandler.cs
- EntityClassGenerator.cs
- PeoplePickerWrapper.cs
- CodeTypeParameterCollection.cs
- WebServiceClientProxyGenerator.cs
- ActivationArguments.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- RecordBuilder.cs
- Span.cs
- OptimalBreakSession.cs
- SourceInterpreter.cs
- GradientStop.cs
- HierarchicalDataTemplate.cs
- RectAnimationBase.cs
- Matrix.cs
- CustomAttributeFormatException.cs
- ThreadInterruptedException.cs
- ValidationError.cs
- SqlTransaction.cs
- CompletedAsyncResult.cs
- FloaterParagraph.cs
- XmlQualifiedNameTest.cs
- OrderedDictionary.cs
- FixedTextBuilder.cs
- EncryptRequest.cs
- BitmapEffectInputData.cs
- TypeConverter.cs
- MimeMapping.cs
- ListView.cs
- _LazyAsyncResult.cs
- ToolboxDataAttribute.cs
- GridViewCancelEditEventArgs.cs
- SortExpressionBuilder.cs
- DesignColumnCollection.cs
- Statements.cs
- ImageAnimator.cs
- AssociationProvider.cs
- CustomAttributeBuilder.cs
- itemelement.cs
- EditingCoordinator.cs
- CapabilitiesUse.cs
- UInt16Converter.cs
- DrawingImage.cs
- SiteOfOriginContainer.cs
- KoreanLunisolarCalendar.cs
- StorageAssociationTypeMapping.cs
- _CommandStream.cs
- PrimaryKeyTypeConverter.cs
- JavaScriptString.cs
- NameValuePermission.cs
- DataGridViewUtilities.cs
- HttpProfileGroupBase.cs
- HuffmanTree.cs
- XmlSchemaType.cs
- GenericWebPart.cs
- EditorZoneBase.cs
- FileClassifier.cs
- PageBuildProvider.cs
- CodePageEncoding.cs
- ExpressionEditorAttribute.cs
- XmlCollation.cs
- ConfigurationConverterBase.cs
- ExeContext.cs
- SQLBoolean.cs
- SizeAnimationClockResource.cs
- XmlHelper.cs
- BaseInfoTable.cs
- BufferAllocator.cs
- SystemIPv6InterfaceProperties.cs
- DebuggerAttributes.cs
- Bezier.cs
- WebBrowsableAttribute.cs
- VirtualPathProvider.cs
- Vector3DIndependentAnimationStorage.cs
- RegexNode.cs
- FrugalList.cs
- XomlCompilerResults.cs
- UseAttributeSetsAction.cs