Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / WindowHideOrCloseTracker.cs / 1 / WindowHideOrCloseTracker.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: Class used to track new UI appearing and make sure any events // are propogated to that new UI. // // History: // 11/20/2003 : Micw Created // //--------------------------------------------------------------------------- using System; using System.Text; using System.Windows.Automation; using MS.Win32; using System.Diagnostics; namespace MS.Internal.Automation { // WindowHideOrCloseTracker - Class used to track new UI appearing and make sure any events // are propogated to that new UI. internal delegate void WindowHideOrCloseHandler( IntPtr hwnd, AutomationElement rawEl, int[] runtimeId ); // Class used to track new UI appearing and make sure any events // are propogated to that new UI. internal class WindowHideOrCloseTracker : WinEventWrap { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors internal WindowHideOrCloseTracker(WindowHideOrCloseHandler newUIHandler) : base(new int[] {NativeMethods.EVENT_OBJECT_DESTROY, NativeMethods.EVENT_OBJECT_HIDE}) { AddCallback(newUIHandler); } #endregion Constructors //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods internal override void WinEventProc(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime) { // ignore any event not pertaining directly to the window if (idObject != UnsafeNativeMethods.OBJID_WINDOW) return; // Ignore if this is a bogus hwnd (shouldn't happen) if (hwnd == IntPtr.Zero) return; NativeMethods.HWND nativeHwnd = NativeMethods.HWND.Cast( hwnd ); // Purposefully including windows that have been destroyed (e.g. IsWindow will return // false here for EVENT_OBJECT_DESTROY) because we need that notification. if (eventId == NativeMethods.EVENT_OBJECT_HIDE && !SafeNativeMethods.IsWindow( nativeHwnd )) { return; } int[] runtimeId; AutomationElement rawEl; if (eventId == NativeMethods.EVENT_OBJECT_DESTROY) { // If the window has been destroyed just report the RuntimeId with the event. runtimeId = HwndProxyElementProvider.MakeRuntimeId( nativeHwnd ); rawEl = null; } else { // If the window is just being hidden then can create (and return as event src) a real element rawEl = AutomationElement.FromHandle( hwnd ); runtimeId = rawEl.GetRuntimeId(); } // Do the notify. Note that this handler is used to notify client-side UIAutomation providers of windows // being destroyed or hidden. The delegate called here is itself protected by a lock. This delegate may // call out to proxies but also calls ClientEventManager.RaiseEventInThisClientOnly which properly // queues the actual callout to client code. object[] handlers = GetHandlers(); Debug.Assert(handlers.Length <= 1, "handlers.Length"); if ( handlers.Length > 0 ) ( (WindowHideOrCloseHandler)handlers [0] )( hwnd, rawEl, runtimeId ); } #endregion Internal Methods //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields // no state #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 track new UI appearing and make sure any events // are propogated to that new UI. // // History: // 11/20/2003 : Micw Created // //--------------------------------------------------------------------------- using System; using System.Text; using System.Windows.Automation; using MS.Win32; using System.Diagnostics; namespace MS.Internal.Automation { // WindowHideOrCloseTracker - Class used to track new UI appearing and make sure any events // are propogated to that new UI. internal delegate void WindowHideOrCloseHandler( IntPtr hwnd, AutomationElement rawEl, int[] runtimeId ); // Class used to track new UI appearing and make sure any events // are propogated to that new UI. internal class WindowHideOrCloseTracker : WinEventWrap { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors internal WindowHideOrCloseTracker(WindowHideOrCloseHandler newUIHandler) : base(new int[] {NativeMethods.EVENT_OBJECT_DESTROY, NativeMethods.EVENT_OBJECT_HIDE}) { AddCallback(newUIHandler); } #endregion Constructors //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods internal override void WinEventProc(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime) { // ignore any event not pertaining directly to the window if (idObject != UnsafeNativeMethods.OBJID_WINDOW) return; // Ignore if this is a bogus hwnd (shouldn't happen) if (hwnd == IntPtr.Zero) return; NativeMethods.HWND nativeHwnd = NativeMethods.HWND.Cast( hwnd ); // Purposefully including windows that have been destroyed (e.g. IsWindow will return // false here for EVENT_OBJECT_DESTROY) because we need that notification. if (eventId == NativeMethods.EVENT_OBJECT_HIDE && !SafeNativeMethods.IsWindow( nativeHwnd )) { return; } int[] runtimeId; AutomationElement rawEl; if (eventId == NativeMethods.EVENT_OBJECT_DESTROY) { // If the window has been destroyed just report the RuntimeId with the event. runtimeId = HwndProxyElementProvider.MakeRuntimeId( nativeHwnd ); rawEl = null; } else { // If the window is just being hidden then can create (and return as event src) a real element rawEl = AutomationElement.FromHandle( hwnd ); runtimeId = rawEl.GetRuntimeId(); } // Do the notify. Note that this handler is used to notify client-side UIAutomation providers of windows // being destroyed or hidden. The delegate called here is itself protected by a lock. This delegate may // call out to proxies but also calls ClientEventManager.RaiseEventInThisClientOnly which properly // queues the actual callout to client code. object[] handlers = GetHandlers(); Debug.Assert(handlers.Length <= 1, "handlers.Length"); if ( handlers.Length > 0 ) ( (WindowHideOrCloseHandler)handlers [0] )( hwnd, rawEl, runtimeId ); } #endregion Internal Methods //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ #region Private Fields // no state #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
- BrowserCapabilitiesFactory.cs
- RoutedUICommand.cs
- ActivityTrace.cs
- RuleInfoComparer.cs
- ExpandCollapseProviderWrapper.cs
- XmlSchemaValidationException.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- RuntimeConfigurationRecord.cs
- ServiceModelInstallComponent.cs
- UpdateManifestForBrowserApplication.cs
- pingexception.cs
- RegexGroupCollection.cs
- BaseCollection.cs
- Memoizer.cs
- SafeLocalAllocation.cs
- EntityKeyElement.cs
- SliderAutomationPeer.cs
- CalculatedColumn.cs
- DbConnectionPoolCounters.cs
- Constants.cs
- QilInvokeEarlyBound.cs
- OperationGenerator.cs
- ItemList.cs
- Composition.cs
- ResumeStoryboard.cs
- GridItem.cs
- BinaryNode.cs
- WebContext.cs
- DataGridViewCellPaintingEventArgs.cs
- PriorityChain.cs
- SafeNativeMethods.cs
- MinMaxParagraphWidth.cs
- httpstaticobjectscollection.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- FixedSOMTextRun.cs
- RegionIterator.cs
- TextTreeNode.cs
- BamlCollectionHolder.cs
- BridgeDataRecord.cs
- ContentPlaceHolder.cs
- ObjectListCommand.cs
- CompiledRegexRunner.cs
- PageCatalogPart.cs
- DeriveBytes.cs
- MediaPlayerState.cs
- OAVariantLib.cs
- DataGridViewButtonColumn.cs
- MemoryStream.cs
- TextTreeFixupNode.cs
- RotateTransform.cs
- XmlSchemaDocumentation.cs
- EventLogPermission.cs
- Stream.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- PreservationFileWriter.cs
- XmlDeclaration.cs
- AnnotationHighlightLayer.cs
- JavaScriptString.cs
- PointLightBase.cs
- XPathDocument.cs
- ApplicationHost.cs
- FixedPosition.cs
- DependsOnAttribute.cs
- LinqDataSourceDisposeEventArgs.cs
- XmlSchemaInclude.cs
- TraceHwndHost.cs
- SizeChangedEventArgs.cs
- EncoderReplacementFallback.cs
- Source.cs
- oledbconnectionstring.cs
- LicenseException.cs
- x509utils.cs
- WebPartDescriptionCollection.cs
- WebPartZone.cs
- StateRuntime.cs
- PropertyChangeTracker.cs
- HttpValueCollection.cs
- CompiledIdentityConstraint.cs
- ReadOnlyDataSource.cs
- PropertyMapper.cs
- PropertyCollection.cs
- EncryptedPackage.cs
- DataKeyCollection.cs
- ToolStripRendererSwitcher.cs
- NonParentingControl.cs
- MailMessageEventArgs.cs
- ToolStripKeyboardHandlingService.cs
- WebPartTransformer.cs
- ImportOptions.cs
- WindowsListViewItem.cs
- PointCollectionConverter.cs
- AccessViolationException.cs
- XmlImplementation.cs
- TextPenaltyModule.cs
- ItemCheckEvent.cs
- FontDialog.cs
- COAUTHINFO.cs
- RunInstallerAttribute.cs
- StringUtil.cs
- SmtpReplyReader.cs