Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / BoundingRectTracker.cs / 1 / BoundingRectTracker.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Class used to send BoundingRect changes for hwnds
//
// History:
// 06/17/2003 : BrendanM Ported to WCP
//
//---------------------------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Automation;
using System.Runtime.InteropServices;
using System.ComponentModel;
using MS.Win32;
namespace MS.Internal.Automation
{
// BoundingRectTracker - Class used to send BoundingRect changes for hwnds
internal class BoundingRectTracker : WinEventWrap
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
internal BoundingRectTracker()
: base(new int[]{NativeMethods.EVENT_OBJECT_LOCATIONCHANGE, NativeMethods.EVENT_OBJECT_HIDE})
{
// Intentionally not setting the callback for the base WinEventWrap since the WinEventProc override
// in this class calls RaiseEventInThisClientOnly to actually raise the event to the client.
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
internal override void WinEventProc(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
{
// Filter... send an event for hwnd only
if ( hwnd == IntPtr.Zero || idObject != UnsafeNativeMethods.OBJID_WINDOW )
return;
switch (eventId)
{
case NativeMethods.EVENT_OBJECT_HIDE: OnHide(hwnd, idObject, idChild); break;
case NativeMethods.EVENT_OBJECT_LOCATIONCHANGE: OnLocationChange(hwnd, idObject, idChild); break;
}
}
#endregion Internal Methods
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
private void OnHide(IntPtr hwnd, int idObject, int idChild)
{
// Clear last hwnd/rect variables (stop looking for dups)
_lastHwnd = hwnd;
_lastRect = _emptyRect;
}
private void OnLocationChange(IntPtr hwnd, int idObject, int idChild)
{
// Filter... send events for visible hwnds only
if (!SafeNativeMethods.IsWindowVisible(NativeMethods.HWND.Cast( hwnd )))
return;
HandleBoundingRectChange(hwnd);
}
private void HandleBoundingRectChange(IntPtr hwnd)
{
NativeMethods.HWND nativeHwnd = NativeMethods.HWND.Cast( hwnd );
NativeMethods.RECT rc32 = new NativeMethods.RECT(0,0,0,0);
// if GetWindwRect fails, most likely the nativeHwnd is an invalid window, so just return.
if (!Misc.GetWindowRect(nativeHwnd, out rc32))
{
return;
}
// Filter... avoid duplicate events
if (hwnd == _lastHwnd && Compare( rc32, _lastRect ))
{
return;
}
AutomationElement rawEl = AutomationElement.FromHandle(hwnd);
//
//
AutomationPropertyChangedEventArgs e = new AutomationPropertyChangedEventArgs(
AutomationElement.BoundingRectangleProperty,
Rect.Empty,
new Rect (rc32.left, rc32.top, rc32.right - rc32.left, rc32.bottom - rc32.top));
//
ClientEventManager.RaiseEventInThisClientOnly(AutomationElement.AutomationPropertyChangedEvent, rawEl, e);
// save the last hwnd/rect for filtering out duplicates
_lastHwnd = hwnd;
_lastRect = rc32;
}
//
private static bool Compare( NativeMethods.RECT rc1, NativeMethods.RECT rc2 )
{
return rc1.left == rc2.left
&& rc1.top == rc2.top
&& rc1.right == rc2.right
&& rc1.bottom == rc2.bottom;
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private static NativeMethods.RECT _emptyRect = new NativeMethods.RECT(0,0,0,0);
private NativeMethods.RECT _lastRect; // keep track of last location
private IntPtr _lastHwnd; // and hwnd for dup checking
#endregion Private Fields
}
}
// 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: Class used to send BoundingRect changes for hwnds
//
// History:
// 06/17/2003 : BrendanM Ported to WCP
//
//---------------------------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Automation;
using System.Runtime.InteropServices;
using System.ComponentModel;
using MS.Win32;
namespace MS.Internal.Automation
{
// BoundingRectTracker - Class used to send BoundingRect changes for hwnds
internal class BoundingRectTracker : WinEventWrap
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
internal BoundingRectTracker()
: base(new int[]{NativeMethods.EVENT_OBJECT_LOCATIONCHANGE, NativeMethods.EVENT_OBJECT_HIDE})
{
// Intentionally not setting the callback for the base WinEventWrap since the WinEventProc override
// in this class calls RaiseEventInThisClientOnly to actually raise the event to the client.
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
internal override void WinEventProc(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime)
{
// Filter... send an event for hwnd only
if ( hwnd == IntPtr.Zero || idObject != UnsafeNativeMethods.OBJID_WINDOW )
return;
switch (eventId)
{
case NativeMethods.EVENT_OBJECT_HIDE: OnHide(hwnd, idObject, idChild); break;
case NativeMethods.EVENT_OBJECT_LOCATIONCHANGE: OnLocationChange(hwnd, idObject, idChild); break;
}
}
#endregion Internal Methods
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
private void OnHide(IntPtr hwnd, int idObject, int idChild)
{
// Clear last hwnd/rect variables (stop looking for dups)
_lastHwnd = hwnd;
_lastRect = _emptyRect;
}
private void OnLocationChange(IntPtr hwnd, int idObject, int idChild)
{
// Filter... send events for visible hwnds only
if (!SafeNativeMethods.IsWindowVisible(NativeMethods.HWND.Cast( hwnd )))
return;
HandleBoundingRectChange(hwnd);
}
private void HandleBoundingRectChange(IntPtr hwnd)
{
NativeMethods.HWND nativeHwnd = NativeMethods.HWND.Cast( hwnd );
NativeMethods.RECT rc32 = new NativeMethods.RECT(0,0,0,0);
// if GetWindwRect fails, most likely the nativeHwnd is an invalid window, so just return.
if (!Misc.GetWindowRect(nativeHwnd, out rc32))
{
return;
}
// Filter... avoid duplicate events
if (hwnd == _lastHwnd && Compare( rc32, _lastRect ))
{
return;
}
AutomationElement rawEl = AutomationElement.FromHandle(hwnd);
//
//
AutomationPropertyChangedEventArgs e = new AutomationPropertyChangedEventArgs(
AutomationElement.BoundingRectangleProperty,
Rect.Empty,
new Rect (rc32.left, rc32.top, rc32.right - rc32.left, rc32.bottom - rc32.top));
//
ClientEventManager.RaiseEventInThisClientOnly(AutomationElement.AutomationPropertyChangedEvent, rawEl, e);
// save the last hwnd/rect for filtering out duplicates
_lastHwnd = hwnd;
_lastRect = rc32;
}
//
private static bool Compare( NativeMethods.RECT rc1, NativeMethods.RECT rc2 )
{
return rc1.left == rc2.left
&& rc1.top == rc2.top
&& rc1.right == rc2.right
&& rc1.bottom == rc2.bottom;
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
private static NativeMethods.RECT _emptyRect = new NativeMethods.RECT(0,0,0,0);
private NativeMethods.RECT _lastRect; // keep track of last location
private IntPtr _lastHwnd; // and hwnd for dup checking
#endregion Private Fields
}
}
// 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
- TextBoxBase.cs
- RectKeyFrameCollection.cs
- GridEntryCollection.cs
- OperatingSystem.cs
- StatusBar.cs
- typedescriptorpermission.cs
- Propagator.ExtentPlaceholderCreator.cs
- EmptyCollection.cs
- WebBrowserSiteBase.cs
- SqlDependencyListener.cs
- RectangleConverter.cs
- AbsoluteQuery.cs
- FormsAuthenticationUserCollection.cs
- StylusPointPropertyInfo.cs
- HitTestParameters3D.cs
- CollectionsUtil.cs
- ValidatingReaderNodeData.cs
- AndCondition.cs
- ServiceDescription.cs
- DataGridViewColumnTypePicker.cs
- XmlHierarchicalDataSourceView.cs
- CmsUtils.cs
- StandardToolWindows.cs
- Instrumentation.cs
- TimeIntervalCollection.cs
- View.cs
- DefaultTextStoreTextComposition.cs
- UseLicense.cs
- Helpers.cs
- StructuralType.cs
- SafeThreadHandle.cs
- MediaTimeline.cs
- DtrList.cs
- BrowserCapabilitiesFactory.cs
- MsmqQueue.cs
- DispatcherSynchronizationContext.cs
- DataPager.cs
- BindingNavigator.cs
- ObfuscateAssemblyAttribute.cs
- CodeTypeReferenceExpression.cs
- NotifyInputEventArgs.cs
- AndAlso.cs
- XmlSchemaAnnotated.cs
- ActivityInterfaces.cs
- coordinatorfactory.cs
- SiteMap.cs
- TaskExceptionHolder.cs
- QueueProcessor.cs
- ChtmlLinkAdapter.cs
- MSAAEventDispatcher.cs
- TextTreeUndo.cs
- ListGeneralPage.cs
- ApplicationFileParser.cs
- Command.cs
- SqlNodeAnnotations.cs
- DirectoryRootQuery.cs
- IndentTextWriter.cs
- TemplatedControlDesigner.cs
- AnnotationHelper.cs
- HtmlEmptyTagControlBuilder.cs
- GenericsInstances.cs
- MenuItemBindingCollection.cs
- HyperLinkStyle.cs
- Application.cs
- AtomServiceDocumentSerializer.cs
- HandlerMappingMemo.cs
- DecoderBestFitFallback.cs
- WebEncodingValidatorAttribute.cs
- SqlTypeConverter.cs
- CodeDirectiveCollection.cs
- JapaneseLunisolarCalendar.cs
- UriScheme.cs
- IndexerNameAttribute.cs
- FilteredDataSetHelper.cs
- MenuCommand.cs
- AddInProcess.cs
- VectorKeyFrameCollection.cs
- LinearQuaternionKeyFrame.cs
- KerberosSecurityTokenAuthenticator.cs
- IssuanceLicense.cs
- Light.cs
- DataGridViewEditingControlShowingEventArgs.cs
- OperationCanceledException.cs
- CheckedListBox.cs
- SoapAttributeAttribute.cs
- SQLDateTime.cs
- EntityClientCacheEntry.cs
- TransactionContextManager.cs
- EditorZoneBase.cs
- ElapsedEventArgs.cs
- MenuItem.cs
- CodeGenerationManager.cs
- HierarchicalDataSourceControl.cs
- Material.cs
- MD5CryptoServiceProvider.cs
- DataGridState.cs
- LayoutTableCell.cs
- RSACryptoServiceProvider.cs
- SortDescription.cs
- DataDocumentXPathNavigator.cs