enabling stylecop on ColorPicker (#5336)

* Getting all warnings fixed

* fixed feedback, missed resize for some reason as well.

Co-authored-by: Clint Rutkas <crutkas@microsoft.com>
This commit is contained in:
Clint Rutkas
2020-07-31 09:13:05 -07:00
committed by GitHub
parent 8fb095e2f4
commit ab86fc9a5e
36 changed files with 309 additions and 124 deletions

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using ColorPicker.Helpers; using ColorPicker.Helpers;
@@ -62,7 +66,9 @@ namespace ColorPickerUI
protected override void OnExit(ExitEventArgs e) protected override void OnExit(ExitEventArgs e)
{ {
if (_instanceMutex != null) if (_instanceMutex != null)
{
_instanceMutex.ReleaseMutex(); _instanceMutex.ReleaseMutex();
}
CursorManager.RestoreOriginalCursors(); CursorManager.RestoreOriginalCursors();
base.OnExit(e); base.OnExit(e);

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows; using System.Windows;
using System.Windows.Interactivity; using System.Windows.Interactivity;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;

View File

@@ -1,4 +1,8 @@
using System.Windows; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Windows;
using System.Windows.Interactivity; using System.Windows.Interactivity;
using ColorPicker.Helpers; using ColorPicker.Helpers;
using ColorPicker.Mouse; using ColorPicker.Mouse;
@@ -59,9 +63,9 @@ namespace ColorPicker.Behaviors
windowLeft -= MonitorRightSideDeadZone - ((int)monitorBounds.Right - windowLeft); windowLeft -= MonitorRightSideDeadZone - ((int)monitorBounds.Right - windowLeft);
} }
if ((windowTop + MonitorBottomSideDeadZone / dpi.DpiScaleX) > monitorBounds.Bottom / dpi.DpiScaleX) if ((windowTop + (MonitorBottomSideDeadZone / dpi.DpiScaleX)) > monitorBounds.Bottom / dpi.DpiScaleX)
{ {
windowTop -= MonitorBottomSideDeadZone / dpi.DpiScaleX - (((int)monitorBounds.Bottom / dpi.DpiScaleX - windowTop)); windowTop -= (MonitorBottomSideDeadZone / dpi.DpiScaleX) - (((int)monitorBounds.Bottom / dpi.DpiScaleX) - windowTop);
} }
AssociatedObject.Left = windowLeft; AssociatedObject.Left = windowLeft;

View File

@@ -1,6 +1,10 @@
using ColorPicker.Helpers; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Windows; using System.Windows;
using System.Windows.Interactivity; using System.Windows.Interactivity;
using ColorPicker.Helpers;
namespace ColorPicker.Behaviors namespace ColorPicker.Behaviors
{ {

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows; using System.Windows;
using System.Windows.Interactivity; using System.Windows.Interactivity;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
@@ -7,10 +11,10 @@ namespace ColorPicker.Behaviors
{ {
public class MoveWindowBehavior : Behavior<Window> public class MoveWindowBehavior : Behavior<Window>
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")]
public static DependencyProperty LeftProperty = DependencyProperty.Register("Left", typeof(double), typeof(MoveWindowBehavior), new PropertyMetadata(new PropertyChangedCallback(LeftPropertyChanged))); public static DependencyProperty LeftProperty = DependencyProperty.Register("Left", typeof(double), typeof(MoveWindowBehavior), new PropertyMetadata(new PropertyChangedCallback(LeftPropertyChanged)));
private static void LeftPropertyChanged(DependencyObject d, private static void LeftPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
DependencyPropertyChangedEventArgs e)
{ {
var sender = ((MoveWindowBehavior)d).AssociatedObject; var sender = ((MoveWindowBehavior)d).AssociatedObject;
var move = new DoubleAnimation(sender.Left, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); var move = new DoubleAnimation(sender.Left, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop);
@@ -18,10 +22,10 @@ namespace ColorPicker.Behaviors
sender.BeginAnimation(Window.LeftProperty, move, HandoffBehavior.SnapshotAndReplace); sender.BeginAnimation(Window.LeftProperty, move, HandoffBehavior.SnapshotAndReplace);
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")]
public static DependencyProperty TopProperty = DependencyProperty.Register("Top", typeof(double), typeof(MoveWindowBehavior), new PropertyMetadata(new PropertyChangedCallback(TopPropertyChanged))); public static DependencyProperty TopProperty = DependencyProperty.Register("Top", typeof(double), typeof(MoveWindowBehavior), new PropertyMetadata(new PropertyChangedCallback(TopPropertyChanged)));
private static void TopPropertyChanged(DependencyObject d, private static void TopPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
DependencyPropertyChangedEventArgs e)
{ {
var sender = ((MoveWindowBehavior)d).AssociatedObject; var sender = ((MoveWindowBehavior)d).AssociatedObject;
var move = new DoubleAnimation(sender.Top, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); var move = new DoubleAnimation(sender.Top, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop);
@@ -35,6 +39,7 @@ namespace ColorPicker.Behaviors
{ {
return (double)GetValue(LeftProperty); return (double)GetValue(LeftProperty);
} }
set set
{ {
SetValue(LeftProperty, value); SetValue(LeftProperty, value);
@@ -47,6 +52,7 @@ namespace ColorPicker.Behaviors
{ {
return (double)GetValue(TopProperty); return (double)GetValue(TopProperty);
} }
set set
{ {
SetValue(TopProperty, value); SetValue(TopProperty, value);

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows; using System.Windows;
using System.Windows.Interactivity; using System.Windows.Interactivity;
using System.Windows.Media.Animation; using System.Windows.Media.Animation;
@@ -7,29 +11,36 @@ namespace ColorPicker.Behaviors
{ {
public class ResizeBehavior : Behavior<FrameworkElement> public class ResizeBehavior : Behavior<FrameworkElement>
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")]
public static DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(ResizeBehavior), new PropertyMetadata(new PropertyChangedCallback(WidthPropertyChanged))); public static DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(ResizeBehavior), new PropertyMetadata(new PropertyChangedCallback(WidthPropertyChanged)));
private static void WidthPropertyChanged(DependencyObject d, private static void WidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
DependencyPropertyChangedEventArgs e)
{ {
var sender = ((ResizeBehavior)d).AssociatedObject; var sender = ((ResizeBehavior)d).AssociatedObject;
var move = new DoubleAnimation(sender.Width, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); var move = new DoubleAnimation(sender.Width, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop);
move.Completed += (s, e1) => move.Completed += (s, e1) =>
{ {
sender.BeginAnimation(FrameworkElement.WidthProperty, null); sender.Width = (double)e.NewValue; sender.BeginAnimation(FrameworkElement.WidthProperty, null);
sender.Width = (double)e.NewValue;
}; };
move.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut }; move.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut };
sender.BeginAnimation(FrameworkElement.WidthProperty, move, HandoffBehavior.SnapshotAndReplace); sender.BeginAnimation(FrameworkElement.WidthProperty, move, HandoffBehavior.SnapshotAndReplace);
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-security#:~:text=Dependency%20properties%20should%20generally%20be%20considered%20to%20be,make%20security%20guarantees%20about%20a%20dependency%20property%20value.")]
public static DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(ResizeBehavior), new PropertyMetadata(new PropertyChangedCallback(HeightPropertyChanged))); public static DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(ResizeBehavior), new PropertyMetadata(new PropertyChangedCallback(HeightPropertyChanged)));
private static void HeightPropertyChanged(DependencyObject d, private static void HeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
DependencyPropertyChangedEventArgs e)
{ {
var sender = ((ResizeBehavior)d).AssociatedObject; var sender = ((ResizeBehavior)d).AssociatedObject;
var move = new DoubleAnimation(sender.Height, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop); var move = new DoubleAnimation(sender.Height, (double)e.NewValue, new Duration(TimeSpan.FromMilliseconds(150)), FillBehavior.Stop);
move.Completed += (s, e1) => { sender.BeginAnimation(FrameworkElement.HeightProperty, null); sender.Height = (double)e.NewValue; }; move.Completed += (s, e1) =>
{
sender.BeginAnimation(FrameworkElement.HeightProperty, null);
sender.Height = (double)e.NewValue;
};
move.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut }; move.EasingFunction = new QuadraticEase() { EasingMode = EasingMode.EaseOut };
sender.BeginAnimation(FrameworkElement.HeightProperty, move, HandoffBehavior.SnapshotAndReplace); sender.BeginAnimation(FrameworkElement.HeightProperty, move, HandoffBehavior.SnapshotAndReplace);
} }
@@ -40,6 +51,7 @@ namespace ColorPicker.Behaviors
{ {
return (double)GetValue(WidthProperty); return (double)GetValue(WidthProperty);
} }
set set
{ {
SetValue(WidthProperty, value); SetValue(WidthProperty, value);
@@ -52,6 +64,7 @@ namespace ColorPicker.Behaviors
{ {
return (double)GetValue(HeightProperty); return (double)GetValue(HeightProperty);
} }
set set
{ {
SetValue(HeightProperty, value); SetValue(HeightProperty, value);

View File

@@ -1,4 +1,8 @@
using System.ComponentModel.Composition; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition.Hosting;
namespace ColorPicker namespace ColorPicker

View File

@@ -230,5 +230,20 @@
<Name>Microsoft.PowerToys.Settings.UI.Lib</Name> <Name>Microsoft.PowerToys.Settings.UI.Lib</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -1,5 +1,10 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows.Input; using System.Windows.Input;
namespace ColorPicker.Common namespace ColorPicker.Common
{ {
public class RelayCommand : ICommand public class RelayCommand : ICommand
@@ -13,7 +18,8 @@ namespace ColorPicker.Common
_execute = x => { execute.Invoke(); }; _execute = x => { execute.Invoke(); };
} }
public RelayCommand(Action<object> execute) : this(x => true, execute) public RelayCommand(Action<object> execute)
: this(x => true, execute)
{ {
} }

View File

@@ -1,4 +1,8 @@
using System.ComponentModel; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace ColorPicker.Common namespace ColorPicker.Common

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Windows; using System.Windows;

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@@ -7,7 +11,7 @@ namespace ColorPicker.Helpers
{ {
public static class Logger public static class Logger
{ {
private static string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ColorPicker"); private static readonly string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ColorPicker");
static Logger() static Logger()
{ {
@@ -30,7 +34,8 @@ namespace ColorPicker.Helpers
public static void LogError(string message, Exception ex) public static void LogError(string message, Exception ex)
{ {
Log(message + Environment.NewLine + Log(
message + Environment.NewLine +
ex?.Message + Environment.NewLine + ex?.Message + Environment.NewLine +
"Inner exception: " + Environment.NewLine + "Inner exception: " + Environment.NewLine +
ex?.InnerException?.Message + Environment.NewLine + ex?.InnerException?.Message + Environment.NewLine +

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@@ -1,6 +1,7 @@
using ColorPicker.Telemetry; // Copyright (c) Microsoft Corporation
using ColorPicker.ViewModelContracts; // The Microsoft Corporation licenses this file to you under the MIT license.
using Microsoft.PowerToys.Telemetry; // See the LICENSE file in the project root for more information.
using System; using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Drawing; using System.Drawing;
@@ -8,6 +9,9 @@ using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using ColorPicker.Telemetry;
using ColorPicker.ViewModelContracts;
using Microsoft.PowerToys.Telemetry;
namespace ColorPicker.Helpers namespace ColorPicker.Helpers
{ {
@@ -19,11 +23,12 @@ namespace ColorPicker.Helpers
private const int MaxZoomLevel = 3; private const int MaxZoomLevel = 3;
private const int MinZoomLevel = 0; private const int MinZoomLevel = 0;
private readonly IZoomViewModel _zoomViewModel;
private readonly AppStateHandler _appStateHandler;
private int _currentZoomLevel = 0; private int _currentZoomLevel = 0;
private int _previousZoomLevel = 0; private int _previousZoomLevel = 0;
private readonly IZoomViewModel _zoomViewModel;
private readonly AppStateHandler _appStateHandler;
private ZoomWindow _zoomWindow; private ZoomWindow _zoomWindow;
private double _lastLeft; private double _lastLeft;
@@ -79,8 +84,8 @@ namespace ColorPicker.Helpers
// we just started zooming, copy screen area // we just started zooming, copy screen area
if (_previousZoomLevel == 0) if (_previousZoomLevel == 0)
{ {
var x = (int)point.X - BaseZoomImageSize / 2; var x = (int)point.X - (BaseZoomImageSize / 2);
var y = (int)point.Y - BaseZoomImageSize / 2; var y = (int)point.Y - (BaseZoomImageSize / 2);
var rect = new Rectangle(x, y, BaseZoomImageSize, BaseZoomImageSize); var rect = new Rectangle(x, y, BaseZoomImageSize, BaseZoomImageSize);
var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb); var bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
var g = Graphics.FromImage(bmp); var g = Graphics.FromImage(bmp);
@@ -143,8 +148,8 @@ namespace ColorPicker.Helpers
_previousScaledY = y / dpi.DpiScaleY; _previousScaledY = y / dpi.DpiScaleY;
} }
_lastLeft = Math.Floor(_previousScaledX - ((BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1)) / 2)); _lastLeft = Math.Floor(_previousScaledX - (BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1) / 2));
_lastTop = Math.Floor(_previousScaledY - ((BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1)) / 2)); _lastTop = Math.Floor(_previousScaledY - (BaseZoomImageSize * Math.Pow(ZoomFactor, _currentZoomLevel - 1) / 2));
var justShown = false; var justShown = false;
if (!_zoomWindow.IsVisible) if (!_zoomWindow.IsVisible)
@@ -155,11 +160,12 @@ namespace ColorPicker.Helpers
_zoomViewModel.Width = BaseZoomImageSize; _zoomViewModel.Width = BaseZoomImageSize;
_zoomWindow.Show(); _zoomWindow.Show();
justShown = true; justShown = true;
// make sure color picker window is on top of just opened zoom window // make sure color picker window is on top of just opened zoom window
AppStateHandler.SetTopMost(); AppStateHandler.SetTopMost();
} }
// dirty hack - sometimes when we just show a window on a second monitor with different DPI, // dirty hack - sometimes when we just show a window on a second monitor with different DPI,
// window position is not set correctly on a first time, we need to "ping" it again to make it appear on the proper location // window position is not set correctly on a first time, we need to "ping" it again to make it appear on the proper location
if (justShown) if (justShown)
{ {

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -47,6 +51,7 @@ namespace ColorPicker.Keyboard
int errorCode = Marshal.GetLastWin32Error(); int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode, $"Failed to remove keyboard hooks for '{Process.GetCurrentProcess().ProcessName}'. Error {errorCode}: {new Win32Exception(Marshal.GetLastWin32Error()).Message}."); throw new Win32Exception(errorCode, $"Failed to remove keyboard hooks for '{Process.GetCurrentProcess().ProcessName}'. Error {errorCode}: {new Win32Exception(Marshal.GetLastWin32Error()).Message}.");
} }
_windowsHookHandle = IntPtr.Zero; _windowsHookHandle = IntPtr.Zero;
// ReSharper disable once DelegateSubtraction // ReSharper disable once DelegateSubtraction
@@ -56,11 +61,13 @@ namespace ColorPicker.Keyboard
if (_user32LibraryHandle != IntPtr.Zero) if (_user32LibraryHandle != IntPtr.Zero)
{ {
if (!FreeLibrary(_user32LibraryHandle)) // reduces reference to library by 1. // reduces reference to library by 1.
if (!FreeLibrary(_user32LibraryHandle))
{ {
int errorCode = Marshal.GetLastWin32Error(); int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode, $"Failed to unload library 'User32.dll'. Error {errorCode}: {new Win32Exception(Marshal.GetLastWin32Error()).Message}."); throw new Win32Exception(errorCode, $"Failed to unload library 'User32.dll'. Error {errorCode}: {new Win32Exception(Marshal.GetLastWin32Error()).Message}.");
} }
_user32LibraryHandle = IntPtr.Zero; _user32LibraryHandle = IntPtr.Zero;
} }
} }
@@ -81,7 +88,7 @@ namespace ColorPicker.Keyboard
KeyDown = 0x0100, KeyDown = 0x0100,
KeyUp = 0x0101, KeyUp = 0x0101,
SysKeyDown = 0x0104, SysKeyDown = 0x0104,
SysKeyUp = 0x0105 SysKeyUp = 0x0105,
} }
private IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam) private IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)

View File

@@ -1,4 +1,8 @@
using System.ComponentModel; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using static ColorPicker.Win32Apis; using static ColorPicker.Win32Apis;
namespace ColorPicker.Keyboard namespace ColorPicker.Keyboard
@@ -6,6 +10,7 @@ namespace ColorPicker.Keyboard
internal class GlobalKeyboardHookEventArgs : HandledEventArgs internal class GlobalKeyboardHookEventArgs : HandledEventArgs
{ {
internal GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; } internal GlobalKeyboardHook.KeyboardState KeyboardState { get; private set; }
internal LowLevelKeyboardInputEvent KeyboardData { get; private set; } internal LowLevelKeyboardInputEvent KeyboardData { get; private set; }
internal GlobalKeyboardHookEventArgs( internal GlobalKeyboardHookEventArgs(

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Windows.Input; using System.Windows.Input;
@@ -59,8 +63,9 @@ namespace ColorPicker.Keyboard
private void Hook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e) private void Hook_KeyboardPressed(object sender, GlobalKeyboardHookEventArgs e)
{ {
var virtualCode = e.KeyboardData.VirtualCode; var virtualCode = e.KeyboardData.VirtualCode;
// ESC pressed // ESC pressed
if(virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape)) if (virtualCode == KeyInterop.VirtualKeyFromKey(Key.Escape))
{ {
_currentlyPressedKeys.Clear(); _currentlyPressedKeys.Clear();
_appStateHandler.HideColorPicker(); _appStateHandler.HideColorPicker();
@@ -113,6 +118,7 @@ namespace ColorPicker.Keyboard
return false; return false;
} }
} }
return true; return true;
} }
} }

View File

@@ -1,6 +1,10 @@
using ColorPicker.ViewModelContracts; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Windows; using System.Windows;
using ColorPicker.ViewModelContracts;
namespace ColorPicker namespace ColorPicker
{ {
@@ -18,7 +22,6 @@ namespace ColorPicker
Hide(); Hide();
} }
[Import] [Import]
public IMainViewModel MainViewModel { get; set; } public IMainViewModel MainViewModel { get; set; }

View File

@@ -1,7 +1,11 @@
using ColorPicker.Helpers; // Copyright (c) Microsoft Corporation
using Microsoft.Win32; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.IO; using System.IO;
using ColorPicker.Helpers;
using Microsoft.Win32;
namespace ColorPicker.Mouse namespace ColorPicker.Mouse
{ {
@@ -19,6 +23,11 @@ namespace ColorPicker.Mouse
private static string _originalCrosshairCursorPath; private static string _originalCrosshairCursorPath;
private static string _originalHandCursorPath; private static string _originalHandCursorPath;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")]
private const int SPI_SETCURSORS = 0x0057;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")]
private const int SPIF_SENDCHANGE = 0x02;
public static void SetColorPickerCursor() public static void SetColorPickerCursor()
{ {
BackupOriginalCursors(); BackupOriginalCursors();
@@ -60,21 +69,21 @@ namespace ColorPicker.Mouse
{ {
_originalArrowCursorPath = (string)Registry.GetValue(CursorsRegistryPath, ArrowRegistryName, string.Empty); _originalArrowCursorPath = (string)Registry.GetValue(CursorsRegistryPath, ArrowRegistryName, string.Empty);
} }
if (string.IsNullOrEmpty(_originalIBeamCursorPath)) if (string.IsNullOrEmpty(_originalIBeamCursorPath))
{ {
_originalIBeamCursorPath = (string)Registry.GetValue(CursorsRegistryPath, IBeamRegistryName, string.Empty); _originalIBeamCursorPath = (string)Registry.GetValue(CursorsRegistryPath, IBeamRegistryName, string.Empty);
} }
if (string.IsNullOrEmpty(_originalCrosshairCursorPath)) if (string.IsNullOrEmpty(_originalCrosshairCursorPath))
{ {
_originalCrosshairCursorPath = (string)Registry.GetValue(CursorsRegistryPath, CrosshairRegistryName, string.Empty); _originalCrosshairCursorPath = (string)Registry.GetValue(CursorsRegistryPath, CrosshairRegistryName, string.Empty);
} }
if (string.IsNullOrEmpty(_originalHandCursorPath)) if (string.IsNullOrEmpty(_originalHandCursorPath))
{ {
_originalHandCursorPath = (string)Registry.GetValue(CursorsRegistryPath, HandRegistryName, string.Empty); _originalHandCursorPath = (string)Registry.GetValue(CursorsRegistryPath, HandRegistryName, string.Empty);
} }
} }
const int SPI_SETCURSORS = 0x0057;
const int SPIF_SENDCHANGE = 0x02;
} }
} }

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing; using System.Drawing;
namespace ColorPicker.Mouse namespace ColorPicker.Mouse

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -11,15 +15,20 @@ namespace ColorPicker.Mouse
internal class MouseHook internal class MouseHook
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")]
private const int WH_MOUSE_LL = 14; private const int WH_MOUSE_LL = 14;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")]
private const int WM_LBUTTONDOWN = 0x0201; private const int WM_LBUTTONDOWN = 0x0201;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")]
private const int WM_MOUSEWHEEL = 0x020A; private const int WM_MOUSEWHEEL = 0x020A;
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop object")]
private const int WHEEL_DELTA = 120; private const int WHEEL_DELTA = 120;
private IntPtr _mouseHookHandle; private IntPtr _mouseHookHandle;
private HookProc _mouseDelegate; private HookProc _mouseDelegate;
private event MouseUpEventHandler MouseDown; private event MouseUpEventHandler MouseDown;
public event MouseUpEventHandler OnMouseDown public event MouseUpEventHandler OnMouseDown
{ {
add add
@@ -27,6 +36,7 @@ namespace ColorPicker.Mouse
Subscribe(); Subscribe();
MouseDown += value; MouseDown += value;
} }
remove remove
{ {
MouseDown -= value; MouseDown -= value;
@@ -35,6 +45,7 @@ namespace ColorPicker.Mouse
} }
private event MouseWheelEventHandler MouseWheel; private event MouseWheelEventHandler MouseWheel;
public event MouseWheelEventHandler OnMouseWheel public event MouseWheelEventHandler OnMouseWheel
{ {
add add
@@ -42,6 +53,7 @@ namespace ColorPicker.Mouse
Subscribe(); Subscribe();
MouseWheel += value; MouseWheel += value;
} }
remove remove
{ {
MouseWheel -= value; MouseWheel -= value;
@@ -69,10 +81,12 @@ namespace ColorPicker.Mouse
if (_mouseHookHandle == IntPtr.Zero) if (_mouseHookHandle == IntPtr.Zero)
{ {
_mouseDelegate = MouseHookProc; _mouseDelegate = MouseHookProc;
_mouseHookHandle = SetWindowsHookEx(WH_MOUSE_LL, _mouseHookHandle = SetWindowsHookEx(
WH_MOUSE_LL,
_mouseDelegate, _mouseDelegate,
GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName),
0); 0);
if (_mouseHookHandle == IntPtr.Zero) if (_mouseHookHandle == IntPtr.Zero)
{ {
int errorCode = Marshal.GetLastWin32Error(); int errorCode = Marshal.GetLastWin32Error();
@@ -92,8 +106,10 @@ namespace ColorPicker.Mouse
{ {
MouseDown.Invoke(null, new System.Drawing.Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y)); MouseDown.Invoke(null, new System.Drawing.Point(mouseHookStruct.pt.x, mouseHookStruct.pt.y));
} }
return new IntPtr(-1); return new IntPtr(-1);
} }
if (wParam.ToInt32() == WM_MOUSEWHEEL) if (wParam.ToInt32() == WM_MOUSEWHEEL)
{ {
if (MouseWheel != null) if (MouseWheel != null)
@@ -103,6 +119,7 @@ namespace ColorPicker.Mouse
} }
} }
} }
return CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam); return CallNextHookEx(_mouseHookHandle, nCode, wParam, lParam);
} }
} }

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;

View File

@@ -1,4 +1,8 @@
using Microsoft.PowerToys.Settings.UI.Lib; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.PowerToys.Settings.UI.Lib;
namespace ColorPicker.Settings namespace ColorPicker.Settings
{ {

View File

@@ -1,8 +1,12 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel; using System.ComponentModel;
namespace ColorPicker.Settings namespace ColorPicker.Settings
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "It does, it is a generic. False positive")]
public sealed class SettingItem<T> : INotifyPropertyChanged public sealed class SettingItem<T> : INotifyPropertyChanged
{ {
private T _value; private T _value;
@@ -18,6 +22,7 @@ namespace ColorPicker.Settings
{ {
return _value; return _value;
} }
set set
{ {
_value = value; _value = value;

View File

@@ -1,11 +1,14 @@
using System.IO; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.IO;
using System.Threading;
using ColorPicker.Helpers;
using Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Settings.UI.Lib.Utilities; using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
using ColorPicker.Helpers;
using System.Threading.Tasks;
using System.Threading;
using System;
namespace ColorPicker.Settings namespace ColorPicker.Settings
{ {
@@ -57,6 +60,7 @@ namespace ColorPicker.Settings
var defaultColorPickerSettings = new ColorPickerSettings(); var defaultColorPickerSettings = new ColorPickerSettings();
defaultColorPickerSettings.Save(); defaultColorPickerSettings.Save();
} }
var settings = SettingsUtils.GetSettings<ColorPickerSettings>(ColorPickerModuleName); var settings = SettingsUtils.GetSettings<ColorPickerSettings>(ColorPickerModuleName);
if (settings != null) if (settings != null)
{ {
@@ -73,6 +77,7 @@ namespace ColorPicker.Settings
{ {
retry = false; retry = false;
} }
Logger.LogError("Failed to read changed settings", ex); Logger.LogError("Failed to read changed settings", ex);
Thread.Sleep(500); Thread.Sleep(500);
} }
@@ -81,7 +86,7 @@ namespace ColorPicker.Settings
Logger.LogError("Failed to read changed settings", ex); Logger.LogError("Failed to read changed settings", ex);
} }
} }
}; }
} }
} }
} }

View File

@@ -1,6 +1,10 @@
using Microsoft.PowerToys.Telemetry; // Copyright (c) Microsoft Corporation
using Microsoft.PowerToys.Telemetry.Events; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.Tracing; using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace ColorPicker.Telemetry namespace ColorPicker.Telemetry
{ {

View File

@@ -1,6 +1,10 @@
using Microsoft.PowerToys.Telemetry; // Copyright (c) Microsoft Corporation
using Microsoft.PowerToys.Telemetry.Events; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.Tracing; using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace ColorPicker.Telemetry namespace ColorPicker.Telemetry
{ {

View File

@@ -1,6 +1,10 @@
using Microsoft.PowerToys.Telemetry; // Copyright (c) Microsoft Corporation
using Microsoft.PowerToys.Telemetry.Events; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.Tracing; using System.Diagnostics.Tracing;
using Microsoft.PowerToys.Telemetry;
using Microsoft.PowerToys.Telemetry.Events;
namespace ColorPicker.Telemetry namespace ColorPicker.Telemetry
{ {

View File

@@ -1,4 +1,8 @@
using System.Windows.Media; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Windows.Media;
namespace ColorPicker.ViewModelContracts namespace ColorPicker.ViewModelContracts
{ {

View File

@@ -1,4 +1,8 @@
using System.Windows.Media.Imaging; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Windows.Media.Imaging;
namespace ColorPicker.ViewModelContracts namespace ColorPicker.ViewModelContracts
{ {

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Globalization; using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@@ -9,8 +13,8 @@ using ColorPicker.Helpers;
using ColorPicker.Keyboard; using ColorPicker.Keyboard;
using ColorPicker.Mouse; using ColorPicker.Mouse;
using ColorPicker.Settings; using ColorPicker.Settings;
using ColorPicker.ViewModelContracts;
using ColorPicker.Telemetry; using ColorPicker.Telemetry;
using ColorPicker.ViewModelContracts;
using Microsoft.PowerToys.Settings.UI.Lib; using Microsoft.PowerToys.Settings.UI.Lib;
using Microsoft.PowerToys.Telemetry; using Microsoft.PowerToys.Telemetry;
@@ -19,12 +23,12 @@ namespace ColorPicker.ViewModels
[Export(typeof(IMainViewModel))] [Export(typeof(IMainViewModel))]
public class MainViewModel : ViewModelBase, IMainViewModel public class MainViewModel : ViewModelBase, IMainViewModel
{ {
private string _hexColor;
private string _rgbColor;
private Brush _colorBrush;
private readonly ZoomWindowHelper _zoomWindowHelper; private readonly ZoomWindowHelper _zoomWindowHelper;
private readonly AppStateHandler _appStateHandler; private readonly AppStateHandler _appStateHandler;
private readonly IUserSettings _userSettings; private readonly IUserSettings _userSettings;
private string _hexColor;
private string _rgbColor;
private Brush _colorBrush;
[ImportingConstructor] [ImportingConstructor]
public MainViewModel( public MainViewModel(
@@ -51,6 +55,7 @@ namespace ColorPicker.ViewModels
{ {
return _hexColor; return _hexColor;
} }
private set private set
{ {
_hexColor = value; _hexColor = value;
@@ -64,6 +69,7 @@ namespace ColorPicker.ViewModels
{ {
return _rgbColor; return _rgbColor;
} }
private set private set
{ {
_rgbColor = value; _rgbColor = value;
@@ -77,6 +83,7 @@ namespace ColorPicker.ViewModels
{ {
return _colorBrush; return _colorBrush;
} }
private set private set
{ {
_colorBrush = value; _colorBrush = value;
@@ -133,6 +140,7 @@ namespace ColorPicker.ViewModels
Logger.LogError("Failed to set text into clipboard", ex); Logger.LogError("Failed to set text into clipboard", ex);
} }
} }
System.Threading.Thread.Sleep(10); System.Threading.Thread.Sleep(10);
} }
} }

View File

@@ -1,7 +1,11 @@
using ColorPicker.Common; // Copyright (c) Microsoft Corporation
using ColorPicker.ViewModelContracts; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel.Composition; using System.ComponentModel.Composition;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using ColorPicker.Common;
using ColorPicker.ViewModelContracts;
namespace ColorPicker.ViewModels namespace ColorPicker.ViewModels
{ {
@@ -26,6 +30,7 @@ namespace ColorPicker.ViewModels
{ {
return _zoomArea; return _zoomArea;
} }
set set
{ {
_zoomArea = value; _zoomArea = value;
@@ -39,6 +44,7 @@ namespace ColorPicker.ViewModels
{ {
return _zoomFactor; return _zoomFactor;
} }
set set
{ {
_zoomFactor = value; _zoomFactor = value;
@@ -52,6 +58,7 @@ namespace ColorPicker.ViewModels
{ {
return _desiredWidth; return _desiredWidth;
} }
set set
{ {
_desiredWidth = value; _desiredWidth = value;
@@ -65,6 +72,7 @@ namespace ColorPicker.ViewModels
{ {
return _desiredHeight; return _desiredHeight;
} }
set set
{ {
_desiredHeight = value; _desiredHeight = value;
@@ -78,6 +86,7 @@ namespace ColorPicker.ViewModels
{ {
return _width; return _width;
} }
set set
{ {
_width = value; _width = value;
@@ -91,6 +100,7 @@ namespace ColorPicker.ViewModels
{ {
return _height; return _height;
} }
set set
{ {
_height = value; _height = value;

View File

@@ -1,17 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ColorPicker.Views namespace ColorPicker.Views
{ {

View File

@@ -1,17 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Linq; // See the LICENSE file in the project root for more information.
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ColorPicker.Views namespace ColorPicker.Views
{ {

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
@@ -6,10 +10,11 @@ namespace ColorPicker
{ {
public static class Win32Apis public static class Win32Apis
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Interop")]
public const int WH_KEYBOARD_LL = 13; public const int WH_KEYBOARD_LL = 13;
public const int VkSnapshot = 0x2c; public const int VkSnapshot = 0x2c;
public const int KfAltdown = 0x2000; public const int KfAltdown = 0x2000;
public const int LlkhfAltdown = (KfAltdown >> 8); public const int LlkhfAltdown = KfAltdown >> 8;
public const int MonitorinfofPrimary = 0x00000001; public const int MonitorinfofPrimary = 0x00000001;
public delegate bool MonitorEnumProc( public delegate bool MonitorEnumProc(
@@ -23,9 +28,7 @@ namespace ColorPicker
[DllImport("kernel32.dll", CharSet = CharSet.Auto)] [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
internal static extern bool FreeLibrary(IntPtr hModule); internal static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
[DllImport("kernel32.dll", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.StdCall)]
internal static extern IntPtr GetModuleHandle(string name); internal static extern IntPtr GetModuleHandle(string name);
[DllImport("user32.dll", CharSet = CharSet.Auto)] [DllImport("user32.dll", CharSet = CharSet.Auto)]
@@ -41,21 +44,19 @@ namespace ColorPicker
[DllImport("user32.dll")] [DllImport("user32.dll")]
internal static extern bool GetCursorPos(out PointInter lpPoint); internal static extern bool GetCursorPos(out PointInter lpPoint);
[DllImport("user32.dll", CharSet = CharSet.Auto, [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
internal static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId); internal static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
internal static extern bool UnhookWindowsHookEx(IntPtr idHook); internal static extern bool UnhookWindowsHookEx(IntPtr idHook);
[DllImport("user32.dll", CharSet = CharSet.Auto, [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
CallingConvention = CallingConvention.StdCall, SetLastError = true)]
internal static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam); internal static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")] [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
internal static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr pvParam, int fWinIni); internal static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr pvParam, int fWinIni);
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct POINT internal struct POINT
{ {
@@ -63,6 +64,7 @@ namespace ColorPicker
public int y; public int y;
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct MSLLHOOKSTRUCT internal struct MSLLHOOKSTRUCT
{ {
@@ -78,10 +80,11 @@ namespace ColorPicker
{ {
public int X; public int X;
public int Y; public int Y;
public static explicit operator System.Windows.Point(PointInter point) => new System.Windows.Point(point.X, point.Y); public static explicit operator System.Windows.Point(PointInter point) => new System.Windows.Point(point.X, point.Y);
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal struct Rect internal struct Rect
{ {
@@ -91,15 +94,17 @@ namespace ColorPicker
public int bottom; public int bottom;
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Interop object")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "false positive, used in MonitorResolutionHelper")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)]
internal class MonitorInfoEx internal class MonitorInfoEx
{ {
internal int cbSize = Marshal.SizeOf(typeof(MonitorInfoEx)); public int cbSize = Marshal.SizeOf(typeof(MonitorInfoEx));
internal Rect rcMonitor = default; public Rect rcMonitor = default;
internal Rect rcWork = default; public Rect rcWork = default;
internal int dwFlags = 0; public int dwFlags = 0;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
internal char[] szDevice = new char[32]; public char[] szDevice = new char[32];
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
@@ -111,7 +116,7 @@ namespace ColorPicker
public int VirtualCode; public int VirtualCode;
/// <summary> /// <summary>
/// A hardware scan code for the key. /// A hardware scan code for the key.
/// </summary> /// </summary>
public int HardwareScanCode; public int HardwareScanCode;
@@ -126,10 +131,9 @@ namespace ColorPicker
public int TimeStamp; public int TimeStamp;
/// <summary> /// <summary>
/// Additional information associated with the message. /// Additional information associated with the message.
/// </summary> /// </summary>
public IntPtr AdditionalInformation; public IntPtr AdditionalInformation;
} }
} }
} }

View File

@@ -1,4 +1,8 @@
using System.ComponentModel; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
using System.Windows; using System.Windows;
namespace ColorPicker namespace ColorPicker
@@ -16,12 +20,14 @@ namespace ColorPicker
InitializeComponent(); InitializeComponent();
DataContext = this; DataContext = this;
} }
public double DesiredLeft public double DesiredLeft
{ {
get get
{ {
return _left; return _left;
} }
set set
{ {
_left = value; _left = value;
@@ -35,6 +41,7 @@ namespace ColorPicker
{ {
return _top; return _top;
} }
set set
{ {
_top = value; _top = value;