Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TemplateBamlRecordReader.cs
- HybridObjectCache.cs
- OleDbConnectionFactory.cs
- RemotingException.cs
- ClockController.cs
- DesignerForm.cs
- WorkflowFormatterBehavior.cs
- ValidatorUtils.cs
- SmtpException.cs
- UIPropertyMetadata.cs
- DelimitedListTraceListener.cs
- ManagementInstaller.cs
- BCryptNative.cs
- EntityDataReader.cs
- WindowsRebar.cs
- NullReferenceException.cs
- CharStorage.cs
- DbConnectionPoolGroupProviderInfo.cs
- FormViewPagerRow.cs
- TrustManagerMoreInformation.cs
- ListDataHelper.cs
- SqlNotificationRequest.cs
- ColumnReorderedEventArgs.cs
- ScrollPattern.cs
- SchemaAttDef.cs
- DecoderFallback.cs
- EntityAdapter.cs
- AssemblyAttributesGoHere.cs
- HtmlInputRadioButton.cs
- LocationSectionRecord.cs
- FixedTextPointer.cs
- DynamicMetaObject.cs
- EnumBuilder.cs
- Parser.cs
- ProtocolsConfiguration.cs
- WorkflowMarkupSerializerMapping.cs
- XmlSerializerAssemblyAttribute.cs
- TraceSwitch.cs
- ValidateNames.cs
- IItemContainerGenerator.cs
- MembershipUser.cs
- PropertyChangeTracker.cs
- Vector.cs
- FormViewPageEventArgs.cs
- UIntPtr.cs
- XmlIlVisitor.cs
- Preprocessor.cs
- ConnectionProviderAttribute.cs
- MsmqHostedTransportManager.cs
- DbConnectionPoolGroupProviderInfo.cs
- ConfigurationSectionCollection.cs
- InputLangChangeEvent.cs
- SrgsElement.cs
- AddInStore.cs
- IBuiltInEvidence.cs
- XComponentModel.cs
- ViewBase.cs
- VariableReference.cs
- DtdParser.cs
- BuilderInfo.cs
- XPathNavigatorKeyComparer.cs
- ZipFileInfoCollection.cs
- Lease.cs
- SlipBehavior.cs
- GlobalProxySelection.cs
- TextLine.cs
- XmlSchemaImporter.cs
- ServiceDesigner.xaml.cs
- RIPEMD160.cs
- SystemColors.cs
- SocketManager.cs
- KeyProperty.cs
- TextTreeObjectNode.cs
- SqlConnectionHelper.cs
- DetailsViewDeletedEventArgs.cs
- ColorConverter.cs
- Emitter.cs
- ZoneIdentityPermission.cs
- TableLayoutStyle.cs
- ZoneButton.cs
- TypedTableHandler.cs
- EntityViewContainer.cs
- TextElementCollection.cs
- ImageMap.cs
- shaperfactoryquerycachekey.cs
- StrongNamePublicKeyBlob.cs
- OrderedDictionaryStateHelper.cs
- RadioButtonList.cs
- RequestDescription.cs
- AssemblyCollection.cs
- XmlBinaryReader.cs
- FileReader.cs
- StringFormat.cs
- GeneralTransform3DCollection.cs
- TextEndOfSegment.cs
- RelationshipType.cs
- DesignerVerbCollection.cs
- XDeferredAxisSource.cs
- AvTraceFormat.cs
- DbgUtil.cs