Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / MenuTracker.cs / 1 / MenuTracker.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: Class used to track context menus appearing // // History: // 3/23/2004 : preid Created // //--------------------------------------------------------------------------- using System; using System.Text; using System.Windows.Automation; using System.Diagnostics; using MS.Win32; namespace MS.Internal.Automation { internal delegate void MenuHandler( AutomationElement rawEl, bool menuHasOpened ); // MenuOpened - Class used to track context menus appearing internal class MenuTracker : WinEventWrap { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors internal MenuTracker(MenuHandler newHandler) : base(new int[] {NativeMethods.EVENT_SYSTEM_MENUPOPUPSTART, NativeMethods.EVENT_SYSTEM_MENUPOPUPEND}) { AddCallback(newHandler); } #endregion Constructors //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods internal override void WinEventProc(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime) { AutomationElement rawEl = null; bool menuHasOpened = eventId == NativeMethods.EVENT_SYSTEM_MENUPOPUPSTART; // Only create a raw element wrapper if the menu has popped up. Send a // null element for menu closed (the element isn't available anymore). // if( menuHasOpened ) { // Ignore if this is a bogus hwnd (shouldn't happen) if( hwnd == IntPtr.Zero ) return; NativeMethods.HWND nativeHwnd = NativeMethods.HWND.Cast( hwnd ); if( !SafeNativeMethods.IsWindow( nativeHwnd ) ) return; // Filter... send events for visible hwnds only if( !SafeNativeMethods.IsWindowVisible( nativeHwnd ) ) return; rawEl = AutomationElement.FromHandle( hwnd ); } // Do callback. This handler is called due to a WinEvent on the client. The handler // is going to hand off the work of calling out to the client code to another thread // via a queue so it is safe to do this callback w/in the lock. object [] handlers = GetHandlers(); Debug.Assert(handlers.Length <= 1, "handlers.Length"); if( handlers.Length > 0 ) ( ( MenuHandler )handlers[0] )( rawEl, menuHasOpened ); } #endregion Internal Methods } } // 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 context menus appearing // // History: // 3/23/2004 : preid Created // //--------------------------------------------------------------------------- using System; using System.Text; using System.Windows.Automation; using System.Diagnostics; using MS.Win32; namespace MS.Internal.Automation { internal delegate void MenuHandler( AutomationElement rawEl, bool menuHasOpened ); // MenuOpened - Class used to track context menus appearing internal class MenuTracker : WinEventWrap { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors internal MenuTracker(MenuHandler newHandler) : base(new int[] {NativeMethods.EVENT_SYSTEM_MENUPOPUPSTART, NativeMethods.EVENT_SYSTEM_MENUPOPUPEND}) { AddCallback(newHandler); } #endregion Constructors //------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- #region Internal Methods internal override void WinEventProc(int eventId, IntPtr hwnd, int idObject, int idChild, uint eventTime) { AutomationElement rawEl = null; bool menuHasOpened = eventId == NativeMethods.EVENT_SYSTEM_MENUPOPUPSTART; // Only create a raw element wrapper if the menu has popped up. Send a // null element for menu closed (the element isn't available anymore). // if( menuHasOpened ) { // Ignore if this is a bogus hwnd (shouldn't happen) if( hwnd == IntPtr.Zero ) return; NativeMethods.HWND nativeHwnd = NativeMethods.HWND.Cast( hwnd ); if( !SafeNativeMethods.IsWindow( nativeHwnd ) ) return; // Filter... send events for visible hwnds only if( !SafeNativeMethods.IsWindowVisible( nativeHwnd ) ) return; rawEl = AutomationElement.FromHandle( hwnd ); } // Do callback. This handler is called due to a WinEvent on the client. The handler // is going to hand off the work of calling out to the client code to another thread // via a queue so it is safe to do this callback w/in the lock. object [] handlers = GetHandlers(); Debug.Assert(handlers.Length <= 1, "handlers.Length"); if( handlers.Length > 0 ) ( ( MenuHandler )handlers[0] )( rawEl, menuHasOpened ); } #endregion Internal Methods } } // 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
- SectionUpdates.cs
- MDIControlStrip.cs
- PathFigure.cs
- CollectionAdapters.cs
- CompositeDataBoundControl.cs
- TrackingServices.cs
- cookiecollection.cs
- ChannelEndpointElementCollection.cs
- PageThemeParser.cs
- UrlMapping.cs
- BaseHashHelper.cs
- SafeNativeMethods.cs
- ByteStorage.cs
- DetailsViewDeletedEventArgs.cs
- ElementHost.cs
- oledbmetadatacollectionnames.cs
- ContextMarshalException.cs
- SinglePhaseEnlistment.cs
- XhtmlConformanceSection.cs
- PageSettings.cs
- GridProviderWrapper.cs
- NativeMethods.cs
- HostTimeoutsElement.cs
- StartUpEventArgs.cs
- ExceptionDetail.cs
- Certificate.cs
- AutomationProperties.cs
- StorageEntitySetMapping.cs
- WpfPayload.cs
- _SingleItemRequestCache.cs
- DbReferenceCollection.cs
- SystemIPInterfaceStatistics.cs
- TimersDescriptionAttribute.cs
- WebServiceErrorEvent.cs
- SecurityUtils.cs
- TypeLibConverter.cs
- IndicFontClient.cs
- Constraint.cs
- RemotingConfiguration.cs
- ColorDialog.cs
- _DisconnectOverlappedAsyncResult.cs
- TextRunTypographyProperties.cs
- BitmapData.cs
- SettingsAttributes.cs
- WbemException.cs
- StreamUpdate.cs
- DataGridViewColumn.cs
- DataGridViewColumnStateChangedEventArgs.cs
- DynamicDocumentPaginator.cs
- ToolBarButton.cs
- ColorAnimation.cs
- AlgoModule.cs
- XPathConvert.cs
- StreamResourceInfo.cs
- storepermission.cs
- NaturalLanguageHyphenator.cs
- AddDataControlFieldDialog.cs
- EventsTab.cs
- XmlJsonWriter.cs
- EntityCollectionChangedParams.cs
- ExpandCollapseProviderWrapper.cs
- Geometry3D.cs
- SubqueryRules.cs
- SignatureConfirmationElement.cs
- SerializationException.cs
- HandleTable.cs
- InvalidWMPVersionException.cs
- PrimitiveType.cs
- Int32Storage.cs
- Vector.cs
- BCLDebug.cs
- TableDetailsRow.cs
- RenderCapability.cs
- SessionState.cs
- NamedObject.cs
- Lock.cs
- DataGridColumnHeaderCollection.cs
- SecurityKeyType.cs
- FloaterParaClient.cs
- CodeSnippetStatement.cs
- RangeContentEnumerator.cs
- X509IssuerSerialKeyIdentifierClause.cs
- BooleanAnimationUsingKeyFrames.cs
- RegionData.cs
- UIntPtr.cs
- WrapPanel.cs
- coordinator.cs
- StructuredTypeInfo.cs
- SmtpFailedRecipientsException.cs
- ConfigXmlAttribute.cs
- DecoderBestFitFallback.cs
- FacetDescription.cs
- XmlSchemaSimpleContentExtension.cs
- MailAddress.cs
- ExternalCalls.cs
- SchemaTypeEmitter.cs
- OperationDescriptionCollection.cs
- DeferredRunTextReference.cs
- RequestNavigateEventArgs.cs
- Merger.cs