Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / System / Windows / InterOp / HwndAppCommandInputProvider.cs / 1 / HwndAppCommandInputProvider.cs
using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using MS.Utility; using MS.Internal; using MS.Win32; namespace System.Windows.Interop { internal sealed class HwndAppCommandInputProvider : DispatcherObject, IInputProvider, IDisposable { ////// Accesses and store critical data. This class is also critical (_site and _source) /// [SecurityCritical] internal HwndAppCommandInputProvider( HwndSource source ) { (new UIPermission(PermissionState.Unrestricted)).Assert(); try { _site = new SecurityCriticalDataClass(InputManager.Current.RegisterInputProvider(this)); } finally { UIPermission.RevertAssert(); } _source = new SecurityCriticalDataClass (source); } /// /// Critical:This class accesses critical data, _site. /// TreatAsSafe: This class does not expose the critical data /// [SecurityCritical, SecurityTreatAsSafe] public void Dispose( ) { if (_site != null) { _site.Value.Dispose(); _site = null; } _source = null; } ////// Critical: As this accesses critical data HwndSource /// TreatAsSafe:Information about whether a given input provider services /// a visual is safe to expose. This method does not expose the critical data either. /// [SecurityCritical, SecurityTreatAsSafe] bool IInputProvider.ProvidesInputForRootVisual( Visual v ) { Debug.Assert(null != _source); return _source.Value.RootVisual == v; } void IInputProvider.NotifyDeactivate() {} ////// Critical: As this accesses critical data HwndSource /// [SecurityCritical] internal IntPtr FilterMessage( IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled ) { // It is possible to be re-entered during disposal. Just return. if(null == _source || null == _source.Value) { return IntPtr.Zero; } if (msg == NativeMethods.WM_APPCOMMAND) { // WM_APPCOMMAND message notifies a window that the user generated an application command event, // for example, by clicking an application command button using the mouse or typing an application command // key on the keyboard. RawAppCommandInputReport report = new RawAppCommandInputReport( _source.Value, InputMode.Foreground, SafeNativeMethods.GetMessageTime(), GetAppCommand(lParam), GetDevice(lParam), InputType.Command); handled = _site.Value.ReportInput(report); } return handled ? new IntPtr(1) : IntPtr.Zero ; } ////// Implementation of the GET_APPCOMMAND_LPARAM macro defined in Winuser.h /// /// ///private static int GetAppCommand( IntPtr lParam ) { return ((short)(NativeMethods.SignedHIWORD(NativeMethods.IntPtrToInt32(lParam)) & ~NativeMethods.FAPPCOMMAND_MASK)); } /// /// Returns the input device that originated this app command. /// InputType.Hid represents an unspecified device that is neither the /// keyboard nor the mouse. /// /// ///private static InputType GetDevice(IntPtr lParam) { InputType inputType = InputType.Hid; // Implementation of the GET_DEVICE_LPARAM macro defined in Winuser.h // Returns either FAPPCOMMAND_KEY (the user pressed a key), FAPPCOMMAND_MOUSE // (the user clicked a mouse button) or FAPPCOMMAND_OEM (unknown device) ushort deviceId = (ushort)(NativeMethods.SignedHIWORD(NativeMethods.IntPtrToInt32(lParam)) & NativeMethods.FAPPCOMMAND_MASK); switch (deviceId) { case NativeMethods.FAPPCOMMAND_MOUSE: inputType = InputType.Mouse; break; case NativeMethods.FAPPCOMMAND_KEY: inputType = InputType.Keyboard; break; case NativeMethods.FAPPCOMMAND_OEM: default: // Unknown device id or FAPPCOMMAND_OEM. // In either cases we set it to the generic human interface device. inputType=InputType.Hid; break; } return inputType; } /// /// This is got under an elevation and is hence critical. This data is not ok to expose. /// private SecurityCriticalDataClass_source; /// /// This is got under an elevation and is hence critical.This data is not ok to expose. /// private SecurityCriticalDataClass_site; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; using MS.Utility; using MS.Internal; using MS.Win32; namespace System.Windows.Interop { internal sealed class HwndAppCommandInputProvider : DispatcherObject, IInputProvider, IDisposable { /// /// Accesses and store critical data. This class is also critical (_site and _source) /// [SecurityCritical] internal HwndAppCommandInputProvider( HwndSource source ) { (new UIPermission(PermissionState.Unrestricted)).Assert(); try { _site = new SecurityCriticalDataClass(InputManager.Current.RegisterInputProvider(this)); } finally { UIPermission.RevertAssert(); } _source = new SecurityCriticalDataClass (source); } /// /// Critical:This class accesses critical data, _site. /// TreatAsSafe: This class does not expose the critical data /// [SecurityCritical, SecurityTreatAsSafe] public void Dispose( ) { if (_site != null) { _site.Value.Dispose(); _site = null; } _source = null; } ////// Critical: As this accesses critical data HwndSource /// TreatAsSafe:Information about whether a given input provider services /// a visual is safe to expose. This method does not expose the critical data either. /// [SecurityCritical, SecurityTreatAsSafe] bool IInputProvider.ProvidesInputForRootVisual( Visual v ) { Debug.Assert(null != _source); return _source.Value.RootVisual == v; } void IInputProvider.NotifyDeactivate() {} ////// Critical: As this accesses critical data HwndSource /// [SecurityCritical] internal IntPtr FilterMessage( IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled ) { // It is possible to be re-entered during disposal. Just return. if(null == _source || null == _source.Value) { return IntPtr.Zero; } if (msg == NativeMethods.WM_APPCOMMAND) { // WM_APPCOMMAND message notifies a window that the user generated an application command event, // for example, by clicking an application command button using the mouse or typing an application command // key on the keyboard. RawAppCommandInputReport report = new RawAppCommandInputReport( _source.Value, InputMode.Foreground, SafeNativeMethods.GetMessageTime(), GetAppCommand(lParam), GetDevice(lParam), InputType.Command); handled = _site.Value.ReportInput(report); } return handled ? new IntPtr(1) : IntPtr.Zero ; } ////// Implementation of the GET_APPCOMMAND_LPARAM macro defined in Winuser.h /// /// ///private static int GetAppCommand( IntPtr lParam ) { return ((short)(NativeMethods.SignedHIWORD(NativeMethods.IntPtrToInt32(lParam)) & ~NativeMethods.FAPPCOMMAND_MASK)); } /// /// Returns the input device that originated this app command. /// InputType.Hid represents an unspecified device that is neither the /// keyboard nor the mouse. /// /// ///private static InputType GetDevice(IntPtr lParam) { InputType inputType = InputType.Hid; // Implementation of the GET_DEVICE_LPARAM macro defined in Winuser.h // Returns either FAPPCOMMAND_KEY (the user pressed a key), FAPPCOMMAND_MOUSE // (the user clicked a mouse button) or FAPPCOMMAND_OEM (unknown device) ushort deviceId = (ushort)(NativeMethods.SignedHIWORD(NativeMethods.IntPtrToInt32(lParam)) & NativeMethods.FAPPCOMMAND_MASK); switch (deviceId) { case NativeMethods.FAPPCOMMAND_MOUSE: inputType = InputType.Mouse; break; case NativeMethods.FAPPCOMMAND_KEY: inputType = InputType.Keyboard; break; case NativeMethods.FAPPCOMMAND_OEM: default: // Unknown device id or FAPPCOMMAND_OEM. // In either cases we set it to the generic human interface device. inputType=InputType.Hid; break; } return inputType; } /// /// This is got under an elevation and is hence critical. This data is not ok to expose. /// private SecurityCriticalDataClass_source; /// /// This is got under an elevation and is hence critical.This data is not ok to expose. /// private SecurityCriticalDataClass_site; } } // 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
- DelegatingTypeDescriptionProvider.cs
- GetPageCompletedEventArgs.cs
- TreeBuilderXamlTranslator.cs
- ScriptModule.cs
- RTTrackingProfile.cs
- XhtmlBasicControlAdapter.cs
- FillRuleValidation.cs
- CacheVirtualItemsEvent.cs
- SqlTypeConverter.cs
- RuntimeWrappedException.cs
- CompilerResults.cs
- Image.cs
- KeyedHashAlgorithm.cs
- CookieHandler.cs
- TextBoxView.cs
- ContentDisposition.cs
- DSACryptoServiceProvider.cs
- ProfilePropertySettings.cs
- X509IssuerSerialKeyIdentifierClause.cs
- ProfileSettingsCollection.cs
- EntityContainer.cs
- EnumType.cs
- FunctionDescription.cs
- ControlAdapter.cs
- BooleanFunctions.cs
- XmlText.cs
- CharKeyFrameCollection.cs
- TdsParser.cs
- ListItemCollection.cs
- RemotingServices.cs
- XhtmlBasicListAdapter.cs
- HTMLTextWriter.cs
- DBAsyncResult.cs
- TypeSystem.cs
- TextTreeFixupNode.cs
- BitStack.cs
- Triangle.cs
- COAUTHINFO.cs
- EncryptedReference.cs
- Icon.cs
- CodeVariableReferenceExpression.cs
- CompositeDataBoundControl.cs
- ActiveXContainer.cs
- SqlUdtInfo.cs
- TargetControlTypeCache.cs
- TextElementEnumerator.cs
- FunctionNode.cs
- SemanticResultValue.cs
- AutoResetEvent.cs
- DBCommand.cs
- EnterpriseServicesHelper.cs
- x509store.cs
- EventWaitHandleSecurity.cs
- SqlMetaData.cs
- DesignTimeParseData.cs
- nulltextcontainer.cs
- COM2ColorConverter.cs
- DirectoryInfo.cs
- CodeBinaryOperatorExpression.cs
- EmptyControlCollection.cs
- EndOfStreamException.cs
- StopRoutingHandler.cs
- PerformanceCounterPermissionAttribute.cs
- HostedElements.cs
- EventPrivateKey.cs
- PopOutPanel.cs
- TogglePattern.cs
- Imaging.cs
- GroupItem.cs
- RC2.cs
- QilTargetType.cs
- OleDbInfoMessageEvent.cs
- MinimizableAttributeTypeConverter.cs
- Propagator.JoinPropagator.cs
- EdmTypeAttribute.cs
- TransformerInfoCollection.cs
- UIElement.cs
- PeerHelpers.cs
- ParallelTimeline.cs
- ScrollChrome.cs
- WsdlImporterElement.cs
- TokenBasedSetEnumerator.cs
- LateBoundChannelParameterCollection.cs
- AutomationFocusChangedEventArgs.cs
- XPathDescendantIterator.cs
- path.cs
- ObjectViewFactory.cs
- DataGridLength.cs
- Hash.cs
- Atom10ItemFormatter.cs
- TreeNode.cs
- TextServicesPropertyRanges.cs
- ExceptionCollection.cs
- Pkcs9Attribute.cs
- RolePrincipal.cs
- CreateParams.cs
- IncrementalReadDecoders.cs
- Normalization.cs
- SplitterPanel.cs
- DeferredElementTreeState.cs