Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / UIAutomation / UIAutomationClient / MS / Internal / Automation / MenuTracker.cs / 1305600 / 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
- TableLayoutPanelDesigner.cs
- FilterElement.cs
- SqlDependencyUtils.cs
- LinkedDataMemberFieldEditor.cs
- StylusPoint.cs
- KeyEvent.cs
- uribuilder.cs
- HtmlForm.cs
- ContainerUtilities.cs
- Stream.cs
- OLEDB_Util.cs
- AccessDataSource.cs
- DocumentViewerBase.cs
- DrawingCollection.cs
- SafeRegistryKey.cs
- XmlUtil.cs
- Margins.cs
- ListViewUpdatedEventArgs.cs
- SymbolDocumentGenerator.cs
- ComponentCommands.cs
- Int32EqualityComparer.cs
- StateItem.cs
- DateTimeFormat.cs
- Opcode.cs
- DigitShape.cs
- XmlSchemaInfo.cs
- CheckedPointers.cs
- GeometryDrawing.cs
- TraceSection.cs
- PropertyEmitterBase.cs
- ReadOnlyPermissionSet.cs
- SqlAliasesReferenced.cs
- DataBoundControlActionList.cs
- SecureEnvironment.cs
- TypeValidationEventArgs.cs
- HtmlTextArea.cs
- PageCache.cs
- RequestCachingSection.cs
- RotateTransform3D.cs
- BamlVersionHeader.cs
- Cursors.cs
- RemoteWebConfigurationHostServer.cs
- ContentValidator.cs
- Solver.cs
- WindowsListViewGroupSubsetLink.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- CalendarData.cs
- XmlUnspecifiedAttribute.cs
- CodeRemoveEventStatement.cs
- DictionaryContent.cs
- DbParameterHelper.cs
- BmpBitmapDecoder.cs
- OutputCacheProfile.cs
- RtfToXamlLexer.cs
- DataBindEngine.cs
- DbConnectionPoolIdentity.cs
- CodeIndexerExpression.cs
- SqlTypesSchemaImporter.cs
- DependencyPropertyDescriptor.cs
- PackUriHelper.cs
- ToolStripProgressBar.cs
- Normalization.cs
- FileBasedResourceGroveler.cs
- DispatcherExceptionEventArgs.cs
- BitmapEffectInput.cs
- Rectangle.cs
- DbConnectionStringCommon.cs
- BitmapCodecInfoInternal.cs
- OdbcErrorCollection.cs
- CorrelationQuery.cs
- CallbackHandler.cs
- WindowsListViewItem.cs
- XmlILConstructAnalyzer.cs
- CheckBox.cs
- WindowsListViewGroupHelper.cs
- ProcessInputEventArgs.cs
- GradientStopCollection.cs
- CodeSnippetStatement.cs
- While.cs
- WindowsSecurityTokenAuthenticator.cs
- WebHttpBindingElement.cs
- RegexWriter.cs
- OracleParameter.cs
- DecoderNLS.cs
- SingleResultAttribute.cs
- InternalConfigHost.cs
- ListenerElementsCollection.cs
- WebResponse.cs
- FixUpCollection.cs
- PagesSection.cs
- EntityDataSourceContextDisposingEventArgs.cs
- ObjectDataSourceStatusEventArgs.cs
- SelectionItemProviderWrapper.cs
- ControlAdapter.cs
- ListViewItem.cs
- WorkflowOperationBehavior.cs
- CodeAttachEventStatement.cs
- ProtocolsConfigurationHandler.cs
- HttpModuleCollection.cs
- CustomAttribute.cs