diff --git a/src/Greenshot.Base/Controls/GreenshotForm.cs b/src/Greenshot.Base/Controls/GreenshotForm.cs
index 42b2719ce..34327706f 100644
--- a/src/Greenshot.Base/Controls/GreenshotForm.cs
+++ b/src/Greenshot.Base/Controls/GreenshotForm.cs
@@ -102,6 +102,20 @@ namespace Greenshot.Base.Controls
///
protected bool ToFront { get; set; }
+ protected GreenshotForm()
+ {
+ DpiChanged += (sender, dpiChangedEventArgs) => DpiChangedHandler(dpiChangedEventArgs.DeviceDpiOld, dpiChangedEventArgs.DeviceDpiNew);
+ }
+
+ ///
+ /// This is the basic DpiChangedHandler responsible for all the DPI relative changes
+ ///
+ ///
+ ///
+ protected virtual void DpiChangedHandler(int oldDpi, int newDpi)
+ {
+ }
+
#if DEBUG
///
/// Code to initialize the language etc during design time
@@ -530,7 +544,7 @@ namespace Greenshot.Base.Controls
///
/// Fill all GreenshotControls with the values from the configuration
///
- protected void FillFields()
+ private void FillFields()
{
foreach (FieldInfo field in GetCachedFields(GetType()))
{
diff --git a/src/Greenshot.Base/Core/AbstractDestination.cs b/src/Greenshot.Base/Core/AbstractDestination.cs
index dc1b38057..7cf1ee0d2 100644
--- a/src/Greenshot.Base/Core/AbstractDestination.cs
+++ b/src/Greenshot.Base/Core/AbstractDestination.cs
@@ -26,6 +26,7 @@ using System.Threading;
using System.Windows.Forms;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
+using Dapplo.Windows.Dpi;
using Dapplo.Windows.User32;
using Greenshot.Base.IniFile;
using Greenshot.Base.Interfaces;
@@ -34,7 +35,7 @@ using log4net;
namespace Greenshot.Base.Core
{
///
- /// Description of AbstractDestination.
+ /// The AbstractDestination is a default implementation of IDestination
///
public abstract class AbstractDestination : IDestination
{
@@ -178,7 +179,7 @@ namespace Greenshot.Base.Core
ExportInformation exportInformation = new ExportInformation(Designation, Language.GetString("settings_destination_picker"));
var menu = new ContextMenuStrip
{
- ImageScalingSize = CoreConfig.ScaledIconSize,
+ ImageScalingSize = CoreConfig.IconSize,
Tag = null,
TopLevel = true
};
@@ -186,10 +187,10 @@ namespace Greenshot.Base.Core
menu.Opening += (sender, args) =>
{
// find the DPI settings for the screen where this is going to land
- var screenDpi = DpiHelper.GetDpi(menu.Location);
- var scaledIconSize = DpiHelper.ScaleWithDpi(CoreConfig.IconSize, screenDpi);
+ var screenDpi = NativeDpiMethods.GetDpi(menu.Location);
+ var scaledIconSize = DpiCalculator.ScaleWithDpi(CoreConfig.IconSize, screenDpi);
menu.SuspendLayout();
- var fontSize = DpiHelper.ScaleWithDpi(12f, screenDpi);
+ var fontSize = DpiCalculator.ScaleWithDpi(12f, screenDpi);
menu.Font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Regular, GraphicsUnit.Pixel);
menu.ImageScalingSize = scaledIconSize;
menu.ResumeLayout();
@@ -306,7 +307,7 @@ namespace Greenshot.Base.Core
ShowMenuAtCursor(menu);
return exportInformation;
}
-
+
///
/// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar.
///
diff --git a/src/Greenshot.Base/Core/CoreConfiguration.cs b/src/Greenshot.Base/Core/CoreConfiguration.cs
index cb488a862..b20e1d246 100644
--- a/src/Greenshot.Base/Core/CoreConfiguration.cs
+++ b/src/Greenshot.Base/Core/CoreConfiguration.cs
@@ -24,7 +24,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
-using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using Dapplo.Windows.Common.Structs;
@@ -370,13 +369,11 @@ namespace Greenshot.Base.Core
}
}
}
-
- public NativeSize ScaledIconSize => DpiHelper.ScaleWithCurrentDpi(_iconSize);
-
- [IniProperty("WebRequestTimeout", Description = "The connect timeout value for webrequets, these are seconds", DefaultValue = "100")]
+
+ [IniProperty("WebRequestTimeout", Description = "The connect timeout value for web requests, these are seconds", DefaultValue = "100")]
public int WebRequestTimeout { get; set; }
- [IniProperty("WebRequestReadWriteTimeout", Description = "The read/write timeout value for webrequets, these are seconds", DefaultValue = "100")]
+ [IniProperty("WebRequestReadWriteTimeout", Description = "The read/write timeout value for web requests, these are seconds", DefaultValue = "100")]
public int WebRequestReadWriteTimeout { get; set; }
public bool UseLargeIcons => IconSize.Width >= 32 || IconSize.Height >= 32;
diff --git a/src/Greenshot.Base/Core/DpiHelper.cs b/src/Greenshot.Base/Core/DpiHelper.cs
deleted file mode 100644
index af9538d5b..000000000
--- a/src/Greenshot.Base/Core/DpiHelper.cs
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using System.Runtime.InteropServices;
-using Dapplo.Windows.Common.Enums;
-using Dapplo.Windows.Common.Extensions;
-using Dapplo.Windows.Common.Structs;
-using Dapplo.Windows.Gdi32;
-using Dapplo.Windows.Gdi32.Enums;
-using Dapplo.Windows.Gdi32.SafeHandles;
-using Dapplo.Windows.User32;
-using Dapplo.Windows.User32.Enums;
-using Greenshot.Base.Core.Enums;
-
-namespace Greenshot.Base.Core
-{
- ///
- /// This handles DPI changes see
- /// Writing DPI-Aware Desktop and Win32 Applications
- ///
- public static class DpiHelper
- {
- ///
- /// This is the default DPI for the screen
- ///
- public const uint DefaultScreenDpi = 96;
-
- ///
- /// Retrieve the current DPI for the UI element which is related to this DpiHandler
- ///
- public static uint Dpi { get; private set; } = WindowsVersion.IsWindows10OrLater ? GetDpiForSystem() : DefaultScreenDpi;
-
- ///
- /// Calculate a DPI scale factor
- ///
- /// uint
- /// double
- public static float DpiScaleFactor(uint dpi)
- {
- if (dpi == 0)
- {
- dpi = Dpi;
- }
-
- return (float) dpi / DefaultScreenDpi;
- }
-
- ///
- /// Scale the supplied number according to the supplied dpi
- ///
- /// double with e.g. the width 16 for 16x16 images
- /// current dpi, normal is 96.
- /// A function which can modify the scale factor
- /// double with the scaled number
- public static float ScaleWithDpi(float someNumber, uint dpi, Func scaleModifier = null)
- {
- var dpiScaleFactor = DpiScaleFactor(dpi);
- if (scaleModifier != null)
- {
- dpiScaleFactor = scaleModifier(dpiScaleFactor);
- }
-
- return dpiScaleFactor * someNumber;
- }
-
- ///
- /// Scale the supplied Size according to the supplied dpi
- ///
- /// Size to resize
- /// current dpi, normal is 96.
- /// A function which can modify the scale factor
- /// NativeSize scaled
- public static NativeSize ScaleWithDpi(NativeSize size, uint dpi, Func scaleModifier = null)
- {
- var dpiScaleFactor = DpiScaleFactor(dpi);
- if (scaleModifier != null)
- {
- dpiScaleFactor = scaleModifier(dpiScaleFactor);
- }
-
- return new NativeSize((int) (dpiScaleFactor * size.Width), (int) (dpiScaleFactor * size.Height));
- }
-
- ///
- /// Scale the supplied NativeSize to the current dpi
- ///
- /// NativeSize to scale
- /// A function which can modify the scale factor
- /// NativeSize scaled
- public static NativeSize ScaleWithCurrentDpi(NativeSize size, Func scaleModifier = null)
- {
- return ScaleWithDpi(size, Dpi, scaleModifier);
- }
-
- ///
- /// Return the DPI for the screen which the location is located on
- ///
- /// NativePoint
- /// uint
- public static uint GetDpi(NativePoint location)
- {
- if (!WindowsVersion.IsWindows81OrLater)
- {
- return DefaultScreenDpi;
- }
- NativeRect rect = new NativeRect(location.X, location.Y, 1, 1);
- IntPtr hMonitor = User32Api.MonitorFromRect(ref rect, MonitorFrom.DefaultToNearest);
- var result = GetDpiForMonitor(hMonitor, MonitorDpiType.EffectiveDpi, out var dpiX, out var dpiY);
- if (result.Succeeded())
- {
- return dpiX;
- }
-
- return DefaultScreenDpi;
- }
-
-
- ///
- /// Retrieve the DPI value for the supplied window handle
- ///
- /// IntPtr
- /// dpi value
- public static uint GetDpi(IntPtr hWnd)
- {
- if (!User32Api.IsWindow(hWnd))
- {
- return DefaultScreenDpi;
- }
-
- // Use the easiest method, but this only works for Windows 10
- if (WindowsVersion.IsWindows10OrLater)
- {
- return GetDpiForWindow(hWnd);
- }
-
- // Use the second easiest method, but this only works for Windows 8.1 or later
- if (WindowsVersion.IsWindows81OrLater)
- {
- var hMonitor = User32Api.MonitorFromWindow(hWnd, MonitorFrom.DefaultToNearest);
- // ReSharper disable once UnusedVariable
- var result = GetDpiForMonitor(hMonitor, MonitorDpiType.EffectiveDpi, out var dpiX, out var dpiY);
- if (result.Succeeded())
- {
- return dpiX;
- }
- }
-
- // Fallback to the global DPI settings
- using var hdc = SafeWindowDcHandle.FromWindow(hWnd);
- if (hdc == null)
- {
- return DefaultScreenDpi;
- }
-
- return (uint) Gdi32Api.GetDeviceCaps(hdc, DeviceCaps.LOGPIXELSX);
- }
-
- ///
- /// See more at GetDpiForWindow function
- /// Returns the dots per inch (dpi) value for the associated window.
- ///
- /// IntPtr
- /// uint with dpi
- [DllImport("user32.dll")]
- private static extern uint GetDpiForWindow(IntPtr hWnd);
-
- ///
- /// See
- /// GetDpiForMonitor function
- /// Queries the dots per inch (dpi) of a display.
- ///
- /// IntPtr
- /// MonitorDpiType
- /// out int for the horizontal dpi
- /// out int for the vertical dpi
- /// true if all okay
- [DllImport("shcore.dll", SetLastError = true)]
- private static extern HResult GetDpiForMonitor(IntPtr hMonitor, MonitorDpiType dpiType, out uint dpiX, out uint dpiY);
-
- ///
- /// See GetDpiForSystem function
- /// Returns the system DPI.
- ///
- /// uint with the system DPI
- [DllImport("user32.dll")]
- private static extern uint GetDpiForSystem();
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/Core/Enums/MonitorDpiType.cs b/src/Greenshot.Base/Core/Enums/MonitorDpiType.cs
deleted file mode 100644
index e434f5bb3..000000000
--- a/src/Greenshot.Base/Core/Enums/MonitorDpiType.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) Dapplo and contributors. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-
-using System;
-
-namespace Greenshot.Base.Core.Enums
-{
- ///
- /// See
- ///
- /// MONITOR_DPI_TYPE
- /// enumeration
- ///
- ///
- [Flags]
- public enum MonitorDpiType
- {
- ///
- /// The effective DPI.
- /// This value should be used when determining the correct scale factor for scaling UI elements.
- /// This incorporates the scale factor set by the user for this specific display.
- ///
- EffectiveDpi = 0,
-
- ///
- /// The angular DPI.
- /// This DPI ensures rendering at a compliant angular resolution on the screen.
- /// This does not include the scale factor set by the user for this specific display
- ///
- AngularDpi = 1,
-
- ///
- /// The raw DPI.
- /// This value is the linear DPI of the screen as measured on the screen itself.
- /// Use this value when you want to read the pixel density and not the recommended scaling setting.
- /// This does not include the scale factor set by the user for this specific display and is not guaranteed to be a
- /// supported DPI value.
- ///
- RawDpi = 2
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/Core/WindowDetails.cs b/src/Greenshot.Base/Core/WindowDetails.cs
index c86092f60..a9c3a747a 100644
--- a/src/Greenshot.Base/Core/WindowDetails.cs
+++ b/src/Greenshot.Base/Core/WindowDetails.cs
@@ -1020,7 +1020,7 @@ namespace Greenshot.Base.Core
{
var colorizationColor = DwmApi.ColorizationColor;
// Modify by losing the transparency and increasing the intensity (as if the background color is white)
- tempForm.BackColor = Color.FromArgb(255, (colorizationColor.R + 255) >> 1, (colorizationColor.G + 255) >> 1, (colorizationColor.B + 255) >> 1); ;
+ tempForm.BackColor = Color.FromArgb(255, (colorizationColor.R + 255) >> 1, (colorizationColor.G + 255) >> 1, (colorizationColor.B + 255) >> 1);
}
// Make sure everything is visible
@@ -1451,7 +1451,7 @@ namespace Greenshot.Base.Core
if (!HasParent && Maximised)
{
- Log.Debug("Correcting for maximalization");
+ Log.Debug("Correcting for maximized window");
GetBorderSize(out var borderSize);
NativeRect borderRectangle = new NativeRect(borderSize.Width, borderSize.Height, windowRect.Width - (2 * borderSize.Width), windowRect.Height - (2 * borderSize.Height));
ImageHelper.Crop(ref returnImage, ref borderRectangle);
diff --git a/src/Greenshot.Base/Greenshot.Base.csproj b/src/Greenshot.Base/Greenshot.Base.csproj
index 56e2c201e..9d8a64589 100644
--- a/src/Greenshot.Base/Greenshot.Base.csproj
+++ b/src/Greenshot.Base/Greenshot.Base.csproj
@@ -6,11 +6,12 @@
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/Greenshot.Base/Hooking/WindowsEventHook.cs b/src/Greenshot.Base/Hooking/WindowsEventHook.cs
deleted file mode 100644
index 7982cc35a..000000000
--- a/src/Greenshot.Base/Hooking/WindowsEventHook.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using Greenshot.Base.UnmanagedHelpers.Enums;
-
-namespace Greenshot.Base.Hooking
-{
- ///
- /// The WinEventHook can register handlers to become important windows events
- /// This makes it possible to know a.o. when a window is created, moved, updated and closed.
- ///
- public class WindowsEventHook : IDisposable
- {
- private readonly WinEventDelegate _winEventHandler;
- private GCHandle _gcHandle;
-
- ///
- /// Used with Register hook
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public delegate void WinEventHandler(WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
-
- ///
- /// Create a WindowsEventHook object
- ///
- public WindowsEventHook()
- {
- _winEventHandler = WinEventDelegateHandler;
- _gcHandle = GCHandle.Alloc(_winEventHandler);
- }
-
- [DllImport("user32", SetLastError = true)]
- private static extern bool UnhookWinEvent(IntPtr hWinEventHook);
-
- [DllImport("user32", SetLastError = true)]
- private static extern IntPtr SetWinEventHook(WinEvent eventMin, WinEvent eventMax, IntPtr hmodWinEventProc, WinEventDelegate lpfnWinEventProc, int idProcess, int idThread,
- WinEventHookFlags dwFlags);
-
- ///
- /// Used with SetWinEventHook
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- private delegate void WinEventDelegate(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
-
- private readonly IDictionary _winEventHandlers = new Dictionary();
-
- ///
- /// Are hooks active?
- ///
- public bool IsHooked => _winEventHandlers.Count > 0;
-
- ///
- /// Hook a WinEvent
- ///
- ///
- ///
- /// true if success
- public void Hook(WinEvent winEvent, WinEventHandler winEventHandler)
- {
- Hook(winEvent, winEvent, winEventHandler);
- }
-
- ///
- /// Hook a WinEvent
- ///
- ///
- ///
- ///
- public void Hook(WinEvent winEventStart, WinEvent winEventEnd, WinEventHandler winEventHandler)
- {
- var hookPtr = SetWinEventHook(winEventStart, winEventEnd, IntPtr.Zero, _winEventHandler, 0, 0,
- WinEventHookFlags.WINEVENT_SKIPOWNPROCESS | WinEventHookFlags.WINEVENT_OUTOFCONTEXT);
- _winEventHandlers.Add(hookPtr, winEventHandler);
- }
-
- ///
- /// Remove all hooks
- ///
- private void Unhook()
- {
- foreach (var hookPtr in _winEventHandlers.Keys)
- {
- if (hookPtr != IntPtr.Zero)
- {
- UnhookWinEvent(hookPtr);
- }
- }
-
- _winEventHandlers.Clear();
- _gcHandle.Free();
- }
-
- ///
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- ///
- public void Dispose()
- {
- Unhook();
- }
-
- ///
- /// Call the WinEventHandler for this event
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- private void WinEventDelegateHandler(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
- {
- if (_winEventHandlers.TryGetValue(hWinEventHook, out var handler))
- {
- handler(eventType, hWnd, idObject, idChild, dwEventThread, dwmsEventTime);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/Hooking/WindowsOpenCloseMonitor.cs b/src/Greenshot.Base/Hooking/WindowsOpenCloseMonitor.cs
deleted file mode 100644
index b8a4781a3..000000000
--- a/src/Greenshot.Base/Hooking/WindowsOpenCloseMonitor.cs
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using Greenshot.Base.Core;
-using Greenshot.Base.UnmanagedHelpers.Enums;
-
-namespace Greenshot.Base.Hooking
-{
- ///
- /// Event arguments for the WindowOpenCloseEvent
- ///
- public class WindowOpenCloseEventArgs : EventArgs
- {
- public bool IsOpen { get; set; }
-
- ///
- /// HWnd of the window which has a changed title
- ///
- public IntPtr HWnd { get; set; }
-
- ///
- /// Title which is changed
- ///
- public string Title { get; set; }
-
- public string ClassName { get; set; }
- }
-
- ///
- /// Delegate for the window open close event
- ///
- ///
- public delegate void WindowOpenCloseEventDelegate(WindowOpenCloseEventArgs eventArgs);
-
- ///
- /// Monitor all new and destroyed windows
- ///
- public sealed class WindowsOpenCloseMonitor : IDisposable
- {
- private WindowsEventHook _hook;
- private readonly object _lockObject = new object();
-
- // ReSharper disable once InconsistentNaming
- private event WindowOpenCloseEventDelegate _windowOpenCloseEvent;
-
- ///
- /// Add / remove event handler to the title monitor
- ///
- public event WindowOpenCloseEventDelegate WindowOpenCloseChangeEvent
- {
- add
- {
- lock (_lockObject)
- {
- if (_hook == null)
- {
- _hook = new WindowsEventHook();
- _hook.Hook(WinEvent.EVENT_OBJECT_CREATE, WinEvent.EVENT_OBJECT_DESTROY, WinEventHandler);
- }
-
- _windowOpenCloseEvent += value;
- }
- }
- remove
- {
- lock (_lockObject)
- {
- _windowOpenCloseEvent -= value;
- if (_windowOpenCloseEvent == null || _windowOpenCloseEvent.GetInvocationList().Length == 0)
- {
- if (_hook != null)
- {
- _hook.Dispose();
- _hook = null;
- }
- }
- }
- }
- }
-
- ///
- /// WinEventDelegate for the creation and destruction
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- private void WinEventHandler(WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
- {
- if (hWnd == IntPtr.Zero || idObject != EventObjects.OBJID_WINDOW)
- {
- return;
- }
-
- if (eventType == WinEvent.EVENT_OBJECT_CREATE)
- {
- if (_windowOpenCloseEvent != null)
- {
- var windowsDetails = new WindowDetails(hWnd);
- _windowOpenCloseEvent(new WindowOpenCloseEventArgs
- {
- HWnd = hWnd,
- IsOpen = true,
- Title = windowsDetails.Text,
- ClassName = windowsDetails.ClassName
- });
- }
- }
-
- if (eventType == WinEvent.EVENT_OBJECT_DESTROY)
- {
- _windowOpenCloseEvent?.Invoke(new WindowOpenCloseEventArgs
- {
- HWnd = hWnd,
- IsOpen = false
- });
- }
- }
-
- private bool _disposedValue; // To detect redundant calls
-
- ///
- /// Dispose the underlying hook
- ///
- public void Dispose(bool disposing)
- {
- if (_disposedValue)
- {
- return;
- }
-
- lock (_lockObject)
- {
- _hook?.Dispose();
- }
-
- _disposedValue = true;
- }
-
- ///
- /// Make sure the finalizer disposes the underlying hook
- ///
- ~WindowsOpenCloseMonitor()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(false);
- }
-
- ///
- /// Dispose the underlying hook
- ///
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/Hooking/WindowsTitleMonitor.cs b/src/Greenshot.Base/Hooking/WindowsTitleMonitor.cs
deleted file mode 100644
index f93542228..000000000
--- a/src/Greenshot.Base/Hooking/WindowsTitleMonitor.cs
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using Greenshot.Base.Core;
-using Greenshot.Base.UnmanagedHelpers.Enums;
-
-namespace Greenshot.Base.Hooking
-{
- ///
- /// Event arguments for the TitleChangeEvent
- ///
- public class TitleChangeEventArgs : EventArgs
- {
- ///
- /// HWnd of the window which has a changed title
- ///
- public IntPtr HWnd { get; set; }
-
- ///
- /// Title which is changed
- ///
- public string Title { get; set; }
- }
-
- ///
- /// Delegate for the title change event
- ///
- ///
- public delegate void TitleChangeEventDelegate(TitleChangeEventArgs eventArgs);
-
- ///
- /// Monitor all title changes
- ///
- public sealed class WindowsTitleMonitor : IDisposable
- {
- private WindowsEventHook _hook;
- private readonly object _lockObject = new object();
-
- // ReSharper disable once InconsistentNaming
- private event TitleChangeEventDelegate _titleChangeEvent;
-
- ///
- /// Add / remove event handler to the title monitor
- ///
- public event TitleChangeEventDelegate TitleChangeEvent
- {
- add
- {
- lock (_lockObject)
- {
- if (_hook == null)
- {
- _hook = new WindowsEventHook();
- _hook.Hook(WinEvent.EVENT_OBJECT_NAMECHANGE, WinEventHandler);
- }
-
- _titleChangeEvent += value;
- }
- }
- remove
- {
- lock (_lockObject)
- {
- _titleChangeEvent -= value;
- if (_titleChangeEvent == null || _titleChangeEvent.GetInvocationList().Length == 0)
- {
- if (_hook != null)
- {
- _hook.Dispose();
- _hook = null;
- }
- }
- }
- }
- }
-
- ///
- /// WinEventDelegate for the creation & destruction
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- private void WinEventHandler(WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
- {
- if (hWnd == IntPtr.Zero || idObject != EventObjects.OBJID_WINDOW)
- {
- return;
- }
-
- if (eventType == WinEvent.EVENT_OBJECT_NAMECHANGE)
- {
- if (_titleChangeEvent != null)
- {
- string newTitle = new WindowDetails(hWnd).Text;
- _titleChangeEvent(new TitleChangeEventArgs
- {
- HWnd = hWnd,
- Title = newTitle
- });
- }
- }
- }
-
- private bool _disposedValue; // To detect redundant calls
-
- ///
- /// Dispose the underlying hook
- ///
- public void Dispose(bool disposing)
- {
- if (_disposedValue)
- {
- return;
- }
-
- lock (_lockObject)
- {
- _hook?.Dispose();
- }
-
- _disposedValue = true;
- }
-
- ///
- /// Make sure the finalizer disposes the underlying hook
- ///
- ~WindowsTitleMonitor()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(false);
- }
-
- ///
- /// Dispose the underlying hook
- ///
- public void Dispose()
- {
- // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/Interfaces/Drawing/Adorners/IAdorner.cs b/src/Greenshot.Base/Interfaces/Drawing/Adorners/IAdorner.cs
index 4d8de842d..1894eb647 100644
--- a/src/Greenshot.Base/Interfaces/Drawing/Adorners/IAdorner.cs
+++ b/src/Greenshot.Base/Interfaces/Drawing/Adorners/IAdorner.cs
@@ -98,7 +98,7 @@ namespace Greenshot.Base.Interfaces.Drawing.Adorners
/// Adjust UI elements to the supplied DPI settings
///
///
- void AdjustToDpi(uint dpi);
+ void AdjustToDpi(int dpi);
///
/// The color of the lines around the adorner
diff --git a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs
index ce4a9c85c..3fe786508 100644
--- a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs
+++ b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainer.cs
@@ -97,8 +97,8 @@ namespace Greenshot.Base.Interfaces.Drawing
///
/// Adjust UI elements to the supplied DPI settings
///
- /// uint
- void AdjustToDpi(uint dpi);
+ /// int
+ void AdjustToDpi(int dpi);
///
/// Enable a way for elements to add a context menu entry
diff --git a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainerList.cs b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainerList.cs
index 19a4e2a25..795c36afe 100644
--- a/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainerList.cs
+++ b/src/Greenshot.Base/Interfaces/Drawing/IDrawableContainerList.cs
@@ -59,6 +59,6 @@ namespace Greenshot.Base.Interfaces.Drawing
void PushElementsToBottom(IDrawableContainerList elements);
void ShowContextMenu(MouseEventArgs e, ISurface surface);
void HandleFieldChangedEvent(object sender, FieldChangedEventArgs e);
- void AdjustToDpi(uint dpi);
+ void AdjustToDpi(int dpi);
}
}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/EnumWindowsProc.cs b/src/Greenshot.Base/Interfaces/IProvideDeviceDpi.cs
similarity index 76%
rename from src/Greenshot.Base/UnmanagedHelpers/EnumWindowsProc.cs
rename to src/Greenshot.Base/Interfaces/IProvideDeviceDpi.cs
index 9d5b10b92..73db77af6 100644
--- a/src/Greenshot.Base/UnmanagedHelpers/EnumWindowsProc.cs
+++ b/src/Greenshot.Base/Interfaces/IProvideDeviceDpi.cs
@@ -1,4 +1,4 @@
-/*
+/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
*
@@ -19,15 +19,16 @@
* along with this program. If not, see .
*/
-using System;
-
-namespace Greenshot.Base.UnmanagedHelpers
+namespace Greenshot.Base.Interfaces
{
///
- /// Used with EnumWindows or EnumChildWindows
+ /// IProvideDeviceDpi can provide the current DPI for a component
///
- /// IntPtr
- /// int
- /// int
- public delegate int EnumWindowsProc(IntPtr hWnd, int lParam);
+ public interface IProvideDeviceDpi
+ {
+ ///
+ /// A simple getter for the current DPI
+ ///
+ int DeviceDpi { get; }
+ }
}
\ No newline at end of file
diff --git a/src/Greenshot.Base/Interfaces/SurfaceLineThicknessEventArgs.cs b/src/Greenshot.Base/Interfaces/SurfaceLineThicknessEventArgs.cs
index 5fd5694ba..61ac1a848 100644
--- a/src/Greenshot.Base/Interfaces/SurfaceLineThicknessEventArgs.cs
+++ b/src/Greenshot.Base/Interfaces/SurfaceLineThicknessEventArgs.cs
@@ -20,7 +20,6 @@
*/
using System;
-using System.Drawing;
namespace Greenshot.Base.Interfaces
{
diff --git a/src/Greenshot.Base/Interfaces/SurfaceShadowEventArgs.cs b/src/Greenshot.Base/Interfaces/SurfaceShadowEventArgs.cs
index a7bd682b7..5159d4d05 100644
--- a/src/Greenshot.Base/Interfaces/SurfaceShadowEventArgs.cs
+++ b/src/Greenshot.Base/Interfaces/SurfaceShadowEventArgs.cs
@@ -20,7 +20,6 @@
*/
using System;
-using System.Drawing;
namespace Greenshot.Base.Interfaces
{
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Enums/DesktopAccessRight.cs b/src/Greenshot.Base/UnmanagedHelpers/Enums/DesktopAccessRight.cs
deleted file mode 100644
index c99ddb149..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Enums/DesktopAccessRight.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Greenshot.Base.UnmanagedHelpers.Enums
-{
- [Flags]
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- public enum DesktopAccessRight : uint
- {
- DESKTOP_READOBJECTS = 0x00000001,
- DESKTOP_CREATEWINDOW = 0x00000002,
- DESKTOP_CREATEMENU = 0x00000004,
- DESKTOP_HOOKCONTROL = 0x00000008,
- DESKTOP_JOURNALRECORD = 0x00000010,
- DESKTOP_JOURNALPLAYBACK = 0x00000020,
- DESKTOP_ENUMERATE = 0x00000040,
- DESKTOP_WRITEOBJECTS = 0x00000080,
- DESKTOP_SWITCHDESKTOP = 0x00000100,
-
- GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
- DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
- DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP)
- };
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Enums/EventObjects.cs b/src/Greenshot.Base/UnmanagedHelpers/Enums/EventObjects.cs
deleted file mode 100644
index c9bf33cfc..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Enums/EventObjects.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System.Diagnostics.CodeAnalysis;
-
-namespace Greenshot.Base.UnmanagedHelpers.Enums
-{
- ///
- /// See Object Identifiers
- ///
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- public enum EventObjects
- {
- OBJID_WINDOW = 0
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Enums/ProcessAccessFlags.cs b/src/Greenshot.Base/UnmanagedHelpers/Enums/ProcessAccessFlags.cs
deleted file mode 100644
index c8795e33c..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Enums/ProcessAccessFlags.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Greenshot.Base.UnmanagedHelpers.Enums
-{
- [Flags]
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- public enum ProcessAccessFlags : uint
- {
- VMRead = 0x00000010,
- QueryInformation = 0x00000400,
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Enums/WinEvent.cs b/src/Greenshot.Base/UnmanagedHelpers/Enums/WinEvent.cs
deleted file mode 100644
index 73b47c2aa..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Enums/WinEvent.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom, Francis Noel
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System.Diagnostics.CodeAnalysis;
-
-namespace Greenshot.Base.UnmanagedHelpers.Enums
-{
- ///
- /// Used for User32.SetWinEventHook
- /// See MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066%28v=vs.85%29.aspx
- ///
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- public enum WinEvent : uint
- {
- EVENT_OBJECT_CREATE = 32768,
- EVENT_OBJECT_DESTROY = 32769,
- EVENT_OBJECT_NAMECHANGE = 32780,
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Enums/WinEventHookFlags.cs b/src/Greenshot.Base/UnmanagedHelpers/Enums/WinEventHookFlags.cs
deleted file mode 100644
index 809cb5248..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Enums/WinEventHookFlags.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Greenshot.Base.UnmanagedHelpers.Enums
-{
- ///
- /// Used for User32.SetWinEventHook
- /// See: https://msdn.microsoft.com/en-us/library/windows/desktop/dd373640%28v=vs.85%29.aspx
- ///
- [SuppressMessage("ReSharper", "InconsistentNaming"), Flags]
- public enum WinEventHookFlags
- {
- WINEVENT_SKIPOWNTHREAD = 1,
- WINEVENT_SKIPOWNPROCESS = 2,
- WINEVENT_OUTOFCONTEXT = 0,
- WINEVENT_INCONTEXT = 4
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Structs/IconInfo.cs b/src/Greenshot.Base/UnmanagedHelpers/Structs/IconInfo.cs
deleted file mode 100644
index 470862304..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Structs/IconInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace Greenshot.Base.UnmanagedHelpers.Structs
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct IconInfo
- {
- public bool fIcon;
- public int xHotspot;
- public int yHotspot;
- public IntPtr hbmMask;
- public IntPtr hbmColor;
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/Structs/SCROLLINFO.cs b/src/Greenshot.Base/UnmanagedHelpers/Structs/SCROLLINFO.cs
deleted file mode 100644
index cf9eaa937..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/Structs/SCROLLINFO.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: https://getgreenshot.org/
- * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace Greenshot.Base.UnmanagedHelpers.Structs
-{
- [Serializable, StructLayout(LayoutKind.Sequential)]
- public struct SCROLLINFO
- {
- public int cbSize;
- public int fMask;
- public int nMin;
- public int nMax;
- public int nPage;
- public int nPos;
- public int nTrackPos;
- }
-}
\ No newline at end of file
diff --git a/src/Greenshot.Base/UnmanagedHelpers/WinEventDelegate.cs b/src/Greenshot.Base/UnmanagedHelpers/WinEventDelegate.cs
deleted file mode 100644
index bd54923f7..000000000
--- a/src/Greenshot.Base/UnmanagedHelpers/WinEventDelegate.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using Greenshot.Base.UnmanagedHelpers.Enums;
-
-namespace Greenshot.Base.UnmanagedHelpers
-{
- ///
- /// Used with SetWinEventHook
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public delegate void WinEventDelegate(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
-}
\ No newline at end of file
diff --git a/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs
index 692431955..2bf1baa00 100644
--- a/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs
+++ b/src/Greenshot.Editor/Drawing/Adorners/AbstractAdorner.cs
@@ -24,7 +24,7 @@ using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
-using Greenshot.Base.Core;
+using Dapplo.Windows.Dpi;
using Greenshot.Base.Interfaces.Drawing;
using Greenshot.Base.Interfaces.Drawing.Adorners;
@@ -39,7 +39,7 @@ namespace Greenshot.Editor.Drawing.Adorners
public AbstractAdorner(IDrawableContainer owner)
{
- _size = DpiHelper.ScaleWithDpi(DefaultSize, 0);
+ _size = DpiCalculator.ScaleWithDpi(DefaultSize, 0);
Owner = owner;
}
@@ -133,9 +133,9 @@ namespace Greenshot.Editor.Drawing.Adorners
/// Adjust UI elements to the supplied DPI settings
///
/// uint
- public void AdjustToDpi(uint dpi)
+ public void AdjustToDpi(int dpi)
{
- _size = DpiHelper.ScaleWithDpi(DefaultSize, dpi);
+ _size = DpiCalculator.ScaleWithDpi(DefaultSize, dpi);
}
public Color OutlineColor { get; set; } = Color.White;
diff --git a/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs
index 7c20e6722..228ac9746 100644
--- a/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs
+++ b/src/Greenshot.Editor/Drawing/Adorners/MoveAdorner.cs
@@ -20,7 +20,6 @@
*/
using System.Drawing;
-using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Greenshot.Base.Interfaces.Drawing;
using Greenshot.Editor.Helpers;
diff --git a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs
index c99d4440f..772885b21 100644
--- a/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs
+++ b/src/Greenshot.Editor/Drawing/Adorners/ResizeAdorner.cs
@@ -20,7 +20,6 @@
*/
using System.Drawing;
-using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Greenshot.Base.Interfaces.Drawing;
using Greenshot.Editor.Helpers;
diff --git a/src/Greenshot.Editor/Drawing/DrawableContainer.cs b/src/Greenshot.Editor/Drawing/DrawableContainer.cs
index 6d5f0d0a0..92a9664f3 100644
--- a/src/Greenshot.Editor/Drawing/DrawableContainer.cs
+++ b/src/Greenshot.Editor/Drawing/DrawableContainer.cs
@@ -442,7 +442,7 @@ namespace Greenshot.Editor.Drawing
/// Adjust UI elements to the supplied DPI settings
///
/// uint with dpi value
- public void AdjustToDpi(uint dpi)
+ public void AdjustToDpi(int dpi)
{
foreach (var adorner in Adorners)
{
diff --git a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs
index 2a684a688..ef30c037f 100644
--- a/src/Greenshot.Editor/Drawing/DrawableContainerList.cs
+++ b/src/Greenshot.Editor/Drawing/DrawableContainerList.cs
@@ -772,8 +772,8 @@ namespace Greenshot.Editor.Drawing
///
/// Adjust UI elements to the supplied DPI settings
///
- ///
- public void AdjustToDpi(uint dpi)
+ /// int
+ public void AdjustToDpi(int dpi)
{
foreach (var drawableContainer in this)
{
diff --git a/src/Greenshot.Editor/Drawing/MetafileContainer.cs b/src/Greenshot.Editor/Drawing/MetafileContainer.cs
index 4372ce24d..04140bfe8 100644
--- a/src/Greenshot.Editor/Drawing/MetafileContainer.cs
+++ b/src/Greenshot.Editor/Drawing/MetafileContainer.cs
@@ -25,7 +25,6 @@ using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using Greenshot.Base.Core;
using Greenshot.Base.Interfaces;
-using Svg;
namespace Greenshot.Editor.Drawing
{
diff --git a/src/Greenshot.Editor/Drawing/Surface.cs b/src/Greenshot.Editor/Drawing/Surface.cs
index a8cc4c2b0..c16066071 100644
--- a/src/Greenshot.Editor/Drawing/Surface.cs
+++ b/src/Greenshot.Editor/Drawing/Surface.cs
@@ -454,7 +454,7 @@ namespace Greenshot.Editor.Drawing
/// Adjust UI elements to the supplied DPI settings
///
///
- public void AdjustToDpi(uint dpi)
+ public void AdjustToDpi(int dpi)
{
foreach (var element in this._elements)
{
diff --git a/src/Greenshot.Editor/Forms/ColorDialog.cs b/src/Greenshot.Editor/Forms/ColorDialog.cs
index ce8dd4b4c..2a146012a 100644
--- a/src/Greenshot.Editor/Forms/ColorDialog.cs
+++ b/src/Greenshot.Editor/Forms/ColorDialog.cs
@@ -21,7 +21,6 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Threading;
diff --git a/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs b/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs
index 90f62493e..c9c1db167 100644
--- a/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs
+++ b/src/Greenshot.Editor/Forms/ImageEditorForm.Designer.cs
@@ -38,7 +38,6 @@ namespace Greenshot.Editor.Forms {
protected override void Dispose(bool disposing)
{
if (disposing) {
- DpiChanged -= AdjustToDpi;
if (components != null) {
components.Dispose();
}
@@ -322,7 +321,7 @@ namespace Greenshot.Editor.Forms {
// toolsToolStrip
//
this.toolsToolStrip.ClickThrough = true;
- this.toolsToolStrip.ImageScalingSize = coreConfiguration.ScaledIconSize;
+ this.toolsToolStrip.ImageScalingSize = coreConfiguration.IconSize;
this.toolsToolStrip.Dock = System.Windows.Forms.DockStyle.None;
this.toolsToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolsToolStrip.Renderer = new CustomToolStripProfessionalRenderer();
@@ -558,7 +557,7 @@ namespace Greenshot.Editor.Forms {
// menuStrip1
//
this.menuStrip1.ClickThrough = true;
- this.menuStrip1.ImageScalingSize = coreConfiguration.ScaledIconSize;
+ this.menuStrip1.ImageScalingSize = coreConfiguration.IconSize;
this.menuStrip1.Dock = System.Windows.Forms.DockStyle.Fill;
this.menuStrip1.Stretch = true;
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -876,7 +875,7 @@ namespace Greenshot.Editor.Forms {
// destinationsToolStrip
//
this.destinationsToolStrip.ClickThrough = true;
- this.destinationsToolStrip.ImageScalingSize = coreConfiguration.ScaledIconSize;
+ this.destinationsToolStrip.ImageScalingSize = coreConfiguration.IconSize;
this.destinationsToolStrip.Dock = System.Windows.Forms.DockStyle.Fill;
this.destinationsToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.destinationsToolStrip.Name = "toolStrip1";
@@ -1031,10 +1030,10 @@ namespace Greenshot.Editor.Forms {
// propertiesToolStrip
//
this.propertiesToolStrip.ClickThrough = true;
- this.propertiesToolStrip.ImageScalingSize = coreConfiguration.ScaledIconSize;
+ this.propertiesToolStrip.ImageScalingSize = coreConfiguration.IconSize;
this.propertiesToolStrip.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertiesToolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
- this.propertiesToolStrip.MinimumSize = new System.Drawing.Size(150, coreConfiguration.ScaledIconSize.Height + 10);
+ this.propertiesToolStrip.MinimumSize = new System.Drawing.Size(150, coreConfiguration.IconSize.Height + 10);
this.propertiesToolStrip.Name = "propertiesToolStrip";
this.propertiesToolStrip.Stretch = true;
this.propertiesToolStrip.TabIndex = 2;
diff --git a/src/Greenshot.Editor/Forms/ImageEditorForm.cs b/src/Greenshot.Editor/Forms/ImageEditorForm.cs
index 43f87aa5a..d6606665b 100644
--- a/src/Greenshot.Editor/Forms/ImageEditorForm.cs
+++ b/src/Greenshot.Editor/Forms/ImageEditorForm.cs
@@ -30,6 +30,7 @@ using System.Threading;
using System.Windows.Forms;
using Dapplo.Windows.Common.Extensions;
using Dapplo.Windows.Common.Structs;
+using Dapplo.Windows.Dpi;
using Dapplo.Windows.Kernel32;
using Dapplo.Windows.User32.Structs;
using Greenshot.Base;
@@ -41,8 +42,6 @@ using Greenshot.Base.IniFile;
using Greenshot.Base.Interfaces;
using Greenshot.Base.Interfaces.Drawing;
using Greenshot.Base.Interfaces.Forms;
-using Greenshot.Base.UnmanagedHelpers;
-using Greenshot.Base.UnmanagedHelpers.Structs;
using Greenshot.Editor.Configuration;
using Greenshot.Editor.Destinations;
using Greenshot.Editor.Drawing;
@@ -114,19 +113,17 @@ namespace Greenshot.Editor.Forms
///
/// Adjust the icons etc to the supplied DPI settings
///
- ///
- /// DpiChangedEventArgs
- private void AdjustToDpi(object sender, DpiChangedEventArgs dpiChangedEventArgs)
+ ///
+ ///
+ protected override void DpiChangedHandler(int oldDpi, int newDpi)
{
- var dpi = DpiHelper.GetDpi(Handle);
- var newSize = DpiHelper.ScaleWithDpi(coreConfiguration.IconSize, dpi);
+ var newSize = DpiCalculator.ScaleWithDpi(coreConfiguration.IconSize, newDpi);
toolsToolStrip.ImageScalingSize = newSize;
menuStrip1.ImageScalingSize = newSize;
destinationsToolStrip.ImageScalingSize = newSize;
propertiesToolStrip.ImageScalingSize = newSize;
propertiesToolStrip.MinimumSize = new Size(150, newSize.Height + 10);
-
- _surface?.AdjustToDpi(dpi);
+ _surface?.AdjustToDpi(newDpi);
UpdateUi();
}
@@ -152,7 +149,6 @@ namespace Greenshot.Editor.Forms
ManualLanguageApply = true;
InitializeComponent();
// Make sure we change the icon size depending on the scaling
- DpiChanged += AdjustToDpi;
Load += delegate
{
var thread = new Thread(AddDestinations)
@@ -161,7 +157,7 @@ namespace Greenshot.Editor.Forms
};
thread.Start();
- AdjustToDpi(null, null);
+ DpiChangedHandler(96, DeviceDpi);
};
// Make sure the editor is placed on the same location as the last editor was on close
@@ -174,7 +170,7 @@ namespace Greenshot.Editor.Forms
}
// ReSharper disable once UnusedVariable
- WindowDetails thisForm = new WindowDetails(Handle)
+ WindowDetails thisForm = new(Handle)
{
WindowPlacement = EditorConfiguration.GetEditorPlacement()
};
@@ -317,9 +313,8 @@ namespace Greenshot.Editor.Forms
// Loop over all items in the propertiesToolStrip
foreach (ToolStripItem item in propertiesToolStrip.Items)
{
- var cb = item as ToolStripComboBox;
// Only ToolStripComboBox that are visible
- if (cb == null || !cb.Visible)
+ if (item is not ToolStripComboBox { Visible: true } cb)
{
continue;
}
@@ -376,7 +371,7 @@ namespace Greenshot.Editor.Forms
{
if (toolstripDestination.IsDynamic)
{
- ToolStripSplitButton destinationButton = new ToolStripSplitButton
+ ToolStripSplitButton destinationButton = new()
{
DisplayStyle = ToolStripItemDisplayStyle.Image,
Size = new Size(23, 22),
@@ -1960,8 +1955,7 @@ namespace Greenshot.Editor.Forms
private void ZoomSetValue(Fraction value)
{
var surface = Surface as Surface;
- var panel = surface?.Parent as Panel;
- if (panel == null)
+ if (surface?.Parent is not Panel panel)
{
return;
}
diff --git a/src/Greenshot.Plugin.Box/BoxConfiguration.cs b/src/Greenshot.Plugin.Box/BoxConfiguration.cs
index 34ae4afc9..fdef95ae5 100644
--- a/src/Greenshot.Plugin.Box/BoxConfiguration.cs
+++ b/src/Greenshot.Plugin.Box/BoxConfiguration.cs
@@ -21,7 +21,6 @@
using System;
using System.Windows.Forms;
-using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Box.Forms;
diff --git a/src/Greenshot.Plugin.Confluence/ConfluenceConfiguration.cs b/src/Greenshot.Plugin.Confluence/ConfluenceConfiguration.cs
index f2212126d..8176ebe6e 100644
--- a/src/Greenshot.Plugin.Confluence/ConfluenceConfiguration.cs
+++ b/src/Greenshot.Plugin.Confluence/ConfluenceConfiguration.cs
@@ -20,7 +20,6 @@
*/
using System;
-using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
diff --git a/src/Greenshot.Plugin.Flickr/FlickrConfiguration.cs b/src/Greenshot.Plugin.Flickr/FlickrConfiguration.cs
index 8eedbf768..e4f602796 100644
--- a/src/Greenshot.Plugin.Flickr/FlickrConfiguration.cs
+++ b/src/Greenshot.Plugin.Flickr/FlickrConfiguration.cs
@@ -20,7 +20,6 @@
*/
using System.Windows.Forms;
-using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Flickr.Forms;
diff --git a/src/Greenshot.Plugin.Flickr/FlickrPlugin.cs b/src/Greenshot.Plugin.Flickr/FlickrPlugin.cs
index 1939fba22..dcad49473 100644
--- a/src/Greenshot.Plugin.Flickr/FlickrPlugin.cs
+++ b/src/Greenshot.Plugin.Flickr/FlickrPlugin.cs
@@ -30,7 +30,6 @@ using Greenshot.Base.IniFile;
using Greenshot.Base.Interfaces;
using Greenshot.Base.Interfaces.Plugin;
using log4net;
-using log4net.Config;
namespace Greenshot.Plugin.Flickr
{
diff --git a/src/Greenshot.Plugin.GooglePhotos/GooglePhotosConfiguration.cs b/src/Greenshot.Plugin.GooglePhotos/GooglePhotosConfiguration.cs
index 91892f136..5765544b9 100644
--- a/src/Greenshot.Plugin.GooglePhotos/GooglePhotosConfiguration.cs
+++ b/src/Greenshot.Plugin.GooglePhotos/GooglePhotosConfiguration.cs
@@ -20,7 +20,6 @@
using System;
using System.Windows.Forms;
-using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.GooglePhotos.Forms;
diff --git a/src/Greenshot.Plugin.Imgur/ImgurConfiguration.cs b/src/Greenshot.Plugin.Imgur/ImgurConfiguration.cs
index 7635ee3de..3bb695672 100644
--- a/src/Greenshot.Plugin.Imgur/ImgurConfiguration.cs
+++ b/src/Greenshot.Plugin.Imgur/ImgurConfiguration.cs
@@ -22,7 +22,6 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
-using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Imgur.Forms;
diff --git a/src/Greenshot.Plugin.Jira/Forms/JiraForm.cs b/src/Greenshot.Plugin.Jira/Forms/JiraForm.cs
index 5830eb1dc..29b75e9bb 100644
--- a/src/Greenshot.Plugin.Jira/Forms/JiraForm.cs
+++ b/src/Greenshot.Plugin.Jira/Forms/JiraForm.cs
@@ -26,6 +26,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dapplo.Jira.Entities;
+using Dapplo.Windows.Dpi;
using Greenshot.Base.Controls;
using Greenshot.Base.Core;
using Greenshot.Base.IniFile;
@@ -173,7 +174,7 @@ namespace Greenshot.Plugin.Jira.Forms
jiraListView.Columns.Add(translation);
}
- var scaledIconSize = DpiHelper.ScaleWithDpi(CoreConfig.IconSize, DpiHelper.GetDpi(Handle));
+ var scaledIconSize = DpiCalculator.ScaleWithDpi(CoreConfig.IconSize, NativeDpiMethods.GetDpi(Handle));
var imageList = new ImageList
{
ImageSize = scaledIconSize
diff --git a/src/Greenshot.Plugin.Jira/JiraConfiguration.cs b/src/Greenshot.Plugin.Jira/JiraConfiguration.cs
index 069cc3263..7163924c5 100644
--- a/src/Greenshot.Plugin.Jira/JiraConfiguration.cs
+++ b/src/Greenshot.Plugin.Jira/JiraConfiguration.cs
@@ -19,7 +19,6 @@
* along with this program. If not, see .
*/
-using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
diff --git a/src/Greenshot.Plugin.Jira/JiraConnector.cs b/src/Greenshot.Plugin.Jira/JiraConnector.cs
index ad48a09fa..fbfd42543 100644
--- a/src/Greenshot.Plugin.Jira/JiraConnector.cs
+++ b/src/Greenshot.Plugin.Jira/JiraConnector.cs
@@ -63,8 +63,8 @@ namespace Greenshot.Plugin.Jira
var jiraConnector = SimpleServiceProvider.Current.GetInstance();
jiraConnector._jiraClient?.Behaviour.SetConfig(new SvgConfiguration
{
- Width = CoreConfig.ScaledIconSize.Width,
- Height = CoreConfig.ScaledIconSize.Height
+ Width = CoreConfig.IconSize.Width,
+ Height = CoreConfig.IconSize.Height
});
}
};
@@ -112,8 +112,8 @@ namespace Greenshot.Plugin.Jira
_jiraClient = JiraClient.Create(new Uri(JiraConfig.Url));
_jiraClient.Behaviour.SetConfig(new SvgConfiguration
{
- Width = CoreConfig.ScaledIconSize.Width,
- Height = CoreConfig.ScaledIconSize.Height
+ Width = CoreConfig.IconSize.Width,
+ Height = CoreConfig.IconSize.Height
});
_jiraClient.SetBasicAuthentication(user, password);
diff --git a/src/Greenshot.Plugin.Jira/JiraMonitor.cs b/src/Greenshot.Plugin.Jira/JiraMonitor.cs
index 17cc20d16..81a62b759 100644
--- a/src/Greenshot.Plugin.Jira/JiraMonitor.cs
+++ b/src/Greenshot.Plugin.Jira/JiraMonitor.cs
@@ -27,7 +27,9 @@ using System.Threading;
using System.Threading.Tasks;
using Dapplo.Jira;
using Dapplo.Log;
-using Greenshot.Base.Hooking;
+using Dapplo.Windows.Desktop;
+using Dapplo.Windows.Structs;
+using Dapplo.Windows.User32;
namespace Greenshot.Plugin.Jira
{
@@ -40,7 +42,7 @@ namespace Greenshot.Plugin.Jira
{
private static readonly LogSource Log = new LogSource();
private readonly Regex _jiraKeyPattern = new Regex(@"[A-Z][A-Z0-9]+\-[0-9]+");
- private readonly WindowsTitleMonitor _monitor;
+ private readonly IDisposable _monitor;
private readonly IList _jiraInstances = new List();
private readonly IDictionary _projectJiraClientMap = new Dictionary();
@@ -56,9 +58,8 @@ namespace Greenshot.Plugin.Jira
public JiraMonitor(int maxEntries = 40)
{
+ _monitor = WinEventHook.WindowTitleChangeObservable().Subscribe(wei => MonitorTitleChangeEvent(wei));
_maxEntries = maxEntries;
- _monitor = new WindowsTitleMonitor();
- _monitor.TitleChangeEvent += MonitorTitleChangeEvent;
}
///
@@ -82,7 +83,6 @@ namespace Greenshot.Plugin.Jira
}
// free managed resources
- _monitor.TitleChangeEvent -= MonitorTitleChangeEvent;
_monitor.Dispose();
// free native resources if there are any.
}
@@ -162,10 +162,10 @@ namespace Greenshot.Plugin.Jira
///
/// Handle title changes, check for JIRA
///
- ///
- private void MonitorTitleChangeEvent(TitleChangeEventArgs eventArgs)
+ /// WinEventInfo
+ private void MonitorTitleChangeEvent(WinEventInfo winEventInfo)
{
- string windowTitle = eventArgs.Title;
+ string windowTitle = User32Api.GetText(winEventInfo.Handle);
if (string.IsNullOrEmpty(windowTitle))
{
return;
diff --git a/src/Greenshot.Plugin.Win10/Destinations/Win10ShareDestination.cs b/src/Greenshot.Plugin.Win10/Destinations/Win10ShareDestination.cs
index 0574a6d0c..fa31d3a11 100644
--- a/src/Greenshot.Plugin.Win10/Destinations/Win10ShareDestination.cs
+++ b/src/Greenshot.Plugin.Win10/Destinations/Win10ShareDestination.cs
@@ -29,9 +29,11 @@ using System.Windows.Interop;
using System.Windows.Media;
using Windows.Storage;
using Windows.Storage.Streams;
+using Dapplo.Windows.Desktop;
+using Dapplo.Windows.Enums;
+using Dapplo.Windows.User32;
using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
-using Greenshot.Base.Hooking;
using Greenshot.Base.Interfaces;
using Greenshot.Base.Interfaces.Plugin;
using Greenshot.Plugin.Win10.Internal;
@@ -82,24 +84,22 @@ namespace Greenshot.Plugin.Win10.Destinations
triggerWindow.Show();
- var focusMonitor = new WindowsOpenCloseMonitor();
var windowHandle = new WindowInteropHelper(triggerWindow).Handle;
// This is a bad trick, but don't know how else to do it.
// Wait for the focus to return, and depending on the state close the window!
- focusMonitor.WindowOpenCloseChangeEvent += e =>
+ var createDestroyMonitor = WinEventHook.WindowTitleChangeObservable().Subscribe(wei =>
{
- if (e.IsOpen)
+ if (wei.WinEvent == WinEvents.EVENT_OBJECT_CREATE)
{
- if ("Windows Shell Experience Host" == e.Title)
+ var windowTitle = User32Api.GetText(wei.Handle);
+ if ("Windows Shell Experience Host" == windowTitle)
{
- shareInfo.SharingHwnd = e.HWnd;
+ shareInfo.SharingHwnd = wei.Handle;
}
-
return;
}
-
- if (e.HWnd == shareInfo.SharingHwnd)
+ if (wei.Handle == shareInfo.SharingHwnd)
{
if (shareInfo.ApplicationName != null)
{
@@ -108,12 +108,12 @@ namespace Greenshot.Plugin.Win10.Destinations
shareInfo.ShareTask.TrySetResult(false);
}
- };
+ });
Share(shareInfo, windowHandle, surface, captureDetails).GetAwaiter().GetResult();
Log.Debug("Sharing finished, closing window.");
triggerWindow.Close();
- focusMonitor.Dispose();
+ createDestroyMonitor.Dispose();
if (string.IsNullOrWhiteSpace(shareInfo.ApplicationName))
{
exportInformation.ExportMade = false;
diff --git a/src/Greenshot.Plugin.Win10/Native/DataTransferManagerHelper.cs b/src/Greenshot.Plugin.Win10/Native/DataTransferManagerHelper.cs
index 990506a1f..1ef1059c4 100644
--- a/src/Greenshot.Plugin.Win10/Native/DataTransferManagerHelper.cs
+++ b/src/Greenshot.Plugin.Win10/Native/DataTransferManagerHelper.cs
@@ -23,7 +23,6 @@ using System;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.DataTransfer;
using Dapplo.Windows.Common.Extensions;
-using Greenshot.Base.Core;
namespace Greenshot.Plugin.Win10.Native
{
diff --git a/src/Greenshot.Plugin.Win10/Native/IDataTransferManagerInterOp.cs b/src/Greenshot.Plugin.Win10/Native/IDataTransferManagerInterOp.cs
index 6d9eb8b5b..408f5f451 100644
--- a/src/Greenshot.Plugin.Win10/Native/IDataTransferManagerInterOp.cs
+++ b/src/Greenshot.Plugin.Win10/Native/IDataTransferManagerInterOp.cs
@@ -21,7 +21,6 @@ using System;
using System.Runtime.InteropServices;
using Windows.ApplicationModel.DataTransfer;
using Dapplo.Windows.Common.Enums;
-using Greenshot.Base.Core.Enums;
namespace Greenshot.Plugin.Win10.Native
{
diff --git a/src/Greenshot/Controls/ContextMenuToolStripProfessionalRenderer.cs b/src/Greenshot/Controls/ContextMenuToolStripProfessionalRenderer.cs
index ef21943f6..0a9a511c7 100644
--- a/src/Greenshot/Controls/ContextMenuToolStripProfessionalRenderer.cs
+++ b/src/Greenshot/Controls/ContextMenuToolStripProfessionalRenderer.cs
@@ -22,8 +22,10 @@
using System.Drawing;
using System.Windows.Forms;
using Dapplo.Windows.Common.Structs;
+using Dapplo.Windows.Dpi;
using Greenshot.Base.Core;
using Greenshot.Base.IniFile;
+using Greenshot.Base.Interfaces;
namespace Greenshot.Controls
{
@@ -32,15 +34,21 @@ namespace Greenshot.Controls
///
public class ContextMenuToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{
+ private readonly IProvideDeviceDpi _provideDeviceDpi;
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection();
private static Image _scaledCheckbox;
+ public ContextMenuToolStripProfessionalRenderer(IProvideDeviceDpi provideDeviceDpi)
+ {
+ _provideDeviceDpi = provideDeviceDpi;
+ }
protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
{
- if (_scaledCheckbox == null || _scaledCheckbox.Size != CoreConfig.ScaledIconSize)
+ var newSize = DpiCalculator.ScaleWithDpi(CoreConfig.IconSize, _provideDeviceDpi.DeviceDpi);
+ if (_scaledCheckbox == null || _scaledCheckbox.Size != newSize)
{
_scaledCheckbox?.Dispose();
- _scaledCheckbox = ImageHelper.ResizeImage(e.Image, true, CoreConfig.ScaledIconSize.Width, CoreConfig.ScaledIconSize.Height, null);
+ _scaledCheckbox = ImageHelper.ResizeImage(e.Image, true, newSize.Width, newSize.Height, null);
}
NativeRect old = e.ImageRectangle;
diff --git a/src/Greenshot/Forms/MainForm.Designer.cs b/src/Greenshot/Forms/MainForm.Designer.cs
index 015e0060b..b558bf4f9 100644
--- a/src/Greenshot/Forms/MainForm.Designer.cs
+++ b/src/Greenshot/Forms/MainForm.Designer.cs
@@ -106,7 +106,7 @@ namespace Greenshot.Forms {
this.contextMenu.Name = "contextMenu";
this.contextMenu.Closing += new System.Windows.Forms.ToolStripDropDownClosingEventHandler(this.ContextMenuClosing);
this.contextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuOpening);
- this.contextMenu.Renderer = new Greenshot.Controls.ContextMenuToolStripProfessionalRenderer();
+ this.contextMenu.Renderer = new Greenshot.Controls.ContextMenuToolStripProfessionalRenderer(this);
//
// contextmenu_capturearea
//
@@ -204,7 +204,7 @@ namespace Greenshot.Forms {
// contextmenu_quicksettings
//
this.contextmenu_quicksettings.Name = "contextmenu_quicksettings";
- this.contextmenu_quicksettings.Size = new System.Drawing.Size(170, coreConfiguration.ScaledIconSize.Height + 8);
+ this.contextmenu_quicksettings.Size = new System.Drawing.Size(170, coreConfiguration.IconSize.Height + 8);
//
// contextmenu_settings
//
diff --git a/src/Greenshot/Forms/MainForm.cs b/src/Greenshot/Forms/MainForm.cs
index 383a5a2c4..78044981a 100644
--- a/src/Greenshot/Forms/MainForm.cs
+++ b/src/Greenshot/Forms/MainForm.cs
@@ -33,6 +33,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Dapplo.Windows.DesktopWindowsManager;
+using Dapplo.Windows.Dpi;
using Dapplo.Windows.Kernel32;
using Greenshot.Base;
using Greenshot.Base.Controls;
@@ -43,7 +44,6 @@ using Greenshot.Base.Help;
using Greenshot.Base.IniFile;
using Greenshot.Base.Interfaces;
using Greenshot.Base.Interfaces.Plugin;
-using Greenshot.Base.UnmanagedHelpers;
using Greenshot.Configuration;
using Greenshot.Destinations;
using Greenshot.Editor;
@@ -60,7 +60,7 @@ namespace Greenshot.Forms
///
/// This is the MainForm, the shell of Greenshot
///
- public partial class MainForm : BaseForm, IGreenshotMainForm, ICaptureHelper
+ public partial class MainForm : BaseForm, IGreenshotMainForm, ICaptureHelper, IProvideDeviceDpi
{
private static ILog LOG;
private static ResourceMutex _applicationMutex;
@@ -380,8 +380,7 @@ namespace Greenshot.Forms
{
var uiContext = TaskScheduler.FromCurrentSynchronizationContext();
SimpleServiceProvider.Current.AddService(uiContext);
- DpiChanged += (e, o) => ApplyDpiScaling();
-
+
// The most important form is this
SimpleServiceProvider.Current.AddService