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 / 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
- FontWeight.cs
- DataTemplate.cs
- DataTableNewRowEvent.cs
- UntrustedRecipientException.cs
- TraceFilter.cs
- ComPlusDiagnosticTraceSchemas.cs
- ApplicationSettingsBase.cs
- ResourcePool.cs
- PieceNameHelper.cs
- newinstructionaction.cs
- _LoggingObject.cs
- User.cs
- TemplateControl.cs
- BamlMapTable.cs
- IIS7UserPrincipal.cs
- SystemColors.cs
- JumpList.cs
- CustomWebEventKey.cs
- GridProviderWrapper.cs
- XmlQualifiedName.cs
- MobilePage.cs
- LoginName.cs
- ChooseAction.cs
- ReferenceService.cs
- BitmapDecoder.cs
- XmlCharacterData.cs
- ReadOnlyAttribute.cs
- DataGridColumnHeader.cs
- TaskFormBase.cs
- BypassElementCollection.cs
- DoubleKeyFrameCollection.cs
- RuleSetCollection.cs
- InputElement.cs
- SimpleWorkerRequest.cs
- ParameterCollection.cs
- UshortList2.cs
- COM2ComponentEditor.cs
- Size.cs
- IPeerNeighbor.cs
- HtmlFormWrapper.cs
- SerializationUtility.cs
- ZipIOBlockManager.cs
- SecurityKeyIdentifier.cs
- WebConfigurationHost.cs
- WebConfigurationHostFileChange.cs
- ApplicationServiceManager.cs
- HelpFileFileNameEditor.cs
- Int64AnimationUsingKeyFrames.cs
- AxisAngleRotation3D.cs
- WorkingDirectoryEditor.cs
- SmiEventStream.cs
- UnmanagedMemoryStreamWrapper.cs
- ObjectView.cs
- AdapterUtil.cs
- TypeUtil.cs
- SessionConnectionReader.cs
- XmlReader.cs
- PtsHost.cs
- SecurityHelper.cs
- ToolStripPanelRow.cs
- XmlSchemaDatatype.cs
- ContentElementAutomationPeer.cs
- login.cs
- StylusDevice.cs
- CDSCollectionETWBCLProvider.cs
- MbpInfo.cs
- MetadataArtifactLoaderFile.cs
- View.cs
- EntityDataSourceMemberPath.cs
- SplitterEvent.cs
- OdbcCommand.cs
- Encoding.cs
- HttpModuleCollection.cs
- ExpressionBuilder.cs
- DataServiceProviderMethods.cs
- ProcessHostServerConfig.cs
- HtmlTextArea.cs
- ClientApiGenerator.cs
- SmiTypedGetterSetter.cs
- ClrProviderManifest.cs
- PublisherIdentityPermission.cs
- StateDesigner.CommentLayoutGlyph.cs
- SqlRecordBuffer.cs
- DefaultEvaluationContext.cs
- EnumBuilder.cs
- RoutingEndpointTrait.cs
- SyntaxCheck.cs
- LoginCancelEventArgs.cs
- TextViewSelectionProcessor.cs
- SchemaSetCompiler.cs
- ProbeDuplexCD1AsyncResult.cs
- WorkflowMarkupSerializer.cs
- URIFormatException.cs
- EtwProvider.cs
- EnumerableRowCollection.cs
- ClientScriptManager.cs
- DrawItemEvent.cs
- NumberSubstitution.cs
- ObjectMemberMapping.cs
- TransformGroup.cs