Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / Input / Win32MouseDevice.cs / 1 / Win32MouseDevice.cs
using System.Diagnostics;
using System.Collections;
using System.Windows;
using System.Windows.Media;
using System.Windows.Interop;
using System.Windows.Threading;
using System.Security;
using System.Security.Permissions;
using MS.Internal;
using MS.Internal.PresentationCore; // SecurityHelper
using MS.Win32; // *NativeMethods
using System.Runtime.InteropServices;
using System;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Input
{
///
/// The Win32MouseDevice class implements the platform specific
/// MouseDevice features for the Win32 platform
///
internal sealed class Win32MouseDevice : MouseDevice
{
///
///
///
///
///
///
/// Critical - This is code that elevates AND creates the mouse device which
/// happens to hold the callback to filter mouse messages
/// TreatAsSafe: This constructor handles critical data but does not expose it
/// It stores instance but there are demands on the instances.
///
[SecurityCritical,SecurityTreatAsSafe]
internal Win32MouseDevice(InputManager inputManager)
: base(inputManager)
{
}
///
/// Gets the current state of the specified button from the device from the underlying system
///
///
/// The mouse button to get the state of
///
///
/// The state of the specified mouse button
///
///
/// Critical: Makes calls to UnsafeNativeMethods (GetKeyState)
/// TreatAsSafe: Only returns the current state of the specified button
///
[SecurityCritical,SecurityTreatAsSafe]
internal override MouseButtonState GetButtonStateFromSystem(MouseButton mouseButton)
{
MouseButtonState mouseButtonState = MouseButtonState.Released;
// Security Mitigation: do not give out input state if the device is not active.
if(IsActive)
{
int virtualKeyCode = 0;
switch( mouseButton )
{
case MouseButton.Left:
virtualKeyCode = NativeMethods.VK_LBUTTON;
break;
case MouseButton.Right:
virtualKeyCode = NativeMethods.VK_RBUTTON;
break;
case MouseButton.Middle:
virtualKeyCode = NativeMethods.VK_MBUTTON;
break;
case MouseButton.XButton1:
virtualKeyCode = NativeMethods.VK_XBUTTON1;
break;
case MouseButton.XButton2:
virtualKeyCode = NativeMethods.VK_XBUTTON2;
break;
}
mouseButtonState = ( UnsafeNativeMethods.GetKeyState(virtualKeyCode) & 0x8000 ) != 0 ? MouseButtonState.Pressed : MouseButtonState.Released;
}
return mouseButtonState;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System.Diagnostics;
using System.Collections;
using System.Windows;
using System.Windows.Media;
using System.Windows.Interop;
using System.Windows.Threading;
using System.Security;
using System.Security.Permissions;
using MS.Internal;
using MS.Internal.PresentationCore; // SecurityHelper
using MS.Win32; // *NativeMethods
using System.Runtime.InteropServices;
using System;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
namespace System.Windows.Input
{
///
/// The Win32MouseDevice class implements the platform specific
/// MouseDevice features for the Win32 platform
///
internal sealed class Win32MouseDevice : MouseDevice
{
///
///
///
///
///
///
/// Critical - This is code that elevates AND creates the mouse device which
/// happens to hold the callback to filter mouse messages
/// TreatAsSafe: This constructor handles critical data but does not expose it
/// It stores instance but there are demands on the instances.
///
[SecurityCritical,SecurityTreatAsSafe]
internal Win32MouseDevice(InputManager inputManager)
: base(inputManager)
{
}
///
/// Gets the current state of the specified button from the device from the underlying system
///
///
/// The mouse button to get the state of
///
///
/// The state of the specified mouse button
///
///
/// Critical: Makes calls to UnsafeNativeMethods (GetKeyState)
/// TreatAsSafe: Only returns the current state of the specified button
///
[SecurityCritical,SecurityTreatAsSafe]
internal override MouseButtonState GetButtonStateFromSystem(MouseButton mouseButton)
{
MouseButtonState mouseButtonState = MouseButtonState.Released;
// Security Mitigation: do not give out input state if the device is not active.
if(IsActive)
{
int virtualKeyCode = 0;
switch( mouseButton )
{
case MouseButton.Left:
virtualKeyCode = NativeMethods.VK_LBUTTON;
break;
case MouseButton.Right:
virtualKeyCode = NativeMethods.VK_RBUTTON;
break;
case MouseButton.Middle:
virtualKeyCode = NativeMethods.VK_MBUTTON;
break;
case MouseButton.XButton1:
virtualKeyCode = NativeMethods.VK_XBUTTON1;
break;
case MouseButton.XButton2:
virtualKeyCode = NativeMethods.VK_XBUTTON2;
break;
}
mouseButtonState = ( UnsafeNativeMethods.GetKeyState(virtualKeyCode) & 0x8000 ) != 0 ? MouseButtonState.Pressed : MouseButtonState.Released;
}
return mouseButtonState;
}
}
}
// 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
- SafeArrayRankMismatchException.cs
- Viewport3DVisual.cs
- KnownTypes.cs
- DataSourceCacheDurationConverter.cs
- Base64Decoder.cs
- EndpointDispatcherTable.cs
- DependentList.cs
- ActiveDocumentEvent.cs
- ListControlDesigner.cs
- ResolveResponse.cs
- AttributeCollection.cs
- Set.cs
- XpsS0ValidatingLoader.cs
- XPathNodeHelper.cs
- MessageSecurityOverMsmqElement.cs
- RemoteWebConfigurationHost.cs
- GroupJoinQueryOperator.cs
- EndPoint.cs
- WriteFileContext.cs
- ApplicationHost.cs
- MouseEventArgs.cs
- SqlVersion.cs
- AutomationPatternInfo.cs
- HasCopySemanticsAttribute.cs
- Freezable.cs
- StrokeRenderer.cs
- InplaceBitmapMetadataWriter.cs
- AppearanceEditorPart.cs
- PageContentCollection.cs
- SetMemberBinder.cs
- LinqDataSourceSelectEventArgs.cs
- FontDialog.cs
- SizeAnimationClockResource.cs
- DecoderBestFitFallback.cs
- X509Certificate2.cs
- SchemaSetCompiler.cs
- ChannelServices.cs
- DefaultParameterValueAttribute.cs
- AuthenticationSection.cs
- ToolStripMenuItem.cs
- FontSourceCollection.cs
- Emitter.cs
- EncoderExceptionFallback.cs
- ListItemConverter.cs
- EditorZoneBase.cs
- PropertyDescriptorGridEntry.cs
- WindowsRichEdit.cs
- NetworkInformationPermission.cs
- IDataContractSurrogate.cs
- ConfigXmlCDataSection.cs
- DataServiceProviderWrapper.cs
- StringSource.cs
- ValidationSummary.cs
- AddInAdapter.cs
- XpsViewerException.cs
- SymLanguageVendor.cs
- SymmetricSecurityBindingElement.cs
- SplitContainer.cs
- XamlWriter.cs
- InfiniteTimeSpanConverter.cs
- DataErrorValidationRule.cs
- Serializer.cs
- RequestContext.cs
- MemoryRecordBuffer.cs
- SvcMapFile.cs
- CommentEmitter.cs
- OpacityConverter.cs
- QilValidationVisitor.cs
- JournalEntryListConverter.cs
- SizeValueSerializer.cs
- AssemblyAssociatedContentFileAttribute.cs
- ServiceOperationWrapper.cs
- FlagsAttribute.cs
- HttpRuntime.cs
- CodeAccessPermission.cs
- PopOutPanel.cs
- RC2.cs
- WebControlsSection.cs
- PartialCachingControl.cs
- AccessibleObject.cs
- OrderByExpression.cs
- DispatchChannelSink.cs
- CrossSiteScriptingValidation.cs
- HtmlString.cs
- UICuesEvent.cs
- RequestContextBase.cs
- SessionEndingCancelEventArgs.cs
- OleDbSchemaGuid.cs
- SpellerError.cs
- CrossContextChannel.cs
- PersonalizationStateInfo.cs
- HttpsHostedTransportConfiguration.cs
- ProfileParameter.cs
- Brushes.cs
- InvalidPropValue.cs
- sqlcontext.cs
- securitymgrsite.cs
- ConditionalAttribute.cs
- BaseDataBoundControl.cs
- DataGridViewRowCancelEventArgs.cs