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
- ImageMap.cs
- AuthenticationService.cs
- UIElement.cs
- ProxyElement.cs
- MissingSatelliteAssemblyException.cs
- IgnoreDataMemberAttribute.cs
- ProgressChangedEventArgs.cs
- MsdtcClusterUtils.cs
- RijndaelManaged.cs
- WorkflowOperationContext.cs
- SafeViewOfFileHandle.cs
- CharacterShapingProperties.cs
- RelationshipEnd.cs
- HealthMonitoringSection.cs
- SelectorAutomationPeer.cs
- ActivitiesCollection.cs
- ConfigurationPermission.cs
- XmlNode.cs
- XmlSchemaComplexType.cs
- AudioStateChangedEventArgs.cs
- GridLength.cs
- ServicePrincipalNameElement.cs
- Reference.cs
- SqlDataReader.cs
- XmlAutoDetectWriter.cs
- MenuItemStyleCollection.cs
- OleStrCAMarshaler.cs
- AutomationTextAttribute.cs
- Duration.cs
- ProviderSettingsCollection.cs
- CfgParser.cs
- RawStylusInputReport.cs
- CustomTypeDescriptor.cs
- ConcurrentDictionary.cs
- InkCollectionBehavior.cs
- ListViewItemMouseHoverEvent.cs
- RegexCapture.cs
- LineSegment.cs
- PriorityRange.cs
- ThemeDictionaryExtension.cs
- ListViewDataItem.cs
- DiscoveryService.cs
- SamlAssertionDirectKeyIdentifierClause.cs
- Image.cs
- StringUtil.cs
- CrossSiteScriptingValidation.cs
- DoubleStorage.cs
- _NestedMultipleAsyncResult.cs
- JsonByteArrayDataContract.cs
- FontInfo.cs
- PagePropertiesChangingEventArgs.cs
- OracleCommandSet.cs
- WebServiceEndpoint.cs
- baseaxisquery.cs
- Globals.cs
- Html32TextWriter.cs
- AutoGeneratedField.cs
- MouseEventArgs.cs
- XmlLoader.cs
- RuntimeWrappedException.cs
- SqlHelper.cs
- MethodRental.cs
- NegationPusher.cs
- BadImageFormatException.cs
- DataGridHelper.cs
- RepeatButtonAutomationPeer.cs
- ThreadInterruptedException.cs
- NetCodeGroup.cs
- HeaderCollection.cs
- ViewValidator.cs
- DescriptionAttribute.cs
- HostingMessageProperty.cs
- TextTabProperties.cs
- wgx_sdk_version.cs
- MarginCollapsingState.cs
- LocalizationParserHooks.cs
- PersistenceTypeAttribute.cs
- NamespaceDecl.cs
- BitmapScalingModeValidation.cs
- OdbcParameter.cs
- _TLSstream.cs
- ChannelBinding.cs
- Mapping.cs
- SmiMetaData.cs
- AsyncSerializedWorker.cs
- SByteConverter.cs
- DummyDataSource.cs
- IIS7WorkerRequest.cs
- HostedHttpContext.cs
- RichTextBox.cs
- SchemaObjectWriter.cs
- TemplatePagerField.cs
- X509WindowsSecurityToken.cs
- SqlConnectionFactory.cs
- BooleanExpr.cs
- MessageQueueException.cs
- DefaultValueTypeConverter.cs
- SmtpMail.cs
- RemoveStoryboard.cs
- PageCodeDomTreeGenerator.cs