mirror of
https://github.com/greenshot/greenshot
synced 2025-07-05 20:42:14 -07:00
Refactoring to use Dapplo.Windows (#398)
* Removed a LOT of the native "Win32" invokes in favor of Dapplo.Windows which was created mainly for Greenshot. * Changed all usages of Point, Rectangle, RectangleF, Size to the Native versions of those from Dapplo.Windows.Common. * Small fix for the OCR text feature.
This commit is contained in:
parent
8aca1c8282
commit
13e2e67e7c
159 changed files with 1646 additions and 6560 deletions
|
@ -102,6 +102,20 @@ namespace Greenshot.Base.Controls
|
|||
/// </summary>
|
||||
protected bool ToFront { get; set; }
|
||||
|
||||
protected GreenshotForm()
|
||||
{
|
||||
DpiChanged += (sender, dpiChangedEventArgs) => DpiChangedHandler(dpiChangedEventArgs.DeviceDpiOld, dpiChangedEventArgs.DeviceDpiNew);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the basic DpiChangedHandler responsible for all the DPI relative changes
|
||||
/// </summary>
|
||||
/// <param name="oldDpi"></param>
|
||||
/// <param name="newDpi"></param>
|
||||
protected virtual void DpiChangedHandler(int oldDpi, int newDpi)
|
||||
{
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// <summary>
|
||||
/// Code to initialize the language etc during design time
|
||||
|
@ -382,10 +396,10 @@ namespace Greenshot.Base.Controls
|
|||
|
||||
protected void ApplyLanguage(Control applyTo)
|
||||
{
|
||||
if (!(applyTo is IGreenshotLanguageBindable languageBindable))
|
||||
if (applyTo is not IGreenshotLanguageBindable languageBindable)
|
||||
{
|
||||
// check if it's a menu!
|
||||
if (!(applyTo is ToolStrip toolStrip))
|
||||
if (applyTo is not ToolStrip toolStrip)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -402,20 +416,14 @@ namespace Greenshot.Base.Controls
|
|||
ApplyLanguage(applyTo, languageBindable.LanguageKey);
|
||||
|
||||
// Repopulate the combox boxes
|
||||
if (applyTo is IGreenshotConfigBindable configBindable && applyTo is GreenshotComboBox comboxBox)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(configBindable.SectionName) && !string.IsNullOrEmpty(configBindable.PropertyName))
|
||||
{
|
||||
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
|
||||
if (section != null)
|
||||
{
|
||||
// Only update the language, so get the actual value and than repopulate
|
||||
Enum currentValue = comboxBox.GetSelectedEnum();
|
||||
comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType);
|
||||
comboxBox.SetValue(currentValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (applyTo is not (IGreenshotConfigBindable configBindable and GreenshotComboBox comboxBox)) return;
|
||||
if (string.IsNullOrEmpty(configBindable.SectionName) || string.IsNullOrEmpty(configBindable.PropertyName)) return;
|
||||
IniSection section = IniConfig.GetIniSection(configBindable.SectionName);
|
||||
if (section == null) return;
|
||||
// Only update the language, so get the actual value and than repopulate
|
||||
Enum currentValue = comboxBox.GetSelectedEnum();
|
||||
comboxBox.Populate(section.Values[configBindable.PropertyName].ValueType);
|
||||
comboxBox.SetValue(currentValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -458,10 +466,9 @@ namespace Greenshot.Base.Controls
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!(controlObject is Control applyToControl))
|
||||
if (controlObject is not Control applyToControl)
|
||||
{
|
||||
ToolStripItem applyToItem = controlObject as ToolStripItem;
|
||||
if (applyToItem == null)
|
||||
if (controlObject is not ToolStripItem applyToItem)
|
||||
{
|
||||
LOG.DebugFormat("No Control or ToolStripItem: {0}", field.Name);
|
||||
continue;
|
||||
|
@ -530,7 +537,7 @@ namespace Greenshot.Base.Controls
|
|||
/// <summary>
|
||||
/// Fill all GreenshotControls with the values from the configuration
|
||||
/// </summary>
|
||||
protected void FillFields()
|
||||
private void FillFields()
|
||||
{
|
||||
foreach (FieldInfo field in GetCachedFields(GetType()))
|
||||
{
|
||||
|
|
|
@ -22,12 +22,15 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.DesktopWindowsManager;
|
||||
using Dapplo.Windows.DesktopWindowsManager.Structs;
|
||||
using Dapplo.Windows.User32;
|
||||
using Dapplo.Windows.User32.Enums;
|
||||
using Greenshot.Base.Core;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
|
||||
namespace Greenshot.Base.Controls
|
||||
{
|
||||
|
@ -70,7 +73,7 @@ namespace Greenshot.Base.Controls
|
|||
{
|
||||
if (_thumbnailHandle == IntPtr.Zero) return;
|
||||
|
||||
DWM.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
DwmApi.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
_thumbnailHandle = IntPtr.Zero;
|
||||
}
|
||||
|
||||
|
@ -83,19 +86,19 @@ namespace Greenshot.Base.Controls
|
|||
{
|
||||
UnregisterThumbnail();
|
||||
|
||||
DWM.DwmRegisterThumbnail(Handle, window.Handle, out _thumbnailHandle);
|
||||
DwmApi.DwmRegisterThumbnail(Handle, window.Handle, out _thumbnailHandle);
|
||||
if (_thumbnailHandle == IntPtr.Zero) return;
|
||||
|
||||
var result = DWM.DwmQueryThumbnailSourceSize(_thumbnailHandle, out var sourceSize);
|
||||
var result = DwmApi.DwmQueryThumbnailSourceSize(_thumbnailHandle, out var sourceSize);
|
||||
if (result.Failed())
|
||||
{
|
||||
DWM.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
DwmApi.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sourceSize.IsEmpty)
|
||||
{
|
||||
DWM.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
DwmApi.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -110,17 +113,17 @@ namespace Greenshot.Base.Controls
|
|||
Width = thumbnailWidth;
|
||||
Height = thumbnailHeight;
|
||||
// Prepare the displaying of the Thumbnail
|
||||
var dwmThumbnailProperties = new DWM_THUMBNAIL_PROPERTIES
|
||||
var dwmThumbnailProperties = new DwmThumbnailProperties()
|
||||
{
|
||||
Opacity = 255,
|
||||
Visible = true,
|
||||
SourceClientAreaOnly = false,
|
||||
Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight)
|
||||
Destination = new NativeRect(0, 0, thumbnailWidth, thumbnailHeight)
|
||||
};
|
||||
result = DWM.DwmUpdateThumbnailProperties(_thumbnailHandle, ref dwmThumbnailProperties);
|
||||
result = DwmApi.DwmUpdateThumbnailProperties(_thumbnailHandle, ref dwmThumbnailProperties);
|
||||
if (result.Failed())
|
||||
{
|
||||
DWM.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
DwmApi.DwmUnregisterThumbnail(_thumbnailHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -137,13 +140,13 @@ namespace Greenshot.Base.Controls
|
|||
// Make sure it's on "top"!
|
||||
if (parentControl != null)
|
||||
{
|
||||
User32.SetWindowPos(Handle, parentControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
|
||||
User32Api.SetWindowPos(Handle, parentControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
|
||||
}
|
||||
}
|
||||
|
||||
public void AlignToControl(Control alignTo)
|
||||
{
|
||||
var screenBounds = WindowCapture.GetScreenBounds();
|
||||
var screenBounds = DisplayInfo.ScreenBounds;
|
||||
if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height))
|
||||
{
|
||||
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height);
|
||||
|
|
|
@ -24,15 +24,18 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
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;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of AbstractDestination.
|
||||
/// The AbstractDestination is a default implementation of IDestination
|
||||
/// </summary>
|
||||
public abstract class AbstractDestination : IDestination
|
||||
{
|
||||
|
@ -41,7 +44,7 @@ namespace Greenshot.Base.Core
|
|||
|
||||
public virtual int CompareTo(object obj)
|
||||
{
|
||||
if (!(obj is IDestination other))
|
||||
if (obj is not IDestination other)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -176,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
|
||||
};
|
||||
|
@ -184,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();
|
||||
|
@ -304,7 +307,7 @@ namespace Greenshot.Base.Core
|
|||
ShowMenuAtCursor(menu);
|
||||
return exportInformation;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
|
@ -312,21 +315,21 @@ namespace Greenshot.Base.Core
|
|||
private static void ShowMenuAtCursor(ContextMenuStrip menu)
|
||||
{
|
||||
// find a suitable location
|
||||
Point location = Cursor.Position;
|
||||
Rectangle menuRectangle = new Rectangle(location, menu.Size);
|
||||
NativePoint location = Cursor.Position;
|
||||
var menuRectangle = new NativeRect(location, menu.Size);
|
||||
|
||||
menuRectangle.Intersect(WindowCapture.GetScreenBounds());
|
||||
menuRectangle = menuRectangle.Intersect(DisplayInfo.ScreenBounds);
|
||||
if (menuRectangle.Height < menu.Height)
|
||||
{
|
||||
location.Offset(-40, -(menuRectangle.Height - menu.Height));
|
||||
location = location.Offset(-40, -(menuRectangle.Height - menu.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
location.Offset(-40, -10);
|
||||
location = location.Offset(-40, -10);
|
||||
}
|
||||
|
||||
// This prevents the problem that the context menu shows in the task-bar
|
||||
User32.SetForegroundWindow(SimpleServiceProvider.Current.GetInstance<NotifyIcon>().ContextMenuStrip.Handle);
|
||||
User32Api.SetForegroundWindow(SimpleServiceProvider.Current.GetInstance<NotifyIcon>().ContextMenuStrip.Handle);
|
||||
menu.Show(location);
|
||||
menu.Focus();
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
|
@ -280,19 +281,19 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Implementation of the RectangleAnimator
|
||||
/// </summary>
|
||||
public class RectangleAnimator : AnimatorBase<Rectangle>
|
||||
public class RectangleAnimator : AnimatorBase<NativeRect>
|
||||
{
|
||||
public RectangleAnimator(Rectangle first, Rectangle last, int frames)
|
||||
public RectangleAnimator(NativeRect first, NativeRect last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleAnimator(Rectangle first, Rectangle last, int frames, EasingType easingType)
|
||||
public RectangleAnimator(NativeRect first, NativeRect last, int frames, EasingType easingType)
|
||||
: base(first, last, frames, easingType, EasingMode.EaseIn)
|
||||
{
|
||||
}
|
||||
|
||||
public RectangleAnimator(Rectangle first, Rectangle last, int frames, EasingType easingType, EasingMode easingMode)
|
||||
public RectangleAnimator(NativeRect first, NativeRect last, int frames, EasingType easingType, EasingMode easingMode)
|
||||
: base(first, last, frames, easingType, easingMode)
|
||||
{
|
||||
}
|
||||
|
@ -300,8 +301,8 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Calculate the next frame object
|
||||
/// </summary>
|
||||
/// <returns>Rectangle</returns>
|
||||
public override Rectangle Next()
|
||||
/// <returns>NativeRect</returns>
|
||||
public override NativeRect Next()
|
||||
{
|
||||
if (!NextFrame)
|
||||
{
|
||||
|
@ -317,7 +318,7 @@ namespace Greenshot.Base.Core
|
|||
double dh = Last.Height - First.Height;
|
||||
int width = First.Width + (int) (easingValue * dw);
|
||||
int height = First.Height + (int) (easingValue * dh);
|
||||
Current = new Rectangle(x, y, width, height);
|
||||
Current = new NativeRect(x, y, width, height);
|
||||
|
||||
return Current;
|
||||
}
|
||||
|
@ -326,19 +327,19 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Implementation of the PointAnimator
|
||||
/// </summary>
|
||||
public class PointAnimator : AnimatorBase<Point>
|
||||
public class PointAnimator : AnimatorBase<NativePoint>
|
||||
{
|
||||
public PointAnimator(Point first, Point last, int frames)
|
||||
public PointAnimator(NativePoint first, NativePoint last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn)
|
||||
{
|
||||
}
|
||||
|
||||
public PointAnimator(Point first, Point last, int frames, EasingType easingType)
|
||||
public PointAnimator(NativePoint first, NativePoint last, int frames, EasingType easingType)
|
||||
: base(first, last, frames, easingType, EasingMode.EaseIn)
|
||||
{
|
||||
}
|
||||
|
||||
public PointAnimator(Point first, Point last, int frames, EasingType easingType, EasingMode easingMode)
|
||||
public PointAnimator(NativePoint first, NativePoint last, int frames, EasingType easingType, EasingMode easingMode)
|
||||
: base(first, last, frames, easingType, easingMode)
|
||||
{
|
||||
}
|
||||
|
@ -347,7 +348,7 @@ namespace Greenshot.Base.Core
|
|||
/// Calculate the next frame value
|
||||
/// </summary>
|
||||
/// <returns>Point</returns>
|
||||
public override Point Next()
|
||||
public override NativePoint Next()
|
||||
{
|
||||
if (NextFrame)
|
||||
{
|
||||
|
@ -357,7 +358,7 @@ namespace Greenshot.Base.Core
|
|||
|
||||
int x = First.X + (int) (easingValue * dx);
|
||||
int y = First.Y + (int) (easingValue * dy);
|
||||
Current = new Point(x, y);
|
||||
Current = new NativePoint(x, y);
|
||||
}
|
||||
|
||||
return Current;
|
||||
|
@ -367,19 +368,19 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Implementation of the SizeAnimator
|
||||
/// </summary>
|
||||
public class SizeAnimator : AnimatorBase<Size>
|
||||
public class SizeAnimator : AnimatorBase<NativeSize>
|
||||
{
|
||||
public SizeAnimator(Size first, Size last, int frames)
|
||||
public SizeAnimator(NativeSize first, NativeSize last, int frames)
|
||||
: base(first, last, frames, EasingType.Linear, EasingMode.EaseIn)
|
||||
{
|
||||
}
|
||||
|
||||
public SizeAnimator(Size first, Size last, int frames, EasingType easingType)
|
||||
public SizeAnimator(NativeSize first, NativeSize last, int frames, EasingType easingType)
|
||||
: base(first, last, frames, easingType, EasingMode.EaseIn)
|
||||
{
|
||||
}
|
||||
|
||||
public SizeAnimator(Size first, Size last, int frames, EasingType easingType, EasingMode easingMode)
|
||||
public SizeAnimator(NativeSize first, NativeSize last, int frames, EasingType easingType, EasingMode easingMode)
|
||||
: base(first, last, frames, easingType, easingMode)
|
||||
{
|
||||
}
|
||||
|
@ -388,7 +389,7 @@ namespace Greenshot.Base.Core
|
|||
/// Calculate the next frame values
|
||||
/// </summary>
|
||||
/// <returns>Size</returns>
|
||||
public override Size Next()
|
||||
public override NativeSize Next()
|
||||
{
|
||||
if (NextFrame)
|
||||
{
|
||||
|
@ -397,7 +398,7 @@ namespace Greenshot.Base.Core
|
|||
double dh = Last.Height - First.Height;
|
||||
int width = First.Width + (int) (easingValue * dw);
|
||||
int height = First.Height + (int) (easingValue * dh);
|
||||
Current = new Size(width, height);
|
||||
Current = new NativeSize(width, height);
|
||||
}
|
||||
|
||||
return Current;
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.User32;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Ocr;
|
||||
using log4net;
|
||||
|
@ -36,18 +39,18 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Capture));
|
||||
|
||||
private Rectangle _screenBounds;
|
||||
private NativeRect _screenBounds;
|
||||
|
||||
/// <summary>
|
||||
/// Get/Set the screen bounds
|
||||
/// </summary>
|
||||
public Rectangle ScreenBounds
|
||||
public NativeRect ScreenBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_screenBounds == Rectangle.Empty)
|
||||
if (_screenBounds.IsEmpty)
|
||||
{
|
||||
_screenBounds = WindowCapture.GetScreenBounds();
|
||||
_screenBounds = DisplayInfo.ScreenBounds;
|
||||
}
|
||||
|
||||
return _screenBounds;
|
||||
|
@ -124,23 +127,23 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public bool CursorVisible { get; set; }
|
||||
|
||||
private Point _cursorLocation = Point.Empty;
|
||||
private NativePoint _cursorLocation = NativePoint.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Get/Set the CursorLocation
|
||||
/// </summary>
|
||||
public Point CursorLocation
|
||||
public NativePoint CursorLocation
|
||||
{
|
||||
get => _cursorLocation;
|
||||
set => _cursorLocation = value;
|
||||
}
|
||||
|
||||
private Point _location = Point.Empty;
|
||||
private NativePoint _location = NativePoint.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Get/set the Location
|
||||
/// </summary>
|
||||
public Point Location
|
||||
public NativePoint Location
|
||||
{
|
||||
get => _location;
|
||||
set => _location = value;
|
||||
|
@ -162,7 +165,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public Capture()
|
||||
{
|
||||
_screenBounds = WindowCapture.GetScreenBounds();
|
||||
_screenBounds = DisplayInfo.ScreenBounds;
|
||||
_captureDetails = new CaptureDetails();
|
||||
}
|
||||
|
||||
|
@ -214,8 +217,8 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
|
||||
/// </summary>
|
||||
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
|
||||
public bool Crop(Rectangle cropRectangle)
|
||||
/// <param name="cropRectangle">NativeRect with bitmap coordinates</param>
|
||||
public bool Crop(NativeRect cropRectangle)
|
||||
{
|
||||
Log.Debug("Cropping to: " + cropRectangle);
|
||||
if (!ImageHelper.Crop(ref _image, ref cropRectangle))
|
||||
|
@ -245,7 +248,7 @@ namespace Greenshot.Base.Core
|
|||
/// <param name="y">y coordinates to move the mouse</param>
|
||||
public void MoveMouseLocation(int x, int y)
|
||||
{
|
||||
_cursorLocation.Offset(x, y);
|
||||
_cursorLocation = _cursorLocation.Offset(x, y);
|
||||
}
|
||||
|
||||
// TODO: Enable when the elements are usable again.
|
||||
|
@ -261,7 +264,7 @@ namespace Greenshot.Base.Core
|
|||
|
||||
//private void MoveElements(List<ICaptureElement> listOfElements, int x, int y) {
|
||||
// foreach(ICaptureElement childElement in listOfElements) {
|
||||
// Rectangle bounds = childElement.Bounds;
|
||||
// NativeRect bounds = childElement.Bounds;
|
||||
// bounds.Offset(x, y);
|
||||
// childElement.Bounds = bounds;
|
||||
// MoveElements(childElement.Children, x, y);
|
||||
|
|
|
@ -20,15 +20,16 @@
|
|||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the method signature which is used to capture a rectangle from the screen.
|
||||
/// </summary>
|
||||
/// <param name="captureBounds"></param>
|
||||
/// <param name="captureBounds">NativeRect</param>
|
||||
/// <returns>Captured Bitmap</returns>
|
||||
public delegate Bitmap CaptureScreenRectangleHandler(Rectangle captureBounds);
|
||||
public delegate Bitmap CaptureScreenRectangleHandler(NativeRect captureBounds);
|
||||
|
||||
/// <summary>
|
||||
/// This is a hack to experiment with different screen capture routines
|
||||
|
|
|
@ -30,13 +30,17 @@ using System.Runtime.InteropServices;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Clipboard;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.Gdi32.Enums;
|
||||
using Dapplo.Windows.Gdi32.Structs;
|
||||
using Dapplo.Windows.User32;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.Core.FileFormatHandlers;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Base.Interfaces.Plugin;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using log4net;
|
||||
using HtmlDocument = HtmlAgilityPack.HtmlDocument;
|
||||
|
||||
|
@ -115,12 +119,12 @@ EndSelection:<<<<<<<4
|
|||
string owner = null;
|
||||
try
|
||||
{
|
||||
IntPtr hWnd = User32.GetClipboardOwner();
|
||||
IntPtr hWnd = ClipboardNative.CurrentOwner;
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
User32.GetWindowThreadProcessId(hWnd, out var pid);
|
||||
User32Api.GetWindowThreadProcessId(hWnd, out var pid);
|
||||
using Process me = Process.GetCurrentProcess();
|
||||
using Process ownerProcess = Process.GetProcessById(pid);
|
||||
// Exclude myself
|
||||
|
@ -142,9 +146,7 @@ EndSelection:<<<<<<<4
|
|||
catch (Exception e)
|
||||
{
|
||||
Log.Warn("Non critical error: Couldn't get clipboard process, trying to use the title.", e);
|
||||
var title = new StringBuilder(260, 260);
|
||||
User32.GetWindowText(hWnd, title, title.Capacity);
|
||||
owner = title.ToString();
|
||||
owner = User32Api.GetText(hWnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -282,6 +284,9 @@ EndSelection:<<<<<<<4
|
|||
{
|
||||
if (dataObject == null) return false;
|
||||
|
||||
IList<string> formats = GetFormats(dataObject);
|
||||
Log.DebugFormat("Found formats: {0}", string.Join(",", formats));
|
||||
|
||||
if (dataObject.GetDataPresent(DataFormats.Bitmap)
|
||||
|| dataObject.GetDataPresent(DataFormats.Dib)
|
||||
|| dataObject.GetDataPresent(DataFormats.Tiff)
|
||||
|
@ -638,8 +643,6 @@ EndSelection:<<<<<<<4
|
|||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IDrawableContainer drawableContainer = null;
|
||||
using FileStream fileStream = new FileStream(imageFile, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
IEnumerable<IDrawableContainer> drawableContainers;
|
||||
try
|
||||
|
@ -1021,20 +1024,17 @@ EndSelection:<<<<<<<4
|
|||
dibV5Stream = new MemoryStream();
|
||||
|
||||
// Create the BITMAPINFOHEADER
|
||||
var header = new BITMAPINFOHEADERV5(imageToSave.Width, imageToSave.Height, 32)
|
||||
{
|
||||
// Make sure we have BI_BITFIELDS, this seems to be normal for Format17?
|
||||
biCompression = BI_COMPRESSION.BI_BITFIELDS
|
||||
};
|
||||
var header = BitmapV5Header.Create(imageToSave.Width, imageToSave.Height, 32);
|
||||
// Make sure we have BI_BITFIELDS, this seems to be normal for Format17?
|
||||
header.Compression = BitmapCompressionMethods.BI_BITFIELDS;
|
||||
// Create a byte[] to write
|
||||
byte[] headerBytes = BinaryStructHelper.ToByteArray(header);
|
||||
// Write the BITMAPINFOHEADER to the stream
|
||||
dibV5Stream.Write(headerBytes, 0, headerBytes.Length);
|
||||
|
||||
// As we have specified BI_COMPRESSION.BI_BITFIELDS, the BitfieldColorMask needs to be added
|
||||
// This also makes sure the default values are set
|
||||
BitfieldColorMask colorMask = new BitfieldColorMask();
|
||||
// Make sure the values are set
|
||||
colorMask.InitValues();
|
||||
// Create the byte[] from the struct
|
||||
byte[] colorMaskBytes = BinaryStructHelper.ToByteArray(colorMask);
|
||||
Array.Reverse(colorMaskBytes);
|
||||
|
@ -1125,7 +1125,7 @@ EndSelection:<<<<<<<4
|
|||
private static byte[] BitmapToByteArray(Bitmap bitmap)
|
||||
{
|
||||
// Lock the bitmap's bits.
|
||||
Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
|
||||
var rect = new NativeRect(0, 0, bitmap.Width, bitmap.Height);
|
||||
BitmapData bmpData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
|
||||
int absStride = Math.Abs(bmpData.Stride);
|
||||
|
|
|
@ -24,9 +24,9 @@ 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;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces;
|
||||
|
@ -322,17 +322,17 @@ namespace Greenshot.Base.Core
|
|||
public bool ProcessEXIFOrientation { get; set; }
|
||||
|
||||
[IniProperty("LastCapturedRegion", Description = "The last used region, for reuse in the capture last region")]
|
||||
public Rectangle LastCapturedRegion { get; set; }
|
||||
public NativeRect LastCapturedRegion { get; set; }
|
||||
|
||||
[IniProperty("Win10BorderCrop", Description = "The capture is cropped with these settings, e.g. when you don't want to color around it -1,-1"), DefaultValue("0,0")]
|
||||
public Size Win10BorderCrop { get; set; }
|
||||
public NativeSize Win10BorderCrop { get; set; }
|
||||
|
||||
private Size _iconSize;
|
||||
private NativeSize _iconSize;
|
||||
|
||||
[IniProperty("BaseIconSize",
|
||||
Description = "Defines the base size of the icons (e.g. for the buttons in the editor), default value 16,16 and it's scaled to the current DPI",
|
||||
DefaultValue = "16,16")]
|
||||
public Size IconSize
|
||||
public NativeSize IconSize
|
||||
{
|
||||
get { return _iconSize; }
|
||||
set
|
||||
|
@ -369,13 +369,11 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Size 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;
|
||||
|
|
|
@ -1,203 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// This handles DPI changes see
|
||||
/// <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266.aspx">Writing DPI-Aware Desktop and Win32 Applications</a>
|
||||
/// </summary>
|
||||
public static class DpiHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the default DPI for the screen
|
||||
/// </summary>
|
||||
public const uint DefaultScreenDpi = 96;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the current DPI for the UI element which is related to this DpiHandler
|
||||
/// </summary>
|
||||
public static uint Dpi { get; private set; } = WindowsVersion.IsWindows10OrLater ? GetDpiForSystem() : DefaultScreenDpi;
|
||||
|
||||
/// <summary>
|
||||
/// Calculate a DPI scale factor
|
||||
/// </summary>
|
||||
/// <param name="dpi">uint</param>
|
||||
/// <returns>double</returns>
|
||||
public static float DpiScaleFactor(uint dpi)
|
||||
{
|
||||
if (dpi == 0)
|
||||
{
|
||||
dpi = Dpi;
|
||||
}
|
||||
|
||||
return (float) dpi / DefaultScreenDpi;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale the supplied number according to the supplied dpi
|
||||
/// </summary>
|
||||
/// <param name="someNumber">double with e.g. the width 16 for 16x16 images</param>
|
||||
/// <param name="dpi">current dpi, normal is 96.</param>
|
||||
/// <param name="scaleModifier">A function which can modify the scale factor</param>
|
||||
/// <returns>double with the scaled number</returns>
|
||||
public static float ScaleWithDpi(float someNumber, uint dpi, Func<float, float> scaleModifier = null)
|
||||
{
|
||||
var dpiScaleFactor = DpiScaleFactor(dpi);
|
||||
if (scaleModifier != null)
|
||||
{
|
||||
dpiScaleFactor = scaleModifier(dpiScaleFactor);
|
||||
}
|
||||
|
||||
return dpiScaleFactor * someNumber;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale the supplied Size according to the supplied dpi
|
||||
/// </summary>
|
||||
/// <param name="size">Size to resize</param>
|
||||
/// <param name="dpi">current dpi, normal is 96.</param>
|
||||
/// <param name="scaleModifier">A function which can modify the scale factor</param>
|
||||
/// <returns>NativeSize scaled</returns>
|
||||
public static Size ScaleWithDpi(Size size, uint dpi, Func<float, float> scaleModifier = null)
|
||||
{
|
||||
var dpiScaleFactor = DpiScaleFactor(dpi);
|
||||
if (scaleModifier != null)
|
||||
{
|
||||
dpiScaleFactor = scaleModifier(dpiScaleFactor);
|
||||
}
|
||||
|
||||
return new Size((int) (dpiScaleFactor * size.Width), (int) (dpiScaleFactor * size.Height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale the supplied NativeSize to the current dpi
|
||||
/// </summary>
|
||||
/// <param name="size">NativeSize to scale</param>
|
||||
/// <param name="scaleModifier">A function which can modify the scale factor</param>
|
||||
/// <returns>NativeSize scaled</returns>
|
||||
public static Size ScaleWithCurrentDpi(Size size, Func<float, float> scaleModifier = null)
|
||||
{
|
||||
return ScaleWithDpi(size, Dpi, scaleModifier);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the DPI for the screen which the location is located on
|
||||
/// </summary>
|
||||
/// <param name="location">POINT</param>
|
||||
/// <returns>uint</returns>
|
||||
public static uint GetDpi(POINT location)
|
||||
{
|
||||
if (!WindowsVersion.IsWindows81OrLater)
|
||||
{
|
||||
return DefaultScreenDpi;
|
||||
}
|
||||
RECT rect = new RECT(location.X, location.Y, 1, 1);
|
||||
IntPtr hMonitor = User32.MonitorFromRect(ref rect, User32.MONITOR_DEFAULTTONEAREST);
|
||||
var result = GetDpiForMonitor(hMonitor, MonitorDpiType.EffectiveDpi, out var dpiX, out var dpiY);
|
||||
if (result.Succeeded())
|
||||
{
|
||||
return dpiX;
|
||||
}
|
||||
|
||||
return DefaultScreenDpi;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the DPI value for the supplied window handle
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr</param>
|
||||
/// <returns>dpi value</returns>
|
||||
public static uint GetDpi(IntPtr hWnd)
|
||||
{
|
||||
if (!User32.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 = User32.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) GDI32.GetDeviceCaps(hdc, DeviceCaps.LOGPIXELSX);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See more at <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/mt748624(v=vs.85).aspx">GetDpiForWindow function</a>
|
||||
/// Returns the dots per inch (dpi) value for the associated window.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr</param>
|
||||
/// <returns>uint with dpi</returns>
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetDpiForWindow(IntPtr hWnd);
|
||||
|
||||
/// <summary>
|
||||
/// See
|
||||
/// <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dn280510(v=vs.85).aspx">GetDpiForMonitor function</a>
|
||||
/// Queries the dots per inch (dpi) of a display.
|
||||
/// </summary>
|
||||
/// <param name="hMonitor">IntPtr</param>
|
||||
/// <param name="dpiType">MonitorDpiType</param>
|
||||
/// <param name="dpiX">out int for the horizontal dpi</param>
|
||||
/// <param name="dpiY">out int for the vertical dpi</param>
|
||||
/// <returns>true if all okay</returns>
|
||||
[DllImport("shcore.dll", SetLastError = true)]
|
||||
private static extern HResult GetDpiForMonitor(IntPtr hMonitor, MonitorDpiType dpiType, out uint dpiX, out uint dpiY);
|
||||
|
||||
/// <summary>
|
||||
/// See <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/mt748623(v=vs.85).aspx">GetDpiForSystem function</a>
|
||||
/// Returns the system DPI.
|
||||
/// </summary>
|
||||
/// <returns>uint with the system DPI</returns>
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint GetDpiForSystem();
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Effects;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
|
@ -136,16 +138,16 @@ namespace Greenshot.Base.Core
|
|||
|
||||
break;
|
||||
case "ShadowOffset":
|
||||
Point shadowOffset = new Point();
|
||||
NativePoint shadowOffset = new NativePoint();
|
||||
string[] coordinates = pair[1].Split(',');
|
||||
if (int.TryParse(coordinates[0], out var shadowOffsetX))
|
||||
{
|
||||
shadowOffset.X = shadowOffsetX;
|
||||
shadowOffset = shadowOffset.ChangeX(shadowOffsetX);
|
||||
}
|
||||
|
||||
if (int.TryParse(coordinates[1], out var shadowOffsetY))
|
||||
{
|
||||
shadowOffset.Y = shadowOffsetY;
|
||||
shadowOffset = shadowOffset.ChangeY(shadowOffsetY);
|
||||
}
|
||||
|
||||
effect.ShadowOffset = shadowOffset;
|
||||
|
|
|
@ -1,33 +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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.Core.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// The HRESULT represents Windows error codes
|
||||
/// See <a href="https://en.wikipedia.org/wiki/HRESULT">wikipedia</a>
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum HResult
|
||||
{
|
||||
S_OK = 0,
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// See
|
||||
/// <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dn280511(v=vs.85).aspx">
|
||||
/// MONITOR_DPI_TYPE
|
||||
/// enumeration
|
||||
/// </a>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum MonitorDpiType
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
EffectiveDpi = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
AngularDpi = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
RawDpi = 2
|
||||
}
|
||||
}
|
|
@ -1,31 +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
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags for the MonitorFromRect / MonitorFromWindow "flags" field
|
||||
/// see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd145063(v=vs.85).aspx">MonitorFromRect function</a>
|
||||
/// or see <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd145064(v=vs.85).aspx">MonitorFromWindow function</a>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum MonitorFrom : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a handle to the display monitor that is nearest to the rectangle.
|
||||
/// </summary>
|
||||
DefaultToNearest = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Returns NULL. (why??)
|
||||
/// </summary>
|
||||
DefaultToNull = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Returns a handle to the primary display monitor.
|
||||
/// </summary>
|
||||
DefaultToPrimary = 2
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Greenshot.Base.Core.Enums
|
||||
{
|
||||
[Flags]
|
||||
public enum PrintWindowFlags : uint
|
||||
{
|
||||
/// <summary>Render the entire window.</summary>
|
||||
PW_ENTIREWINDOW = 0,
|
||||
|
||||
/// <summary>Only the client area of the window is copied to hdcBlt. By default, the entire window is copied.</summary>
|
||||
PW_CLIENTONLY = 1,
|
||||
|
||||
/// <summary>Undocumented</summary>
|
||||
PW_RENDERFULLCONTENT = 0x00000002,
|
||||
}
|
||||
}
|
|
@ -23,8 +23,12 @@ using System;
|
|||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Dapplo.Windows.Kernel32;
|
||||
using Dapplo.Windows.Kernel32.Enums;
|
||||
using Dapplo.Windows.Kernel32.Structs;
|
||||
using Dapplo.Windows.User32;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
|
@ -163,7 +167,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// Get some important information for fixing GDI related Problems
|
||||
environment.AppendFormat("GDI object count: {0}", User32.GetGuiResourcesGDICount());
|
||||
environment.AppendFormat("GDI object count: {0}", User32Api.GetGuiResourcesGdiCount());
|
||||
if (newline)
|
||||
{
|
||||
environment.AppendLine();
|
||||
|
@ -173,7 +177,7 @@ namespace Greenshot.Base.Core
|
|||
environment.Append(", ");
|
||||
}
|
||||
|
||||
environment.AppendFormat("User object count: {0}", User32.GetGuiResourcesUserCount());
|
||||
environment.AppendFormat("User object count: {0}", User32Api.GetGuiResourcesUserCount());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -291,33 +295,33 @@ namespace Greenshot.Base.Core
|
|||
string edition = string.Empty;
|
||||
|
||||
OperatingSystem osVersion = Environment.OSVersion;
|
||||
OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
|
||||
var osVersionInfo = OsVersionInfoEx.Create();
|
||||
|
||||
if (GetVersionEx(ref osVersionInfo))
|
||||
if (Kernel32Api.GetVersionEx(ref osVersionInfo))
|
||||
{
|
||||
int majorVersion = osVersion.Version.Major;
|
||||
int minorVersion = osVersion.Version.Minor;
|
||||
byte productType = osVersionInfo.ProductType;
|
||||
ushort suiteMask = osVersionInfo.SuiteMask;
|
||||
var productType = osVersionInfo.ProductType;
|
||||
var suiteMask = osVersionInfo.SuiteMask;
|
||||
|
||||
if (majorVersion == 4)
|
||||
{
|
||||
if (productType == VER_NT_WORKSTATION)
|
||||
if (productType == WindowsProductTypes.VER_NT_WORKSTATION)
|
||||
{
|
||||
// Windows NT 4.0 Workstation
|
||||
edition = "Workstation";
|
||||
}
|
||||
else if (productType == VER_NT_SERVER)
|
||||
else if (productType == WindowsProductTypes.VER_NT_SERVER)
|
||||
{
|
||||
edition = (suiteMask & VER_SUITE_ENTERPRISE) != 0 ? "Enterprise Server" : "Standard Server";
|
||||
edition = (suiteMask & WindowsSuites.Enterprise) != 0 ? "Enterprise Server" : "Standard Server";
|
||||
}
|
||||
}
|
||||
|
||||
else if (majorVersion == 5)
|
||||
{
|
||||
if (productType == VER_NT_WORKSTATION)
|
||||
if (productType == WindowsProductTypes.VER_NT_WORKSTATION)
|
||||
{
|
||||
if ((suiteMask & VER_SUITE_PERSONAL) != 0)
|
||||
if ((suiteMask & WindowsSuites.Personal) != 0)
|
||||
{
|
||||
// Windows XP Home Edition
|
||||
edition = "Home";
|
||||
|
@ -328,16 +332,16 @@ namespace Greenshot.Base.Core
|
|||
edition = "Professional";
|
||||
}
|
||||
}
|
||||
else if (productType == VER_NT_SERVER)
|
||||
else if (productType == WindowsProductTypes.VER_NT_SERVER)
|
||||
{
|
||||
if (minorVersion == 0)
|
||||
{
|
||||
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
|
||||
if ((suiteMask & WindowsSuites.DataCenter) != 0)
|
||||
{
|
||||
// Windows 2000 Datacenter Server
|
||||
edition = "Datacenter Server";
|
||||
}
|
||||
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
|
||||
else if ((suiteMask & WindowsSuites.Enterprise) != 0)
|
||||
{
|
||||
// Windows 2000 Advanced Server
|
||||
edition = "Advanced Server";
|
||||
|
@ -350,17 +354,17 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
else
|
||||
{
|
||||
if ((suiteMask & VER_SUITE_DATACENTER) != 0)
|
||||
if ((suiteMask & WindowsSuites.DataCenter) != 0)
|
||||
{
|
||||
// Windows Server 2003 Datacenter Edition
|
||||
edition = "Datacenter";
|
||||
}
|
||||
else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0)
|
||||
else if ((suiteMask & WindowsSuites.Enterprise) != 0)
|
||||
{
|
||||
// Windows Server 2003 Enterprise Edition
|
||||
edition = "Enterprise";
|
||||
}
|
||||
else if ((suiteMask & VER_SUITE_BLADE) != 0)
|
||||
else if ((suiteMask & WindowsSuites.Blade) != 0)
|
||||
{
|
||||
// Windows Server 2003 Web Edition
|
||||
edition = "Web Edition";
|
||||
|
@ -376,122 +380,9 @@ namespace Greenshot.Base.Core
|
|||
|
||||
else if (majorVersion == 6)
|
||||
{
|
||||
if (GetProductInfo(majorVersion, minorVersion, osVersionInfo.ServicePackMajor, osVersionInfo.ServicePackMinor, out var ed))
|
||||
if (Kernel32Api.GetProductInfo(majorVersion, minorVersion, osVersionInfo.ServicePackMajor, osVersionInfo.ServicePackMinor, out var windowsProduct))
|
||||
{
|
||||
switch (ed)
|
||||
{
|
||||
case PRODUCT_BUSINESS:
|
||||
edition = "Business";
|
||||
break;
|
||||
case PRODUCT_BUSINESS_N:
|
||||
edition = "Business N";
|
||||
break;
|
||||
case PRODUCT_CLUSTER_SERVER:
|
||||
edition = "HPC Edition";
|
||||
break;
|
||||
case PRODUCT_DATACENTER_SERVER:
|
||||
edition = "Datacenter Server";
|
||||
break;
|
||||
case PRODUCT_DATACENTER_SERVER_CORE:
|
||||
edition = "Datacenter Server (core installation)";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE:
|
||||
edition = "Enterprise";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE_N:
|
||||
edition = "Enterprise N";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE_SERVER:
|
||||
edition = "Enterprise Server";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE_SERVER_CORE:
|
||||
edition = "Enterprise Server (core installation)";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE_SERVER_CORE_V:
|
||||
edition = "Enterprise Server without Hyper-V (core installation)";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE_SERVER_IA64:
|
||||
edition = "Enterprise Server for Itanium-based Systems";
|
||||
break;
|
||||
case PRODUCT_ENTERPRISE_SERVER_V:
|
||||
edition = "Enterprise Server without Hyper-V";
|
||||
break;
|
||||
case PRODUCT_HOME_BASIC:
|
||||
edition = "Home Basic";
|
||||
break;
|
||||
case PRODUCT_HOME_BASIC_N:
|
||||
edition = "Home Basic N";
|
||||
break;
|
||||
case PRODUCT_HOME_PREMIUM:
|
||||
edition = "Home Premium";
|
||||
break;
|
||||
case PRODUCT_HOME_PREMIUM_N:
|
||||
edition = "Home Premium N";
|
||||
break;
|
||||
case PRODUCT_HYPERV:
|
||||
edition = "Microsoft Hyper-V Server";
|
||||
break;
|
||||
case PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT:
|
||||
edition = "Windows Essential Business Management Server";
|
||||
break;
|
||||
case PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING:
|
||||
edition = "Windows Essential Business Messaging Server";
|
||||
break;
|
||||
case PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY:
|
||||
edition = "Windows Essential Business Security Server";
|
||||
break;
|
||||
case PRODUCT_SERVER_FOR_SMALLBUSINESS:
|
||||
edition = "Windows Essential Server Solutions";
|
||||
break;
|
||||
case PRODUCT_SERVER_FOR_SMALLBUSINESS_V:
|
||||
edition = "Windows Essential Server Solutions without Hyper-V";
|
||||
break;
|
||||
case PRODUCT_SMALLBUSINESS_SERVER:
|
||||
edition = "Windows Small Business Server";
|
||||
break;
|
||||
case PRODUCT_STANDARD_SERVER:
|
||||
edition = "Standard Server";
|
||||
break;
|
||||
case PRODUCT_STANDARD_SERVER_CORE:
|
||||
edition = "Standard Server (core installation)";
|
||||
break;
|
||||
case PRODUCT_STANDARD_SERVER_CORE_V:
|
||||
edition = "Standard Server without Hyper-V (core installation)";
|
||||
break;
|
||||
case PRODUCT_STANDARD_SERVER_V:
|
||||
edition = "Standard Server without Hyper-V";
|
||||
break;
|
||||
case PRODUCT_STARTER:
|
||||
edition = "Starter";
|
||||
break;
|
||||
case PRODUCT_STORAGE_ENTERPRISE_SERVER:
|
||||
edition = "Enterprise Storage Server";
|
||||
break;
|
||||
case PRODUCT_STORAGE_EXPRESS_SERVER:
|
||||
edition = "Express Storage Server";
|
||||
break;
|
||||
case PRODUCT_STORAGE_STANDARD_SERVER:
|
||||
edition = "Standard Storage Server";
|
||||
break;
|
||||
case PRODUCT_STORAGE_WORKGROUP_SERVER:
|
||||
edition = "Workgroup Storage Server";
|
||||
break;
|
||||
case PRODUCT_UNDEFINED:
|
||||
edition = "Unknown product";
|
||||
break;
|
||||
case PRODUCT_ULTIMATE:
|
||||
edition = "Ultimate";
|
||||
break;
|
||||
case PRODUCT_ULTIMATE_N:
|
||||
edition = "Ultimate N";
|
||||
break;
|
||||
case PRODUCT_WEB_SERVER:
|
||||
edition = "Web Server";
|
||||
break;
|
||||
case PRODUCT_WEB_SERVER_CORE:
|
||||
edition = "Web Server (core installation)";
|
||||
break;
|
||||
}
|
||||
edition = windowsProduct.GetEnumDescription();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -518,13 +409,13 @@ namespace Greenshot.Base.Core
|
|||
string name = "unknown";
|
||||
|
||||
OperatingSystem osVersion = Environment.OSVersion;
|
||||
OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
|
||||
if (GetVersionEx(ref osVersionInfo))
|
||||
var osVersionInfo = OsVersionInfoEx.Create();
|
||||
if (Kernel32Api.GetVersionEx(ref osVersionInfo))
|
||||
{
|
||||
int majorVersion = osVersion.Version.Major;
|
||||
int minorVersion = osVersion.Version.Minor;
|
||||
byte productType = osVersionInfo.ProductType;
|
||||
ushort suiteMask = osVersionInfo.SuiteMask;
|
||||
var productType = osVersionInfo.ProductType;
|
||||
var suiteMask = osVersionInfo.SuiteMask;
|
||||
switch (osVersion.Platform)
|
||||
{
|
||||
case PlatformID.Win32Windows:
|
||||
|
@ -563,10 +454,10 @@ namespace Greenshot.Base.Core
|
|||
case 4:
|
||||
switch (productType)
|
||||
{
|
||||
case 1:
|
||||
case WindowsProductTypes.VER_NT_WORKSTATION:
|
||||
name = "Windows NT 4.0";
|
||||
break;
|
||||
case 3:
|
||||
case WindowsProductTypes.VER_NT_SERVER:
|
||||
name = "Windows NT 4.0 Server";
|
||||
break;
|
||||
}
|
||||
|
@ -581,18 +472,18 @@ namespace Greenshot.Base.Core
|
|||
case 1:
|
||||
name = suiteMask switch
|
||||
{
|
||||
0x0200 => "Windows XP Professional",
|
||||
WindowsSuites.Personal => "Windows XP Professional",
|
||||
_ => "Windows XP"
|
||||
};
|
||||
break;
|
||||
case 2:
|
||||
name = suiteMask switch
|
||||
{
|
||||
0x0200 => "Windows XP Professional x64",
|
||||
0x0002 => "Windows Server 2003 Enterprise",
|
||||
0x0080 => "Windows Server 2003 Data Center",
|
||||
0x0400 => "Windows Server 2003 Web Edition",
|
||||
0x8000 => "Windows Home Server",
|
||||
WindowsSuites.Personal => "Windows XP Professional x64",
|
||||
WindowsSuites.Enterprise => "Windows Server 2003 Enterprise",
|
||||
WindowsSuites.DataCenter => "Windows Server 2003 Data Center",
|
||||
WindowsSuites.Blade => "Windows Server 2003 Web Edition",
|
||||
WindowsSuites.WHServer => "Windows Home Server",
|
||||
_ => "Windows Server 2003"
|
||||
};
|
||||
break;
|
||||
|
@ -605,14 +496,14 @@ namespace Greenshot.Base.Core
|
|||
case 0:
|
||||
name = productType switch
|
||||
{
|
||||
3 => "Windows Server 2008",
|
||||
WindowsProductTypes.VER_NT_SERVER => "Windows Server 2008",
|
||||
_ => "Windows Vista"
|
||||
};
|
||||
break;
|
||||
case 1:
|
||||
name = productType switch
|
||||
{
|
||||
3 => "Windows Server 2008 R2",
|
||||
WindowsProductTypes.VER_NT_SERVER => "Windows Server 2008 R2",
|
||||
_ => "Windows 7"
|
||||
};
|
||||
break;
|
||||
|
@ -640,134 +531,6 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
}
|
||||
|
||||
[DllImport("Kernel32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool GetProductInfo(
|
||||
int osMajorVersion,
|
||||
int osMinorVersion,
|
||||
int spMajorVersion,
|
||||
int spMinorVersion,
|
||||
out int edition);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private unsafe struct OSVERSIONINFOEX
|
||||
{
|
||||
/// <summary>
|
||||
/// The size of this data structure, in bytes. Set this member to sizeof(OSVERSIONINFOEX).
|
||||
/// </summary>
|
||||
private int _dwOSVersionInfoSize;
|
||||
|
||||
private readonly int _dwMajorVersion;
|
||||
private readonly int _dwMinorVersion;
|
||||
private readonly int _dwBuildNumber;
|
||||
private readonly int _dwPlatformId;
|
||||
private fixed char _szCSDVersion[128];
|
||||
private readonly short _wServicePackMajor;
|
||||
private readonly short _wServicePackMinor;
|
||||
private readonly ushort _wSuiteMask;
|
||||
private readonly byte _wProductType;
|
||||
private readonly byte _wReserved;
|
||||
|
||||
/// A null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack installed on the system.
|
||||
/// If no Service Pack has been installed, the string is empty.
|
||||
/// </summary>
|
||||
public string ServicePackVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
fixed (char* servicePackVersion = _szCSDVersion)
|
||||
{
|
||||
return new string(servicePackVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The major version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the
|
||||
/// major version number is 3.
|
||||
/// If no Service Pack has been installed, the value is zero.
|
||||
/// </summary>
|
||||
public short ServicePackMajor => _wServicePackMajor;
|
||||
|
||||
/// <summary>
|
||||
/// The minor version number of the latest Service Pack installed on the system. For example, for Service Pack 3, the
|
||||
/// minor version number is 0.
|
||||
/// </summary>
|
||||
public short ServicePackMinor => _wServicePackMinor;
|
||||
|
||||
/// <summary>
|
||||
/// A bit mask that identifies the product suites available on the system. This member can be a combination of the
|
||||
/// following values.
|
||||
/// </summary>
|
||||
public ushort SuiteMask => _wSuiteMask;
|
||||
|
||||
/// <summary>
|
||||
/// Any additional information about the system.
|
||||
/// </summary>
|
||||
public byte ProductType => _wProductType;
|
||||
|
||||
/// <summary>
|
||||
/// Factory for an empty OsVersionInfoEx
|
||||
/// </summary>
|
||||
/// <returns>OSVERSIONINFOEX</returns>
|
||||
public static OSVERSIONINFOEX Create()
|
||||
{
|
||||
return new OSVERSIONINFOEX
|
||||
{
|
||||
_dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private const int PRODUCT_UNDEFINED = 0x00000000;
|
||||
private const int PRODUCT_ULTIMATE = 0x00000001;
|
||||
private const int PRODUCT_HOME_BASIC = 0x00000002;
|
||||
private const int PRODUCT_HOME_PREMIUM = 0x00000003;
|
||||
private const int PRODUCT_ENTERPRISE = 0x00000004;
|
||||
private const int PRODUCT_HOME_BASIC_N = 0x00000005;
|
||||
private const int PRODUCT_BUSINESS = 0x00000006;
|
||||
private const int PRODUCT_STANDARD_SERVER = 0x00000007;
|
||||
private const int PRODUCT_DATACENTER_SERVER = 0x00000008;
|
||||
private const int PRODUCT_SMALLBUSINESS_SERVER = 0x00000009;
|
||||
private const int PRODUCT_ENTERPRISE_SERVER = 0x0000000A;
|
||||
private const int PRODUCT_STARTER = 0x0000000B;
|
||||
private const int PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C;
|
||||
private const int PRODUCT_STANDARD_SERVER_CORE = 0x0000000D;
|
||||
private const int PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E;
|
||||
private const int PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F;
|
||||
private const int PRODUCT_BUSINESS_N = 0x00000010;
|
||||
private const int PRODUCT_WEB_SERVER = 0x00000011;
|
||||
private const int PRODUCT_CLUSTER_SERVER = 0x00000012;
|
||||
private const int PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014;
|
||||
private const int PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015;
|
||||
private const int PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016;
|
||||
private const int PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017;
|
||||
private const int PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018;
|
||||
private const int PRODUCT_HOME_PREMIUM_N = 0x0000001A;
|
||||
private const int PRODUCT_ENTERPRISE_N = 0x0000001B;
|
||||
private const int PRODUCT_ULTIMATE_N = 0x0000001C;
|
||||
private const int PRODUCT_WEB_SERVER_CORE = 0x0000001D;
|
||||
private const int PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E;
|
||||
private const int PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F;
|
||||
private const int PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020;
|
||||
private const int PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023;
|
||||
private const int PRODUCT_STANDARD_SERVER_V = 0x00000024;
|
||||
private const int PRODUCT_ENTERPRISE_SERVER_V = 0x00000026;
|
||||
private const int PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028;
|
||||
private const int PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029;
|
||||
private const int PRODUCT_HYPERV = 0x0000002A;
|
||||
|
||||
private const int VER_NT_WORKSTATION = 1;
|
||||
private const int VER_NT_SERVER = 3;
|
||||
private const int VER_SUITE_ENTERPRISE = 2;
|
||||
private const int VER_SUITE_DATACENTER = 128;
|
||||
private const int VER_SUITE_PERSONAL = 512;
|
||||
private const int VER_SUITE_BLADE = 1024;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the service pack information of the operating system running on this computer.
|
||||
/// </summary>
|
||||
|
@ -776,9 +539,9 @@ namespace Greenshot.Base.Core
|
|||
get
|
||||
{
|
||||
string servicePack = string.Empty;
|
||||
OSVERSIONINFOEX osVersionInfo = OSVERSIONINFOEX.Create();
|
||||
OsVersionInfoEx osVersionInfo = OsVersionInfoEx.Create();
|
||||
|
||||
if (GetVersionEx(ref osVersionInfo))
|
||||
if (Kernel32Api.GetVersionEx(ref osVersionInfo))
|
||||
{
|
||||
servicePack = osVersionInfo.ServicePackVersion;
|
||||
}
|
||||
|
@ -787,6 +550,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full version string of the operating system running on this computer.
|
||||
/// </summary>
|
||||
public static string VersionString
|
||||
|
|
|
@ -23,6 +23,8 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
|
@ -84,7 +86,7 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Size of the underlying image
|
||||
/// </summary>
|
||||
Size Size { get; }
|
||||
NativeSize Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Height of the image area that this fastbitmap covers
|
||||
|
@ -127,19 +129,19 @@ namespace Greenshot.Base.Core
|
|||
bool HasAlphaChannel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Draw the stored bitmap to the destionation bitmap at the supplied point
|
||||
/// Draw the stored bitmap to the destination bitmap at the supplied point
|
||||
/// </summary>
|
||||
/// <param name="graphics">Graphics</param>
|
||||
/// <param name="destination">Point with location</param>
|
||||
void DrawTo(Graphics graphics, Point destination);
|
||||
/// <param name="destination">NativePoint with location</param>
|
||||
void DrawTo(Graphics graphics, NativePoint destination);
|
||||
|
||||
/// <summary>
|
||||
/// Draw the stored Bitmap on the Destination bitmap with the specified rectangle
|
||||
/// Be aware that the stored bitmap will be resized to the specified rectangle!!
|
||||
/// </summary>
|
||||
/// <param name="graphics">Graphics</param>
|
||||
/// <param name="destinationRect">Rectangle with destination</param>
|
||||
void DrawTo(Graphics graphics, Rectangle destinationRect);
|
||||
/// <param name="destinationRect">NativeRect with destination</param>
|
||||
void DrawTo(Graphics graphics, NativeRect destinationRect);
|
||||
|
||||
/// <summary>
|
||||
/// Return true if the coordinates are inside the FastBitmap
|
||||
|
@ -214,7 +216,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public interface IFastBitmapWithClip : IFastBitmap
|
||||
{
|
||||
Rectangle Clip { get; set; }
|
||||
NativeRect Clip { get; set; }
|
||||
|
||||
bool InvertClip { get; set; }
|
||||
|
||||
|
@ -267,14 +269,14 @@ namespace Greenshot.Base.Core
|
|||
public const int ColorIndexB = 2;
|
||||
public const int ColorIndexA = 3;
|
||||
|
||||
protected Rectangle Area;
|
||||
protected NativeRect Area;
|
||||
|
||||
/// <summary>
|
||||
/// If this is set to true, the bitmap will be disposed when disposing the IFastBitmap
|
||||
/// </summary>
|
||||
public bool NeedsDispose { get; set; }
|
||||
|
||||
public Rectangle Clip { get; set; }
|
||||
public NativeRect Clip { get; set; }
|
||||
|
||||
public bool InvertClip { get; set; }
|
||||
|
||||
|
@ -290,7 +292,7 @@ namespace Greenshot.Base.Core
|
|||
|
||||
public static IFastBitmap Create(Bitmap source)
|
||||
{
|
||||
return Create(source, Rectangle.Empty);
|
||||
return Create(source, NativeRect.Empty);
|
||||
}
|
||||
|
||||
public void SetResolution(float horizontal, float vertical)
|
||||
|
@ -303,44 +305,37 @@ namespace Greenshot.Base.Core
|
|||
/// The supplied rectangle specifies the area for which the FastBitmap does its thing
|
||||
/// </summary>
|
||||
/// <param name="source">Bitmap to access</param>
|
||||
/// <param name="area">Rectangle which specifies the area to have access to, can be Rectangle.Empty for the whole image</param>
|
||||
/// <param name="area">NativeRect which specifies the area to have access to, can be NativeRect.Empty for the whole image</param>
|
||||
/// <returns>IFastBitmap</returns>
|
||||
public static IFastBitmap Create(Bitmap source, Rectangle area)
|
||||
{
|
||||
switch (source.PixelFormat)
|
||||
public static IFastBitmap Create(Bitmap source, NativeRect area) =>
|
||||
source.PixelFormat switch
|
||||
{
|
||||
case PixelFormat.Format8bppIndexed:
|
||||
return new FastChunkyBitmap(source, area);
|
||||
case PixelFormat.Format24bppRgb:
|
||||
return new Fast24RgbBitmap(source, area);
|
||||
case PixelFormat.Format32bppRgb:
|
||||
return new Fast32RgbBitmap(source, area);
|
||||
case PixelFormat.Format32bppArgb:
|
||||
case PixelFormat.Format32bppPArgb:
|
||||
return new Fast32ArgbBitmap(source, area);
|
||||
default:
|
||||
throw new NotSupportedException($"Not supported Pixelformat {source.PixelFormat}");
|
||||
}
|
||||
}
|
||||
PixelFormat.Format8bppIndexed => new FastChunkyBitmap(source, area),
|
||||
PixelFormat.Format24bppRgb => new Fast24RgbBitmap(source, area),
|
||||
PixelFormat.Format32bppRgb => new Fast32RgbBitmap(source, area),
|
||||
PixelFormat.Format32bppArgb => new Fast32ArgbBitmap(source, area),
|
||||
PixelFormat.Format32bppPArgb => new Fast32ArgbBitmap(source, area),
|
||||
_ => throw new NotSupportedException($"Not supported PixelFormat {source.PixelFormat}")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Factory for creating a FastBitmap as a destination for the source
|
||||
/// </summary>
|
||||
/// <param name="source">Bitmap to clone</param>
|
||||
/// <param name="pixelFormat">new Pixelformat</param>
|
||||
/// <param name="pixelFormat">new PixelFormat</param>
|
||||
/// <returns>IFastBitmap</returns>
|
||||
public static IFastBitmap CreateCloneOf(Image source, PixelFormat pixelFormat)
|
||||
{
|
||||
return CreateCloneOf(source, pixelFormat, Rectangle.Empty);
|
||||
return CreateCloneOf(source, pixelFormat, NativeRect.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Factory for creating a FastBitmap as a destination for the source
|
||||
/// </summary>
|
||||
/// <param name="source">Bitmap to clone</param>
|
||||
/// <param name="area">Area of the bitmap to access, can be Rectangle.Empty for the whole</param>
|
||||
/// <param name="area">Area of the bitmap to access, can be NativeRect.Empty for the whole</param>
|
||||
/// <returns>IFastBitmap</returns>
|
||||
public static IFastBitmap CreateCloneOf(Image source, Rectangle area)
|
||||
public static IFastBitmap CreateCloneOf(Image source, NativeRect area)
|
||||
{
|
||||
return CreateCloneOf(source, PixelFormat.DontCare, area);
|
||||
}
|
||||
|
@ -350,9 +345,9 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="source">Bitmap to clone</param>
|
||||
/// <param name="pixelFormat">Pixelformat of the cloned bitmap</param>
|
||||
/// <param name="area">Area of the bitmap to access, can be Rectangle.Empty for the whole</param>
|
||||
/// <param name="area">Area of the bitmap to access, can be NativeRect.Empty for the whole</param>
|
||||
/// <returns>IFastBitmap</returns>
|
||||
public static IFastBitmap CreateCloneOf(Image source, PixelFormat pixelFormat, Rectangle area)
|
||||
public static IFastBitmap CreateCloneOf(Image source, PixelFormat pixelFormat, NativeRect area)
|
||||
{
|
||||
Bitmap destination = ImageHelper.CloneArea(source, area, pixelFormat);
|
||||
FastBitmap fastBitmap = Create(destination) as FastBitmap;
|
||||
|
@ -369,11 +364,11 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Factory for creating a FastBitmap as a destination
|
||||
/// </summary>
|
||||
/// <param name="newSize"></param>
|
||||
/// <param name="pixelFormat"></param>
|
||||
/// <param name="backgroundColor"></param>
|
||||
/// <param name="newSize">NativeSize</param>
|
||||
/// <param name="pixelFormat">PixelFormat</param>
|
||||
/// <param name="backgroundColor">Color</param>
|
||||
/// <returns>IFastBitmap</returns>
|
||||
public static IFastBitmap CreateEmpty(Size newSize, PixelFormat pixelFormat, Color backgroundColor)
|
||||
public static IFastBitmap CreateEmpty(NativeSize newSize, PixelFormat pixelFormat, Color backgroundColor)
|
||||
{
|
||||
Bitmap destination = ImageHelper.CreateEmpty(newSize.Width, newSize.Height, pixelFormat, backgroundColor, 96f, 96f);
|
||||
IFastBitmap fastBitmap = Create(destination);
|
||||
|
@ -385,14 +380,14 @@ namespace Greenshot.Base.Core
|
|||
/// Constructor which stores the image and locks it when called
|
||||
/// </summary>
|
||||
/// <param name="bitmap">Bitmap</param>
|
||||
/// <param name="area">Rectangle</param>
|
||||
protected FastBitmap(Bitmap bitmap, Rectangle area)
|
||||
/// <param name="area">NativeRect</param>
|
||||
protected FastBitmap(Bitmap bitmap, NativeRect area)
|
||||
{
|
||||
Bitmap = bitmap;
|
||||
Rectangle bitmapArea = new Rectangle(Point.Empty, bitmap.Size);
|
||||
if (area != Rectangle.Empty)
|
||||
var bitmapArea = new NativeRect(NativePoint.Empty, bitmap.Size);
|
||||
if (area != NativeRect.Empty)
|
||||
{
|
||||
area.Intersect(bitmapArea);
|
||||
area = area.Intersect(bitmapArea);
|
||||
Area = area;
|
||||
}
|
||||
else
|
||||
|
@ -413,11 +408,11 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Return the size of the image
|
||||
/// </summary>
|
||||
public Size Size
|
||||
public NativeSize Size
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Area == Rectangle.Empty)
|
||||
if (Area == NativeRect.Empty)
|
||||
{
|
||||
return Bitmap.Size;
|
||||
}
|
||||
|
@ -433,7 +428,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
get
|
||||
{
|
||||
if (Area == Rectangle.Empty)
|
||||
if (Area == NativeRect.Empty)
|
||||
{
|
||||
return Bitmap.Width;
|
||||
}
|
||||
|
@ -449,7 +444,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
get
|
||||
{
|
||||
if (Area == Rectangle.Empty)
|
||||
if (Area == NativeRect.Empty)
|
||||
{
|
||||
return Bitmap.Height;
|
||||
}
|
||||
|
@ -596,13 +591,13 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the stored bitmap to the destionation bitmap at the supplied point
|
||||
/// Draw the stored bitmap to the destination bitmap at the supplied point
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="destination"></param>
|
||||
public void DrawTo(Graphics graphics, Point destination)
|
||||
public void DrawTo(Graphics graphics, NativePoint destination)
|
||||
{
|
||||
DrawTo(graphics, new Rectangle(destination, Area.Size));
|
||||
DrawTo(graphics, new NativeRect(destination, Area.Size));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -610,8 +605,8 @@ namespace Greenshot.Base.Core
|
|||
/// Be aware that the stored bitmap will be resized to the specified rectangle!!
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="destinationRect"></param>
|
||||
public void DrawTo(Graphics graphics, Rectangle destinationRect)
|
||||
/// <param name="destinationRect">NativeRect</param>
|
||||
public void DrawTo(Graphics graphics, NativeRect destinationRect)
|
||||
{
|
||||
// Make sure this.bitmap is unlocked, if it was locked
|
||||
bool isLocked = BitsLocked;
|
||||
|
@ -715,7 +710,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is the implementation of the FastBitmat for the 8BPP pixelformat
|
||||
/// This is the implementation of the FastBitmap for the 8BPP pixelformat
|
||||
/// </summary>
|
||||
public unsafe class FastChunkyBitmap : FastBitmap
|
||||
{
|
||||
|
@ -723,7 +718,7 @@ namespace Greenshot.Base.Core
|
|||
private readonly Color[] _colorEntries;
|
||||
private readonly Dictionary<Color, byte> _colorCache = new Dictionary<Color, byte>();
|
||||
|
||||
public FastChunkyBitmap(Bitmap source, Rectangle area) : base(source, area)
|
||||
public FastChunkyBitmap(Bitmap source, NativeRect area) : base(source, area)
|
||||
{
|
||||
_colorEntries = Bitmap.Palette.Entries;
|
||||
}
|
||||
|
@ -825,7 +820,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public unsafe class Fast24RgbBitmap : FastBitmap
|
||||
{
|
||||
public Fast24RgbBitmap(Bitmap source, Rectangle area) : base(source, area)
|
||||
public Fast24RgbBitmap(Bitmap source, NativeRect area) : base(source, area)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -891,7 +886,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public unsafe class Fast32RgbBitmap : FastBitmap
|
||||
{
|
||||
public Fast32RgbBitmap(Bitmap source, Rectangle area) : base(source, area)
|
||||
public Fast32RgbBitmap(Bitmap source, NativeRect area) : base(source, area)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -961,7 +956,7 @@ namespace Greenshot.Base.Core
|
|||
|
||||
public Color BackgroundBlendColor { get; set; }
|
||||
|
||||
public Fast32ArgbBitmap(Bitmap source, Rectangle area) : base(source, area)
|
||||
public Fast32ArgbBitmap(Bitmap source, NativeRect area) : base(source, area)
|
||||
{
|
||||
BackgroundBlendColor = Color.White;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
|
@ -30,8 +30,8 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
public FileDescriptorFlags Flags { get; set; }
|
||||
public Guid ClassId { get; set; }
|
||||
public SIZE Size { get; set; }
|
||||
public POINT Point { get; set; }
|
||||
public NativeSize Size { get; set; }
|
||||
public NativePoint Point { get; set; }
|
||||
public FileAttributes FileAttributes { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
public DateTime LastAccessTime { get; set; }
|
||||
|
@ -46,9 +46,9 @@ namespace Greenshot.Base.Core
|
|||
//ClassID
|
||||
ClassId = new Guid(reader.ReadBytes(16));
|
||||
//Size
|
||||
Size = new SIZE(reader.ReadInt32(), reader.ReadInt32());
|
||||
Size = new NativeSize(reader.ReadInt32(), reader.ReadInt32());
|
||||
//Point
|
||||
Point = new POINT(reader.ReadInt32(), reader.ReadInt32());
|
||||
Point = new NativePoint(reader.ReadInt32(), reader.ReadInt32());
|
||||
//FileAttributes
|
||||
FileAttributes = (FileAttributes)reader.ReadUInt32();
|
||||
//CreationTime
|
||||
|
|
|
@ -1,52 +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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
using System.Diagnostics.Contracts;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions to handle the HResult
|
||||
/// </summary>
|
||||
public static class HResultExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Test if the HResult represents a fail
|
||||
/// </summary>
|
||||
/// <param name="hResult">HResult</param>
|
||||
/// <returns>bool</returns>
|
||||
[Pure]
|
||||
public static bool Failed(this HResult hResult)
|
||||
{
|
||||
return hResult < 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the HResult represents a success
|
||||
/// </summary>
|
||||
/// <param name="hResult">HResult</param>
|
||||
/// <returns>bool</returns>
|
||||
[Pure]
|
||||
public static bool Succeeded(this HResult hResult)
|
||||
{
|
||||
return hResult >= HResult.S_OK;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,18 +27,18 @@ using System.Drawing.Imaging;
|
|||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.Gdi32;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.Effects;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using log4net;
|
||||
using Brush = System.Drawing.Brush;
|
||||
using Color = System.Drawing.Color;
|
||||
using Matrix = System.Drawing.Drawing2D.Matrix;
|
||||
using Pen = System.Drawing.Pen;
|
||||
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||
using Point = System.Drawing.Point;
|
||||
using Size = System.Drawing.Size;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
|
@ -157,7 +157,7 @@ namespace Greenshot.Base.Core
|
|||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
Rectangle rectDestination = new Rectangle(0, 0, thumbWidth, thumbHeight);
|
||||
NativeRect rectDestination = new NativeRect(0, 0, thumbWidth, thumbHeight);
|
||||
graphics.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
|
@ -165,18 +165,18 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Crops the image to the specified rectangle
|
||||
/// Crops the image to the specified NativeRect
|
||||
/// </summary>
|
||||
/// <param name="image">Image to crop</param>
|
||||
/// <param name="cropRectangle">Rectangle with bitmap coordinates, will be "intersected" to the bitmap</param>
|
||||
public static bool Crop(ref Image image, ref Rectangle cropRectangle)
|
||||
/// <param name="cropNativeRect">NativeRect with bitmap coordinates, will be "intersected" to the bitmap</param>
|
||||
public static bool Crop(ref Image image, ref NativeRect cropNativeRect)
|
||||
{
|
||||
if (image is Bitmap && (image.Width * image.Height > 0))
|
||||
{
|
||||
cropRectangle.Intersect(new Rectangle(0, 0, image.Width, image.Height));
|
||||
if (cropRectangle.Width != 0 || cropRectangle.Height != 0)
|
||||
cropNativeRect = cropNativeRect.Intersect(new NativeRect(0, 0, image.Width, image.Height));
|
||||
if (cropNativeRect.Width != 0 || cropNativeRect.Height != 0)
|
||||
{
|
||||
Image returnImage = CloneArea(image, cropRectangle, PixelFormat.DontCare);
|
||||
Image returnImage = CloneArea(image, cropNativeRect, PixelFormat.DontCare);
|
||||
image.Dispose();
|
||||
image = returnImage;
|
||||
return true;
|
||||
|
@ -188,20 +188,20 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private helper method for the FindAutoCropRectangle
|
||||
/// Private helper method for the FindAutoCropNativeRect
|
||||
/// </summary>
|
||||
/// <param name="fastBitmap">IFastBitmap</param>
|
||||
/// <param name="colorPoint">Point</param>
|
||||
/// <param name="colorPoint">NativePoint</param>
|
||||
/// <param name="cropDifference">int</param>
|
||||
/// <param name="area">Rectangle with optional area to scan in</param>
|
||||
/// <returns>Rectangle</returns>
|
||||
private static Rectangle FindAutoCropRectangle(IFastBitmap fastBitmap, Point colorPoint, int cropDifference, Rectangle? area = null)
|
||||
/// <param name="area">NativeRect with optional area to scan in</param>
|
||||
/// <returns>NativeRect</returns>
|
||||
private static NativeRect FindAutoCropNativeRect(IFastBitmap fastBitmap, NativePoint colorPoint, int cropDifference, NativeRect? area = null)
|
||||
{
|
||||
area ??= new Rectangle(0, 0, fastBitmap.Width, fastBitmap.Height);
|
||||
Rectangle cropRectangle = Rectangle.Empty;
|
||||
area ??= new NativeRect(0, 0, fastBitmap.Width, fastBitmap.Height);
|
||||
NativeRect cropNativeRect = NativeRect.Empty;
|
||||
Color referenceColor = fastBitmap.GetColorAt(colorPoint.X, colorPoint.Y);
|
||||
Point min = new Point(int.MaxValue, int.MaxValue);
|
||||
Point max = new Point(int.MinValue, int.MinValue);
|
||||
NativePoint min = new NativePoint(int.MaxValue, int.MaxValue);
|
||||
NativePoint max = new NativePoint(int.MinValue, int.MinValue);
|
||||
|
||||
if (cropDifference > 0)
|
||||
{
|
||||
|
@ -218,10 +218,10 @@ namespace Greenshot.Base.Core
|
|||
continue;
|
||||
}
|
||||
|
||||
if (x < min.X) min.X = x;
|
||||
if (y < min.Y) min.Y = y;
|
||||
if (x > max.X) max.X = x;
|
||||
if (y > max.Y) max.Y = y;
|
||||
if (x < min.X) min = min.ChangeX(x);
|
||||
if (y < min.Y) min = min.ChangeY(y);
|
||||
if (x > max.X) max = max.ChangeX(x);
|
||||
if (y > max.Y) max = max.ChangeY(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,43 +237,44 @@ namespace Greenshot.Base.Core
|
|||
continue;
|
||||
}
|
||||
|
||||
if (x < min.X) min.X = x;
|
||||
if (y < min.Y) min.Y = y;
|
||||
if (x > max.X) max.X = x;
|
||||
if (y > max.Y) max.Y = y;
|
||||
if (x < min.X) min = min.ChangeX(x);
|
||||
if (y < min.Y) min = min.ChangeY(y);
|
||||
if (x > max.X) max = max.ChangeX(x);
|
||||
if (y > max.Y) max = max.ChangeY(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(Point.Empty.Equals(min) && max.Equals(new Point(area.Value.Width - 1, area.Value.Height - 1))))
|
||||
if (!(NativePoint.Empty.Equals(min) && max.Equals(new NativePoint(area.Value.Width - 1, area.Value.Height - 1))))
|
||||
{
|
||||
if (!(min.X == int.MaxValue || min.Y == int.MaxValue || max.X == int.MinValue || min.X == int.MinValue))
|
||||
{
|
||||
cropRectangle = new Rectangle(min.X, min.Y, max.X - min.X + 1, max.Y - min.Y + 1);
|
||||
cropNativeRect = new NativeRect(min.X, min.Y, max.X - min.X + 1, max.Y - min.Y + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return cropRectangle;
|
||||
return cropNativeRect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a rectangle for the image which crops the image of all colors equal to that on 0,0
|
||||
/// Get a NativeRect for the image which crops the image of all colors equal to that on 0,0
|
||||
/// </summary>
|
||||
/// <param name="image">Image</param>
|
||||
/// <param name="cropDifference">int</param>
|
||||
/// <param name="area">Rectangle with optional area</param>
|
||||
/// <returns>Rectangle</returns>
|
||||
public static Rectangle FindAutoCropRectangle(Image image, int cropDifference, Rectangle? area = null)
|
||||
/// <param name="area">NativeRect with optional area</param>
|
||||
/// <returns>NativeRect</returns>
|
||||
public static NativeRect FindAutoCropRectangle(Image image, int cropDifference, NativeRect? area = null)
|
||||
{
|
||||
area ??= new Rectangle(0, 0, image.Width, image.Height);
|
||||
Rectangle cropRectangle = Rectangle.Empty;
|
||||
var checkPoints = new List<Point>
|
||||
area ??= new NativeRect(0, 0, image.Width, image.Height);
|
||||
NativeRect cropNativeRect = NativeRect.Empty;
|
||||
var checkPoints = new List<NativePoint>
|
||||
{
|
||||
new Point(area.Value.Left, area.Value.Top),
|
||||
new Point(area.Value.Left, area.Value.Bottom - 1),
|
||||
new Point(area.Value.Right - 1, area.Value.Top),
|
||||
new Point(area.Value.Right - 1, area.Value.Bottom - 1)
|
||||
new(area.Value.Left, area.Value.Top),
|
||||
new(area.Value.Left, area.Value.Bottom - 1),
|
||||
new(area.Value.Right - 1, area.Value.Top),
|
||||
new(area.Value.Right - 1, area.Value.Bottom - 1)
|
||||
};
|
||||
|
||||
// Top Left
|
||||
// Bottom Left
|
||||
// Top Right
|
||||
|
@ -281,17 +282,17 @@ namespace Greenshot.Base.Core
|
|||
using (IFastBitmap fastBitmap = FastBitmap.Create((Bitmap) image))
|
||||
{
|
||||
// find biggest area
|
||||
foreach (Point checkPoint in checkPoints)
|
||||
foreach (var checkPoint in checkPoints)
|
||||
{
|
||||
var currentRectangle = FindAutoCropRectangle(fastBitmap, checkPoint, cropDifference, area);
|
||||
if (currentRectangle.Width * currentRectangle.Height > cropRectangle.Width * cropRectangle.Height)
|
||||
var currentNativeRect = FindAutoCropNativeRect(fastBitmap, checkPoint, cropDifference, area);
|
||||
if (currentNativeRect.Width * currentNativeRect.Height > cropNativeRect.Width * cropNativeRect.Height)
|
||||
{
|
||||
cropRectangle = currentRectangle;
|
||||
cropNativeRect = currentNativeRect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cropRectangle;
|
||||
return cropNativeRect;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -345,7 +346,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="path">Path to draw to</param>
|
||||
/// <param name="points">Points for the lines to draw</param>
|
||||
private static void DrawLines(GraphicsPath path, List<Point> points)
|
||||
private static void DrawLines(GraphicsPath path, List<NativePoint> points)
|
||||
{
|
||||
path.AddLine(points[0], points[1]);
|
||||
for (int i = 0; i < points.Count - 1; i++)
|
||||
|
@ -372,12 +373,12 @@ namespace Greenshot.Base.Core
|
|||
int horizontalRegions = (int) Math.Round((float) sourceImage.Width / horizontalToothRange);
|
||||
int verticalRegions = (int) Math.Round((float) sourceImage.Height / verticalToothRange);
|
||||
|
||||
Point topLeft = new Point(0, 0);
|
||||
Point topRight = new Point(sourceImage.Width, 0);
|
||||
Point bottomLeft = new Point(0, sourceImage.Height);
|
||||
Point bottomRight = new Point(sourceImage.Width, sourceImage.Height);
|
||||
var topLeft = new NativePoint(0, 0);
|
||||
var topRight = new NativePoint(sourceImage.Width, 0);
|
||||
var bottomLeft = new NativePoint(0, sourceImage.Height);
|
||||
var bottomRight = new NativePoint(sourceImage.Width, sourceImage.Height);
|
||||
|
||||
List<Point> points = new List<Point>();
|
||||
var points = new List<NativePoint>();
|
||||
|
||||
if (edges[0])
|
||||
{
|
||||
|
@ -388,15 +389,15 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
else
|
||||
{
|
||||
points.Add(new Point(random.Next(1, toothHeight), random.Next(1, toothHeight)));
|
||||
points.Add(new NativePoint(random.Next(1, toothHeight), random.Next(1, toothHeight)));
|
||||
}
|
||||
|
||||
for (int i = 1; i < horizontalRegions - 1; i++)
|
||||
{
|
||||
points.Add(new Point(i * horizontalToothRange, random.Next(1, toothHeight)));
|
||||
points.Add(new NativePoint(i * horizontalToothRange, random.Next(1, toothHeight)));
|
||||
}
|
||||
|
||||
points.Add(new Point(sourceImage.Width - random.Next(1, toothHeight), random.Next(1, toothHeight)));
|
||||
points.Add(new NativePoint(sourceImage.Width - random.Next(1, toothHeight), random.Next(1, toothHeight)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -410,10 +411,10 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
for (int i = 1; i < verticalRegions - 1; i++)
|
||||
{
|
||||
points.Add(new Point(sourceImage.Width - random.Next(1, toothHeight), i * verticalToothRange));
|
||||
points.Add(new NativePoint(sourceImage.Width - random.Next(1, toothHeight), i * verticalToothRange));
|
||||
}
|
||||
|
||||
points.Add(new Point(sourceImage.Width - random.Next(1, toothHeight), sourceImage.Height - random.Next(1, toothHeight)));
|
||||
points.Add(new NativePoint(sourceImage.Width - random.Next(1, toothHeight), sourceImage.Height - random.Next(1, toothHeight)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -428,10 +429,10 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
for (int i = 1; i < horizontalRegions - 1; i++)
|
||||
{
|
||||
points.Add(new Point(sourceImage.Width - i * horizontalToothRange, sourceImage.Height - random.Next(1, toothHeight)));
|
||||
points.Add(new NativePoint(sourceImage.Width - i * horizontalToothRange, sourceImage.Height - random.Next(1, toothHeight)));
|
||||
}
|
||||
|
||||
points.Add(new Point(random.Next(1, toothHeight), sourceImage.Height - random.Next(1, toothHeight)));
|
||||
points.Add(new NativePoint(random.Next(1, toothHeight), sourceImage.Height - random.Next(1, toothHeight)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -447,7 +448,7 @@ namespace Greenshot.Base.Core
|
|||
// One fewer as the end point is the starting point
|
||||
for (int i = 1; i < verticalRegions - 1; i++)
|
||||
{
|
||||
points.Add(new Point(random.Next(1, toothHeight), points[points.Count - 1].Y - verticalToothRange));
|
||||
points.Add(new NativePoint(random.Next(1, toothHeight), points[points.Count - 1].Y - verticalToothRange));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -768,19 +769,18 @@ namespace Greenshot.Base.Core
|
|||
/// <param name="applySize"></param>
|
||||
/// <param name="rect"></param>
|
||||
/// <param name="invert"></param>
|
||||
/// <returns></returns>
|
||||
public static Rectangle CreateIntersectRectangle(Size applySize, Rectangle rect, bool invert)
|
||||
/// <returns>NativeRect</returns>
|
||||
public static NativeRect CreateIntersectRectangle(NativeSize applySize, NativeRect rect, bool invert)
|
||||
{
|
||||
Rectangle myRect;
|
||||
NativeRect myRect;
|
||||
if (invert)
|
||||
{
|
||||
myRect = new Rectangle(0, 0, applySize.Width, applySize.Height);
|
||||
myRect = new NativeRect(0, 0, applySize.Width, applySize.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
Rectangle applyRect = new Rectangle(0, 0, applySize.Width, applySize.Height);
|
||||
myRect = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
|
||||
myRect.Intersect(applyRect);
|
||||
NativeRect applyRect = new NativeRect(0, 0, applySize.Width, applySize.Height);
|
||||
myRect = new NativeRect(rect.X, rect.Y, rect.Width, rect.Height).Intersect(applyRect);
|
||||
}
|
||||
|
||||
return myRect;
|
||||
|
@ -796,11 +796,9 @@ namespace Greenshot.Base.Core
|
|||
/// <param name="shadowOffset"></param>
|
||||
/// <param name="matrix">The transform matrix which describes how the elements need to be transformed to stay at the same location</param>
|
||||
/// <returns>Bitmap with the shadow, is bigger than the sourceBitmap!!</returns>
|
||||
public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, Point shadowOffset, Matrix matrix, PixelFormat targetPixelformat)
|
||||
public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, NativePoint shadowOffset, Matrix matrix, PixelFormat targetPixelformat)
|
||||
{
|
||||
Point offset = shadowOffset;
|
||||
offset.X += shadowSize - 1;
|
||||
offset.Y += shadowSize - 1;
|
||||
NativePoint offset = shadowOffset.Offset(shadowSize - 1, shadowSize - 1);
|
||||
matrix.Translate(offset.X, offset.Y, MatrixOrder.Append);
|
||||
// Create a new "clean" image
|
||||
Bitmap returnImage = CreateEmpty(sourceBitmap.Width + shadowSize * 2, sourceBitmap.Height + shadowSize * 2, targetPixelformat, Color.Empty,
|
||||
|
@ -811,7 +809,7 @@ namespace Greenshot.Base.Core
|
|||
shadowSize++;
|
||||
}
|
||||
|
||||
bool useGdiBlur = GDIplus.IsBlurPossible(shadowSize);
|
||||
bool useGdiBlur = GdiPlusApi.IsBlurPossible(shadowSize);
|
||||
// Create "mask" for the shadow
|
||||
ColorMatrix maskMatrix = new ColorMatrix
|
||||
{
|
||||
|
@ -828,20 +826,20 @@ namespace Greenshot.Base.Core
|
|||
maskMatrix.Matrix33 = darkness;
|
||||
}
|
||||
|
||||
Rectangle shadowRectangle = new Rectangle(new Point(shadowSize, shadowSize), sourceBitmap.Size);
|
||||
ApplyColorMatrix((Bitmap) sourceBitmap, Rectangle.Empty, returnImage, shadowRectangle, maskMatrix);
|
||||
NativeRect shadowNativeRect = new NativeRect(new NativePoint(shadowSize, shadowSize), sourceBitmap.Size);
|
||||
ApplyColorMatrix((Bitmap) sourceBitmap, NativeRect.Empty, returnImage, shadowNativeRect, maskMatrix);
|
||||
|
||||
// blur "shadow", apply to whole new image
|
||||
if (useGdiBlur)
|
||||
{
|
||||
// Use GDI Blur
|
||||
Rectangle newImageRectangle = new Rectangle(0, 0, returnImage.Width, returnImage.Height);
|
||||
GDIplus.ApplyBlur(returnImage, newImageRectangle, shadowSize + 1, false);
|
||||
NativeRect newImageNativeRect = new NativeRect(0, 0, returnImage.Width, returnImage.Height);
|
||||
GdiPlusApi.ApplyBlur(returnImage, newImageNativeRect, shadowSize + 1, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// try normal software blur
|
||||
//returnImage = CreateBlur(returnImage, newImageRectangle, true, shadowSize, 1d, false, newImageRectangle);
|
||||
//returnImage = CreateBlur(returnImage, newImageNativeRect, true, shadowSize, 1d, false, newImageNativeRect);
|
||||
ApplyBoxBlur(returnImage, shadowSize);
|
||||
}
|
||||
|
||||
|
@ -905,18 +903,18 @@ namespace Greenshot.Base.Core
|
|||
/// <param name="colorMatrix">ColorMatrix to apply</param>
|
||||
public static void ApplyColorMatrix(Bitmap source, ColorMatrix colorMatrix)
|
||||
{
|
||||
ApplyColorMatrix(source, Rectangle.Empty, source, Rectangle.Empty, colorMatrix);
|
||||
ApplyColorMatrix(source, NativeRect.Empty, source, NativeRect.Empty, colorMatrix);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply a color matrix by copying from the source to the destination
|
||||
/// </summary>
|
||||
/// <param name="source">Image to copy from</param>
|
||||
/// <param name="sourceRect">Rectangle to copy from</param>
|
||||
/// <param name="destRect">Rectangle to copy to</param>
|
||||
/// <param name="sourceRect">NativeRect to copy from</param>
|
||||
/// <param name="destRect">NativeRect to copy to</param>
|
||||
/// <param name="dest">Image to copy to</param>
|
||||
/// <param name="colorMatrix">ColorMatrix to apply</param>
|
||||
public static void ApplyColorMatrix(Bitmap source, Rectangle sourceRect, Bitmap dest, Rectangle destRect, ColorMatrix colorMatrix)
|
||||
public static void ApplyColorMatrix(Bitmap source, NativeRect sourceRect, Bitmap dest, NativeRect destRect, ColorMatrix colorMatrix)
|
||||
{
|
||||
using ImageAttributes imageAttributes = new ImageAttributes();
|
||||
imageAttributes.ClearColorMatrix();
|
||||
|
@ -928,15 +926,15 @@ namespace Greenshot.Base.Core
|
|||
/// Apply a color matrix by copying from the source to the destination
|
||||
/// </summary>
|
||||
/// <param name="source">Image to copy from</param>
|
||||
/// <param name="sourceRect">Rectangle to copy from</param>
|
||||
/// <param name="destRect">Rectangle to copy to</param>
|
||||
/// <param name="sourceRect">NativeRect to copy from</param>
|
||||
/// <param name="destRect">NativeRect to copy to</param>
|
||||
/// <param name="dest">Image to copy to</param>
|
||||
/// <param name="imageAttributes">ImageAttributes to apply</param>
|
||||
public static void ApplyImageAttributes(Bitmap source, Rectangle sourceRect, Bitmap dest, Rectangle destRect, ImageAttributes imageAttributes)
|
||||
public static void ApplyImageAttributes(Bitmap source, NativeRect sourceRect, Bitmap dest, NativeRect destRect, ImageAttributes imageAttributes)
|
||||
{
|
||||
if (sourceRect == Rectangle.Empty)
|
||||
if (sourceRect == NativeRect.Empty)
|
||||
{
|
||||
sourceRect = new Rectangle(0, 0, source.Width, source.Height);
|
||||
sourceRect = new NativeRect(0, 0, source.Width, source.Height);
|
||||
}
|
||||
|
||||
if (dest == null)
|
||||
|
@ -944,9 +942,9 @@ namespace Greenshot.Base.Core
|
|||
dest = source;
|
||||
}
|
||||
|
||||
if (destRect == Rectangle.Empty)
|
||||
if (destRect == NativeRect.Empty)
|
||||
{
|
||||
destRect = new Rectangle(0, 0, dest.Width, dest.Height);
|
||||
destRect = new NativeRect(0, 0, dest.Width, dest.Height);
|
||||
}
|
||||
|
||||
using Graphics graphics = Graphics.FromImage(dest);
|
||||
|
@ -995,7 +993,7 @@ namespace Greenshot.Base.Core
|
|||
public static Image CreateBorder(Image sourceImage, int borderSize, Color borderColor, PixelFormat targetPixelformat, Matrix matrix)
|
||||
{
|
||||
// "return" the shifted offset, so the caller can e.g. move elements
|
||||
Point offset = new Point(borderSize, borderSize);
|
||||
NativePoint offset = new NativePoint(borderSize, borderSize);
|
||||
matrix.Translate(offset.X, offset.Y, MatrixOrder.Append);
|
||||
|
||||
// Create a new "clean" image
|
||||
|
@ -1010,7 +1008,7 @@ namespace Greenshot.Base.Core
|
|||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
using (GraphicsPath path = new GraphicsPath())
|
||||
{
|
||||
path.AddRectangle(new Rectangle(borderSize >> 1, borderSize >> 1, newImage.Width - borderSize, newImage.Height - borderSize));
|
||||
path.AddRectangle(new NativeRect(borderSize >> 1, borderSize >> 1, newImage.Width - borderSize, newImage.Height - borderSize));
|
||||
using Pen pen = new Pen(borderColor, borderSize)
|
||||
{
|
||||
LineJoin = LineJoin.Round,
|
||||
|
@ -1090,7 +1088,7 @@ namespace Greenshot.Base.Core
|
|||
sourceImage.VerticalResolution);
|
||||
using (ImageAttributes adjustAttributes = CreateAdjustAttributes(brightness, contrast, gamma))
|
||||
{
|
||||
ApplyImageAttributes((Bitmap) sourceImage, Rectangle.Empty, newBitmap, Rectangle.Empty, adjustAttributes);
|
||||
ApplyImageAttributes((Bitmap) sourceImage, NativeRect.Empty, newBitmap, NativeRect.Empty, adjustAttributes);
|
||||
}
|
||||
|
||||
return newBitmap;
|
||||
|
@ -1156,7 +1154,7 @@ namespace Greenshot.Base.Core
|
|||
return (Image) sourceImage.Clone();
|
||||
}
|
||||
|
||||
return CloneArea(sourceImage, Rectangle.Empty, PixelFormat.DontCare);
|
||||
return CloneArea(sourceImage, NativeRect.Empty, PixelFormat.DontCare);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1167,7 +1165,7 @@ namespace Greenshot.Base.Core
|
|||
/// <returns>Bitmap with clone image data</returns>
|
||||
public static Bitmap Clone(Image sourceBitmap, PixelFormat targetFormat)
|
||||
{
|
||||
return CloneArea(sourceBitmap, Rectangle.Empty, targetFormat);
|
||||
return CloneArea(sourceBitmap, NativeRect.Empty, targetFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1178,22 +1176,22 @@ namespace Greenshot.Base.Core
|
|||
/// 2) When going from a transparent to a non transparent bitmap, we draw the background white!
|
||||
/// </summary>
|
||||
/// <param name="sourceImage">Source bitmap to clone</param>
|
||||
/// <param name="sourceRect">Rectangle to copy from the source, use Rectangle.Empty for all</param>
|
||||
/// <param name="sourceRect">NativeRect to copy from the source, use NativeRect.Empty for all</param>
|
||||
/// <param name="targetFormat">Target Format, use PixelFormat.DontCare if you want the original (or a default if the source PixelFormat is not supported)</param>
|
||||
/// <returns></returns>
|
||||
public static Bitmap CloneArea(Image sourceImage, Rectangle sourceRect, PixelFormat targetFormat)
|
||||
public static Bitmap CloneArea(Image sourceImage, NativeRect sourceRect, PixelFormat targetFormat)
|
||||
{
|
||||
Bitmap newImage;
|
||||
Rectangle bitmapRect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
|
||||
NativeRect bitmapRect = new NativeRect(0, 0, sourceImage.Width, sourceImage.Height);
|
||||
|
||||
// Make sure the source is not Rectangle.Empty
|
||||
if (Rectangle.Empty.Equals(sourceRect))
|
||||
// Make sure the source is not NativeRect.Empty
|
||||
if (NativeRect.Empty.Equals(sourceRect))
|
||||
{
|
||||
sourceRect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height);
|
||||
sourceRect = new NativeRect(0, 0, sourceImage.Width, sourceImage.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceRect.Intersect(bitmapRect);
|
||||
sourceRect = sourceRect.Intersect(bitmapRect);
|
||||
}
|
||||
|
||||
// If no pixelformat is supplied
|
||||
|
@ -1505,7 +1503,7 @@ namespace Greenshot.Base.Core
|
|||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
using ImageAttributes wrapMode = new ImageAttributes();
|
||||
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||
graphics.DrawImage(sourceImage, new Rectangle(destX, destY, destWidth, destHeight), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, wrapMode);
|
||||
graphics.DrawImage(sourceImage, new NativeRect(destX, destY, destWidth, destHeight), 0, 0, sourceImage.Width, sourceImage.Height, GraphicsUnit.Pixel, wrapMode);
|
||||
}
|
||||
|
||||
return newImage;
|
||||
|
@ -1528,7 +1526,7 @@ namespace Greenshot.Base.Core
|
|||
graphics.RotateTransform(rotationAngle);
|
||||
graphics.TranslateTransform(-(float)bitmap.Width / 2, -(float)bitmap.Height / 2);
|
||||
|
||||
graphics.DrawImage(image, new Point(0, 0));
|
||||
graphics.DrawImage(image, new NativePoint(0, 0));
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
@ -1579,7 +1577,7 @@ namespace Greenshot.Base.Core
|
|||
/// <returns>BitmapSource</returns>
|
||||
public static BitmapSource ToBitmapSource(this Bitmap bitmap)
|
||||
{
|
||||
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
var bitmapData = bitmap.LockBits(new NativeRect(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
|
||||
BitmapSource bitmapSource;
|
||||
try
|
||||
|
@ -1608,7 +1606,7 @@ namespace Greenshot.Base.Core
|
|||
var pixelFormat = bitmapSource.Format.Map();
|
||||
|
||||
Bitmap bitmap = new Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight, pixelFormat);
|
||||
BitmapData data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, pixelFormat);
|
||||
BitmapData data = bitmap.LockBits(new NativeRect(NativePoint.Empty, bitmap.Size), ImageLockMode.WriteOnly, pixelFormat);
|
||||
bitmapSource.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
|
||||
bitmap.UnlockBits(data);
|
||||
return bitmap;
|
||||
|
|
|
@ -36,13 +36,12 @@ using Greenshot.Base.Core.FileFormatHandlers;
|
|||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Plugin;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of ImageOutput.
|
||||
/// This contains all io related logic for image
|
||||
/// </summary>
|
||||
public static class ImageIO
|
||||
{
|
||||
|
@ -559,93 +558,6 @@ namespace Greenshot.Base.Core
|
|||
return fileImage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Based on: https://www.codeproject.com/KB/cs/IconExtractor.aspx
|
||||
/// And a hint from: https://www.codeproject.com/KB/cs/IconLib.aspx
|
||||
/// </summary>
|
||||
/// <param name="iconStream">Stream with the icon information</param>
|
||||
/// <returns>Bitmap with the Vista Icon (256x256)</returns>
|
||||
private static Bitmap ExtractVistaIcon(Stream iconStream)
|
||||
{
|
||||
const int sizeIconDir = 6;
|
||||
const int sizeIconDirEntry = 16;
|
||||
Bitmap bmpPngExtracted = null;
|
||||
try
|
||||
{
|
||||
byte[] srcBuf = new byte[iconStream.Length];
|
||||
iconStream.Read(srcBuf, 0, (int)iconStream.Length);
|
||||
int iCount = BitConverter.ToInt16(srcBuf, 4);
|
||||
for (int iIndex = 0; iIndex < iCount; iIndex++)
|
||||
{
|
||||
int iWidth = srcBuf[sizeIconDir + sizeIconDirEntry * iIndex];
|
||||
int iHeight = srcBuf[sizeIconDir + sizeIconDirEntry * iIndex + 1];
|
||||
if (iWidth == 0 && iHeight == 0)
|
||||
{
|
||||
int iImageSize = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 8);
|
||||
int iImageOffset = BitConverter.ToInt32(srcBuf, sizeIconDir + sizeIconDirEntry * iIndex + 12);
|
||||
using MemoryStream destStream = new MemoryStream();
|
||||
destStream.Write(srcBuf, iImageOffset, iImageSize);
|
||||
destStream.Seek(0, SeekOrigin.Begin);
|
||||
bmpPngExtracted = new Bitmap(destStream); // This is PNG! :)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return bmpPngExtracted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648069%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
/// <param name="location">The file (EXE or DLL) to get the icon from</param>
|
||||
/// <param name="index">Index of the icon</param>
|
||||
/// <param name="takeLarge">true if the large icon is wanted</param>
|
||||
/// <returns>Icon</returns>
|
||||
public static Icon ExtractAssociatedIcon(string location, int index, bool takeLarge)
|
||||
{
|
||||
Shell32.ExtractIconEx(location, index, out var large, out var small, 1);
|
||||
Icon returnIcon = null;
|
||||
bool isLarge = false;
|
||||
bool isSmall = false;
|
||||
try
|
||||
{
|
||||
if (takeLarge && !IntPtr.Zero.Equals(large))
|
||||
{
|
||||
returnIcon = Icon.FromHandle(large);
|
||||
isLarge = true;
|
||||
}
|
||||
else if (!IntPtr.Zero.Equals(small))
|
||||
{
|
||||
returnIcon = Icon.FromHandle(small);
|
||||
isSmall = true;
|
||||
}
|
||||
else if (!IntPtr.Zero.Equals(large))
|
||||
{
|
||||
returnIcon = Icon.FromHandle(large);
|
||||
isLarge = true;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (isLarge && !IntPtr.Zero.Equals(small))
|
||||
{
|
||||
User32.DestroyIcon(small);
|
||||
}
|
||||
|
||||
if (isSmall && !IntPtr.Zero.Equals(large))
|
||||
{
|
||||
User32.DestroyIcon(large);
|
||||
}
|
||||
}
|
||||
|
||||
return returnIcon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an image from a stream, if an extension is supplied more formats are supported.
|
||||
/// </summary>
|
||||
|
|
|
@ -25,8 +25,8 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Icons;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using log4net;
|
||||
using Microsoft.Win32;
|
||||
|
||||
|
@ -113,7 +113,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="path">path to the exe or dll</param>
|
||||
/// <param name="index">index of the icon</param>
|
||||
/// <returns>Bitmap with the icon or null if something happended</returns>
|
||||
/// <returns>Bitmap with the icon or null if something happened</returns>
|
||||
public static Image GetCachedExeIcon(string path, int index)
|
||||
{
|
||||
string cacheKey = $"{path}:{index}";
|
||||
|
@ -148,7 +148,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="path">path to the exe or dll</param>
|
||||
/// <param name="index">index of the icon</param>
|
||||
/// <returns>Bitmap with the icon or null if something happended</returns>
|
||||
/// <returns>Bitmap with the icon or null if something happened</returns>
|
||||
private static Bitmap GetExeIcon(string path, int index)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
|
@ -158,20 +158,11 @@ namespace Greenshot.Base.Core
|
|||
|
||||
try
|
||||
{
|
||||
using (Icon appIcon = ImageIO.ExtractAssociatedIcon(path, index, CoreConfig.UseLargeIcons))
|
||||
var appIcon = IconHelper.ExtractAssociatedIcon<Bitmap>(path, index, CoreConfig.UseLargeIcons);
|
||||
if (appIcon != null)
|
||||
{
|
||||
if (appIcon != null)
|
||||
{
|
||||
return appIcon.ToBitmap();
|
||||
}
|
||||
}
|
||||
|
||||
using (Icon appIcon = Shell32.GetFileIcon(path, CoreConfig.UseLargeIcons ? Shell32.IconSize.Large : Shell32.IconSize.Small, false))
|
||||
{
|
||||
if (appIcon != null)
|
||||
{
|
||||
return appIcon.ToBitmap();
|
||||
}
|
||||
Log.DebugFormat("Loaded icon for {0}, with dimensions {1}x{2}", path, appIcon.Width, appIcon.Height);
|
||||
return appIcon;
|
||||
}
|
||||
}
|
||||
catch (Exception exIcon)
|
||||
|
@ -195,27 +186,25 @@ namespace Greenshot.Base.Core
|
|||
// Try to find a separator, so we insert ourselves after it
|
||||
for (int i = 0; i < contextMenu.Items.Count; i++)
|
||||
{
|
||||
if (contextMenu.Items[i].GetType() == typeof(ToolStripSeparator))
|
||||
if (contextMenu.Items[i].GetType() != typeof(ToolStripSeparator)) continue;
|
||||
// Check if we need to add a new separator, which is done if the first found has a Tag with the value "PluginsAreAddedBefore"
|
||||
if ("PluginsAreAddedBefore".Equals(contextMenu.Items[i].Tag))
|
||||
{
|
||||
// Check if we need to add a new separator, which is done if the first found has a Tag with the value "PluginsAreAddedBefore"
|
||||
if ("PluginsAreAddedBefore".Equals(contextMenu.Items[i].Tag))
|
||||
var separator = new ToolStripSeparator
|
||||
{
|
||||
var separator = new ToolStripSeparator
|
||||
{
|
||||
Tag = "PluginsAreAddedAfter",
|
||||
Size = new Size(305, 6)
|
||||
};
|
||||
contextMenu.Items.Insert(i, separator);
|
||||
}
|
||||
else if (!"PluginsAreAddedAfter".Equals(contextMenu.Items[i].Tag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
contextMenu.Items.Insert(i + 1, item);
|
||||
addedItem = true;
|
||||
break;
|
||||
Tag = "PluginsAreAddedAfter",
|
||||
Size = new Size(305, 6)
|
||||
};
|
||||
contextMenu.Items.Insert(i, separator);
|
||||
}
|
||||
else if (!"PluginsAreAddedAfter".Equals(contextMenu.Items[i].Tag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
contextMenu.Items.Insert(i + 1, item);
|
||||
addedItem = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// If we didn't insert the item, we just add it...
|
||||
|
|
|
@ -26,10 +26,20 @@ using System.Drawing;
|
|||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
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.Gdi32.Structs;
|
||||
using Dapplo.Windows.Icons;
|
||||
using Dapplo.Windows.Icons.SafeHandles;
|
||||
using Dapplo.Windows.Kernel32;
|
||||
using Dapplo.Windows.User32;
|
||||
using Dapplo.Windows.User32.Enums;
|
||||
using Dapplo.Windows.User32.Structs;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
|
@ -42,35 +52,6 @@ namespace Greenshot.Base.Core
|
|||
private static readonly ILog Log = LogManager.GetLogger(typeof(WindowCapture));
|
||||
private static readonly CoreConfiguration Configuration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
/// <summary>
|
||||
/// Used to cleanup the unmanaged resource in the iconInfo for the CaptureCursor method
|
||||
/// </summary>
|
||||
/// <param name="hObject"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteObject(IntPtr hObject);
|
||||
|
||||
/// <summary>
|
||||
/// Get the bounds of all screens combined.
|
||||
/// </summary>
|
||||
/// <returns>A Rectangle of the bounds of the entire display area.</returns>
|
||||
public static Rectangle GetScreenBounds()
|
||||
{
|
||||
int left = 0, top = 0, bottom = 0, right = 0;
|
||||
foreach (Screen screen in Screen.AllScreens)
|
||||
{
|
||||
left = Math.Min(left, screen.Bounds.X);
|
||||
top = Math.Min(top, screen.Bounds.Y);
|
||||
int screenAbsRight = screen.Bounds.X + screen.Bounds.Width;
|
||||
int screenAbsBottom = screen.Bounds.Y + screen.Bounds.Height;
|
||||
right = Math.Max(right, screenAbsRight);
|
||||
bottom = Math.Max(bottom, screenAbsBottom);
|
||||
}
|
||||
|
||||
return new Rectangle(left, top, (right + Math.Abs(left)), (bottom + Math.Abs(top)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the cursor location safely, accounting for DPI settings in Vista/Windows 7. This implementation
|
||||
/// can conveniently be used when the cursor location is needed to deal with a fullscreen bitmap.
|
||||
|
@ -78,9 +59,9 @@ namespace Greenshot.Base.Core
|
|||
/// <returns>
|
||||
/// Point with cursor location, relative to the top left corner of the monitor setup (which itself might actually not be on any screen)
|
||||
/// </returns>
|
||||
public static Point GetCursorLocationRelativeToScreenBounds()
|
||||
public static NativePoint GetCursorLocationRelativeToScreenBounds()
|
||||
{
|
||||
return GetLocationRelativeToScreenBounds(User32.GetCursorLocation());
|
||||
return GetLocationRelativeToScreenBounds(User32Api.GetCursorLocation());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -90,12 +71,10 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="locationRelativeToScreenOrigin"></param>
|
||||
/// <returns>Point</returns>
|
||||
public static Point GetLocationRelativeToScreenBounds(Point locationRelativeToScreenOrigin)
|
||||
public static NativePoint GetLocationRelativeToScreenBounds(NativePoint locationRelativeToScreenOrigin)
|
||||
{
|
||||
Point ret = locationRelativeToScreenOrigin;
|
||||
Rectangle bounds = GetScreenBounds();
|
||||
ret.Offset(-bounds.X, -bounds.Y);
|
||||
return ret;
|
||||
NativeRect bounds = DisplayInfo.ScreenBounds;
|
||||
return locationRelativeToScreenOrigin.Offset(-bounds.X, -bounds.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -110,36 +89,26 @@ namespace Greenshot.Base.Core
|
|||
capture = new Capture();
|
||||
}
|
||||
|
||||
var cursorInfo = new CursorInfo();
|
||||
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
|
||||
if (!User32.GetCursorInfo(out cursorInfo)) return capture;
|
||||
if (cursorInfo.flags != User32.CURSOR_SHOWING) return capture;
|
||||
var cursorInfo = CursorInfo.Create();
|
||||
if (!NativeCursorMethods.GetCursorInfo(ref cursorInfo)) return capture;
|
||||
if (cursorInfo.Flags != CursorInfoFlags.Showing) return capture;
|
||||
|
||||
using SafeIconHandle safeIcon = User32.CopyIcon(cursorInfo.hCursor);
|
||||
if (!User32.GetIconInfo(safeIcon, out var iconInfo)) return capture;
|
||||
using SafeIconHandle safeIcon = NativeIconMethods.CopyIcon(cursorInfo.CursorHandle);
|
||||
if (!NativeIconMethods.GetIconInfo(safeIcon, out var iconInfo)) return capture;
|
||||
|
||||
Point cursorLocation = User32.GetCursorLocation();
|
||||
NativePoint cursorLocation = User32Api.GetCursorLocation();
|
||||
// Align cursor location to Bitmap coordinates (instead of Screen coordinates)
|
||||
var x = cursorLocation.X - iconInfo.xHotspot - capture.ScreenBounds.X;
|
||||
var y = cursorLocation.Y - iconInfo.yHotspot - capture.ScreenBounds.Y;
|
||||
var x = cursorLocation.X - iconInfo.Hotspot.X - capture.ScreenBounds.X;
|
||||
var y = cursorLocation.Y - iconInfo.Hotspot.Y - capture.ScreenBounds.Y;
|
||||
// Set the location
|
||||
capture.CursorLocation = new Point(x, y);
|
||||
capture.CursorLocation = new NativePoint(x, y);
|
||||
|
||||
using (Icon icon = Icon.FromHandle(safeIcon.DangerousGetHandle()))
|
||||
{
|
||||
capture.Cursor = icon;
|
||||
}
|
||||
|
||||
if (iconInfo.hbmMask != IntPtr.Zero)
|
||||
{
|
||||
DeleteObject(iconInfo.hbmMask);
|
||||
}
|
||||
|
||||
if (iconInfo.hbmColor != IntPtr.Zero)
|
||||
{
|
||||
DeleteObject(iconInfo.hbmColor);
|
||||
}
|
||||
|
||||
iconInfo.BitmaskBitmapHandle.Dispose();
|
||||
iconInfo.ColorBitmapHandle.Dispose();
|
||||
return capture;
|
||||
}
|
||||
|
||||
|
@ -161,11 +130,11 @@ namespace Greenshot.Base.Core
|
|||
/// Helper method to create an exception that might explain what is wrong while capturing
|
||||
/// </summary>
|
||||
/// <param name="method">string with current method</param>
|
||||
/// <param name="captureBounds">Rectangle of what we want to capture</param>
|
||||
/// <param name="captureBounds">NativeRect of what we want to capture</param>
|
||||
/// <returns></returns>
|
||||
private static Exception CreateCaptureException(string method, Rectangle captureBounds)
|
||||
private static Exception CreateCaptureException(string method, NativeRect captureBounds)
|
||||
{
|
||||
Exception exceptionToThrow = User32.CreateWin32Exception(method);
|
||||
Exception exceptionToThrow = User32Api.CreateWin32Exception(method);
|
||||
if (!captureBounds.IsEmpty)
|
||||
{
|
||||
exceptionToThrow.Data.Add("Height", captureBounds.Height);
|
||||
|
@ -233,9 +202,9 @@ namespace Greenshot.Base.Core
|
|||
/// This method will use User32 code to capture the specified captureBounds from the screen
|
||||
/// </summary>
|
||||
/// <param name="capture">ICapture where the captured Bitmap will be stored</param>
|
||||
/// <param name="captureBounds">Rectangle with the bounds to capture</param>
|
||||
/// <param name="captureBounds">NativeRect with the bounds to capture</param>
|
||||
/// <returns>A Capture Object with a part of the Screen as an Image</returns>
|
||||
public static ICapture CaptureRectangle(ICapture capture, Rectangle captureBounds)
|
||||
public static ICapture CaptureRectangle(ICapture capture, NativeRect captureBounds)
|
||||
{
|
||||
if (capture == null)
|
||||
{
|
||||
|
@ -271,9 +240,9 @@ namespace Greenshot.Base.Core
|
|||
/// This method will use User32 code to capture the specified captureBounds from the screen
|
||||
/// </summary>
|
||||
/// <param name="capture">ICapture where the captured Bitmap will be stored</param>
|
||||
/// <param name="captureBounds">Rectangle with the bounds to capture</param>
|
||||
/// <param name="captureBounds">NativeRect with the bounds to capture</param>
|
||||
/// <returns>A Capture Object with a part of the Screen as an Image</returns>
|
||||
public static ICapture CaptureRectangleFromDesktopScreen(ICapture capture, Rectangle captureBounds)
|
||||
public static ICapture CaptureRectangleFromDesktopScreen(ICapture capture, NativeRect captureBounds)
|
||||
{
|
||||
if (capture == null)
|
||||
{
|
||||
|
@ -288,9 +257,9 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// This method will use User32 code to capture the specified captureBounds from the screen
|
||||
/// </summary>
|
||||
/// <param name="captureBounds">Rectangle with the bounds to capture</param>
|
||||
/// <param name="captureBounds">NativeRect with the bounds to capture</param>
|
||||
/// <returns>Bitmap which is captured from the screen at the location specified by the captureBounds</returns>
|
||||
public static Bitmap CaptureRectangle(Rectangle captureBounds)
|
||||
public static Bitmap CaptureRectangle(NativeRect captureBounds)
|
||||
{
|
||||
Bitmap returnBitmap = null;
|
||||
if (captureBounds.Height <= 0 || captureBounds.Width <= 0)
|
||||
|
@ -321,7 +290,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// create a device context we can copy to
|
||||
using SafeCompatibleDCHandle safeCompatibleDcHandle = GDI32.CreateCompatibleDC(desktopDcHandle);
|
||||
using SafeCompatibleDcHandle safeCompatibleDcHandle = Gdi32Api.CreateCompatibleDC(desktopDcHandle);
|
||||
// Check if the device context is there, if not throw an error with as much info as possible!
|
||||
if (safeCompatibleDcHandle.IsInvalid)
|
||||
{
|
||||
|
@ -332,13 +301,13 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// Create BITMAPINFOHEADER for CreateDIBSection
|
||||
BITMAPINFOHEADERV5 bmi = new BITMAPINFOHEADERV5(captureBounds.Width, captureBounds.Height, 24);
|
||||
var bitmapInfoHeader = BitmapV5Header.Create(captureBounds.Width, captureBounds.Height, 24);
|
||||
|
||||
// Make sure the last error is set to 0
|
||||
Win32.SetLastError(0);
|
||||
Kernel32Api.SetLastError(0);
|
||||
|
||||
// create a bitmap we can copy it to, using GetDeviceCaps to get the width/height
|
||||
using SafeDibSectionHandle safeDibSectionHandle = GDI32.CreateDIBSection(desktopDcHandle, ref bmi, BITMAPINFOHEADERV5.DIB_RGB_COLORS, out _, IntPtr.Zero, 0);
|
||||
using SafeDibSectionHandle safeDibSectionHandle = Gdi32Api.CreateDIBSection(desktopDcHandle, ref bitmapInfoHeader, DibColors.RgbColors, out _, IntPtr.Zero, 0);
|
||||
if (safeDibSectionHandle.IsInvalid)
|
||||
{
|
||||
// Get Exception before the error is lost
|
||||
|
@ -355,8 +324,8 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
// bitblt over (make copy)
|
||||
// ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
|
||||
GDI32.BitBlt(safeCompatibleDcHandle, 0, 0, captureBounds.Width, captureBounds.Height, desktopDcHandle, captureBounds.X, captureBounds.Y,
|
||||
CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
|
||||
Gdi32Api.BitBlt(safeCompatibleDcHandle, 0, 0, captureBounds.Width, captureBounds.Height, desktopDcHandle, captureBounds.X, captureBounds.Y,
|
||||
RasterOperations.SourceCopy | RasterOperations.CaptureBlt);
|
||||
}
|
||||
|
||||
// get a .NET image object for it
|
||||
|
@ -388,7 +357,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// If the region is not empty, we have "offscreenContent"
|
||||
using Graphics screenGraphics = Graphics.FromHwnd(User32.GetDesktopWindow());
|
||||
using Graphics screenGraphics = Graphics.FromHwnd(User32Api.GetDesktopWindow());
|
||||
offscreenContent = !captureRegion.IsEmpty(screenGraphics);
|
||||
}
|
||||
|
||||
|
@ -397,17 +366,16 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
using Bitmap tmpBitmap = Image.FromHbitmap(safeDibSectionHandle.DangerousGetHandle());
|
||||
// Create a new bitmap which has a transparent background
|
||||
returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent,
|
||||
tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution);
|
||||
returnBitmap = ImageHelper.CreateEmpty(tmpBitmap.Width, tmpBitmap.Height, PixelFormat.Format32bppArgb, Color.Transparent, tmpBitmap.HorizontalResolution, tmpBitmap.VerticalResolution);
|
||||
// Content will be copied here
|
||||
using Graphics graphics = Graphics.FromImage(returnBitmap);
|
||||
// For all screens copy the content to the new bitmap
|
||||
foreach (Screen screen in Screen.AllScreens)
|
||||
|
||||
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
|
||||
{
|
||||
Rectangle screenBounds = screen.Bounds;
|
||||
// Make sure the bounds are offsetted to the capture bounds
|
||||
screenBounds.Offset(-captureBounds.X, -captureBounds.Y);
|
||||
graphics.DrawImage(tmpBitmap, screenBounds, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height, GraphicsUnit.Pixel);
|
||||
// Make sure the bounds are offset to the capture bounds
|
||||
var displayBounds = displayInfo.Bounds.Offset(-captureBounds.X, -captureBounds.Y);
|
||||
graphics.DrawImage(tmpBitmap, displayBounds, displayBounds.X, displayBounds.Y, displayBounds.Width, displayBounds.Height, GraphicsUnit.Pixel);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -7,13 +7,25 @@ using System.Linq;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common;
|
||||
using Dapplo.Windows.Common.Enums;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.DesktopWindowsManager;
|
||||
using Dapplo.Windows.DesktopWindowsManager.Enums;
|
||||
using Dapplo.Windows.DesktopWindowsManager.Structs;
|
||||
using Dapplo.Windows.Gdi32;
|
||||
using Dapplo.Windows.Gdi32.SafeHandles;
|
||||
using Dapplo.Windows.Kernel32;
|
||||
using Dapplo.Windows.Kernel32.Enums;
|
||||
using Dapplo.Windows.Messages.Enumerations;
|
||||
using Dapplo.Windows.User32;
|
||||
using Dapplo.Windows.User32.Enums;
|
||||
using Dapplo.Windows.User32.Structs;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interop;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
|
@ -187,8 +199,8 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// Get the process id
|
||||
User32.GetWindowThreadProcessId(Handle, out var processId);
|
||||
return Kernel32.GetProcessPath(processId);
|
||||
User32Api.GetWindowThreadProcessId(Handle, out var processId);
|
||||
return Kernel32Api.GetProcessPath(processId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,35 +260,35 @@ namespace Greenshot.Base.Core
|
|||
IntPtr iconHandle;
|
||||
if (Conf.UseLargeIcons)
|
||||
{
|
||||
iconHandle = User32.SendMessage(hWnd, (int) WindowsMessages.WM_GETICON, iconBig, IntPtr.Zero);
|
||||
iconHandle = User32Api.SendMessage(hWnd, WindowsMessages.WM_GETICON, iconBig, IntPtr.Zero);
|
||||
if (iconHandle == IntPtr.Zero)
|
||||
{
|
||||
iconHandle = User32.GetClassLongWrapper(hWnd, (int) ClassLongIndex.GCL_HICON);
|
||||
iconHandle = User32Api.GetClassLongWrapper(hWnd, ClassLongIndex.IconHandle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
iconHandle = User32.SendMessage(hWnd, (int) WindowsMessages.WM_GETICON, iconSmall2, IntPtr.Zero);
|
||||
iconHandle = User32Api.SendMessage(hWnd, WindowsMessages.WM_GETICON, iconSmall2, IntPtr.Zero);
|
||||
}
|
||||
|
||||
if (iconHandle == IntPtr.Zero)
|
||||
{
|
||||
iconHandle = User32.SendMessage(hWnd, (int) WindowsMessages.WM_GETICON, iconSmall, IntPtr.Zero);
|
||||
iconHandle = User32Api.SendMessage(hWnd, WindowsMessages.WM_GETICON, iconSmall, IntPtr.Zero);
|
||||
}
|
||||
|
||||
if (iconHandle == IntPtr.Zero)
|
||||
{
|
||||
iconHandle = User32.GetClassLongWrapper(hWnd, (int) ClassLongIndex.GCL_HICONSM);
|
||||
iconHandle = User32Api.GetClassLongWrapper(hWnd, ClassLongIndex.IconHandle);
|
||||
}
|
||||
|
||||
if (iconHandle == IntPtr.Zero)
|
||||
{
|
||||
iconHandle = User32.SendMessage(hWnd, (int) WindowsMessages.WM_GETICON, iconBig, IntPtr.Zero);
|
||||
iconHandle = User32Api.SendMessage(hWnd, WindowsMessages.WM_GETICON, iconBig, IntPtr.Zero);
|
||||
}
|
||||
|
||||
if (iconHandle == IntPtr.Zero)
|
||||
{
|
||||
iconHandle = User32.GetClassLongWrapper(hWnd, (int) ClassLongIndex.GCL_HICON);
|
||||
iconHandle = User32Api.GetClassLongWrapper(hWnd, ClassLongIndex.IconHandle);
|
||||
}
|
||||
|
||||
if (iconHandle == IntPtr.Zero)
|
||||
|
@ -342,7 +354,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
if (_parentHandle == IntPtr.Zero)
|
||||
{
|
||||
_parentHandle = User32.GetParent(Handle);
|
||||
_parentHandle = User32Api.GetParent(Handle);
|
||||
_parent = null;
|
||||
}
|
||||
|
||||
|
@ -368,7 +380,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
if (_parentHandle == IntPtr.Zero)
|
||||
{
|
||||
_parentHandle = User32.GetParent(Handle);
|
||||
_parentHandle = User32Api.GetParent(Handle);
|
||||
}
|
||||
|
||||
if (_parentHandle != IntPtr.Zero)
|
||||
|
@ -434,9 +446,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
if (_text == null)
|
||||
{
|
||||
var title = new StringBuilder(260, 260);
|
||||
User32.GetWindowText(Handle, title, title.Capacity);
|
||||
_text = title.ToString();
|
||||
_text = User32Api.GetText(Handle);
|
||||
}
|
||||
|
||||
return _text;
|
||||
|
@ -448,7 +458,7 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Gets the window's class name.
|
||||
/// </summary>
|
||||
public string ClassName => _className ??= GetClassName(Handle);
|
||||
public string ClassName => _className ??= User32Api.GetClassname(Handle);
|
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether the window is iconic (minimized) or not.
|
||||
|
@ -462,17 +472,17 @@ namespace Greenshot.Base.Core
|
|||
return !Visible;
|
||||
}
|
||||
|
||||
return User32.IsIconic(Handle) || Location.X <= -32000;
|
||||
return User32Api.IsIconic(Handle) || Location.X <= -32000;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
User32.SendMessage(Handle, (int) WindowsMessages.WM_SYSCOMMAND, (IntPtr) User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
User32Api.SendMessage(Handle, WindowsMessages.WM_SYSCOMMAND, SysCommands.SC_MINIMIZE, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
User32.SendMessage(Handle, (int) WindowsMessages.WM_SYSCOMMAND, (IntPtr) User32.SC_RESTORE, IntPtr.Zero);
|
||||
User32Api.SendMessage(Handle, WindowsMessages.WM_SYSCOMMAND, SysCommands.SC_RESTORE, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -488,15 +498,11 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
if (Visible)
|
||||
{
|
||||
Rectangle windowRectangle = WindowRectangle;
|
||||
foreach (var screen in Screen.AllScreens)
|
||||
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
|
||||
{
|
||||
if (screen.Bounds.Contains(windowRectangle))
|
||||
if (WindowRectangle.Equals(displayInfo.Bounds))
|
||||
{
|
||||
if (windowRectangle.Equals(screen.Bounds))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -504,17 +510,17 @@ namespace Greenshot.Base.Core
|
|||
return false;
|
||||
}
|
||||
|
||||
return User32.IsZoomed(Handle);
|
||||
return User32Api.IsZoomed(Handle);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
User32.SendMessage(Handle, (int) WindowsMessages.WM_SYSCOMMAND, (IntPtr) User32.SC_MAXIMIZE, IntPtr.Zero);
|
||||
User32Api.SendMessage(Handle, WindowsMessages.WM_SYSCOMMAND, SysCommands.SC_MAXIMIZE, IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
User32.SendMessage(Handle, (int) WindowsMessages.WM_SYSCOMMAND, (IntPtr) User32.SC_MINIMIZE, IntPtr.Zero);
|
||||
User32Api.SendMessage(Handle, WindowsMessages.WM_SYSCOMMAND, SysCommands.SC_MINIMIZE, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +530,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public bool IsCloaked
|
||||
{
|
||||
get => DWM.IsWindowCloaked(Handle);
|
||||
get => DwmApi.IsWindowCloaked(Handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -542,32 +548,31 @@ namespace Greenshot.Base.Core
|
|||
|
||||
if (IsApp)
|
||||
{
|
||||
Rectangle windowRectangle = WindowRectangle;
|
||||
foreach (Screen screen in Screen.AllScreens)
|
||||
var windowRectangle = WindowRectangle;
|
||||
|
||||
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
|
||||
{
|
||||
if (screen.Bounds.Contains(windowRectangle))
|
||||
if (!displayInfo.Bounds.Contains(windowRectangle)) continue;
|
||||
if (windowRectangle.Equals(displayInfo.Bounds))
|
||||
{
|
||||
if (windowRectangle.Equals(screen.Bounds))
|
||||
// Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes
|
||||
// Although it might be the other App, this is not "very" important
|
||||
NativeRect rect = displayInfo.Bounds;
|
||||
IntPtr monitor = User32Api.MonitorFromRect(ref rect, MonitorFrom.DefaultToNull);
|
||||
if (monitor != IntPtr.Zero)
|
||||
{
|
||||
// Fullscreen, it's "visible" when AppVisibilityOnMonitor says yes
|
||||
// Although it might be the other App, this is not "very" important
|
||||
RECT rect = new RECT(screen.Bounds);
|
||||
IntPtr monitor = User32.MonitorFromRect(ref rect, User32.MONITOR_DEFAULTTONULL);
|
||||
if (monitor != IntPtr.Zero)
|
||||
MONITOR_APP_VISIBILITY? monitorAppVisibility = AppVisibility?.GetAppVisibilityOnMonitor(monitor);
|
||||
//LOG.DebugFormat("App {0} visible: {1} on {2}", Text, monitorAppVisibility, screen.Bounds);
|
||||
if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE)
|
||||
{
|
||||
MONITOR_APP_VISIBILITY? monitorAppVisibility = AppVisibility?.GetAppVisibilityOnMonitor(monitor);
|
||||
//LOG.DebugFormat("App {0} visible: {1} on {2}", Text, monitorAppVisibility, screen.Bounds);
|
||||
if (monitorAppVisibility == MONITOR_APP_VISIBILITY.MAV_APP_VISIBLE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Is only partly on the screen, when this happens the app is always visible!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Is only partly on the screen, when this happens the app is always visible!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -585,7 +590,7 @@ namespace Greenshot.Base.Core
|
|||
return IsAppLauncherVisible;
|
||||
}
|
||||
|
||||
return User32.IsWindowVisible(Handle);
|
||||
return User32Api.IsWindowVisible(Handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,7 +607,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
get
|
||||
{
|
||||
User32.GetWindowThreadProcessId(Handle, out var processId);
|
||||
User32Api.GetWindowThreadProcessId(Handle, out var processId);
|
||||
return processId;
|
||||
}
|
||||
}
|
||||
|
@ -613,7 +618,7 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
try
|
||||
{
|
||||
User32.GetWindowThreadProcessId(Handle, out var processId);
|
||||
User32Api.GetWindowThreadProcessId(Handle, out var processId);
|
||||
return Process.GetProcessById(processId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -625,14 +630,14 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
}
|
||||
|
||||
private Rectangle _previousWindowRectangle = Rectangle.Empty;
|
||||
private NativeRect _previousWindowRectangle = NativeRect.Empty;
|
||||
private long _lastWindowRectangleRetrieveTime;
|
||||
private const long CacheTime = TimeSpan.TicksPerSecond * 2;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bounding rectangle of the window
|
||||
/// </summary>
|
||||
public Rectangle WindowRectangle
|
||||
public NativeRect WindowRectangle
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -644,9 +649,8 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
return _previousWindowRectangle;
|
||||
}
|
||||
|
||||
Rectangle windowRect = Rectangle.Empty;
|
||||
if (DWM.IsDwmEnabled)
|
||||
NativeRect windowRect = new();
|
||||
if (DwmApi.IsDwmEnabled)
|
||||
{
|
||||
bool gotFrameBounds = GetExtendedFrameBounds(out windowRect);
|
||||
if (IsApp)
|
||||
|
@ -661,9 +665,9 @@ namespace Greenshot.Base.Core
|
|||
|
||||
if (gotFrameBounds && WindowsVersion.IsWindows10OrLater && !Maximised)
|
||||
{
|
||||
// Somehow DWM doesn't calculate it corectly, there is a 1 pixel border around the capture
|
||||
// Somehow DWM doesn't calculate it correctly, there is a 1 pixel border around the capture
|
||||
// Remove this border, currently it's fixed but TODO: Make it depend on the OS?
|
||||
windowRect.Inflate(Conf.Win10BorderCrop);
|
||||
windowRect = windowRect.Inflate(Conf.Win10BorderCrop);
|
||||
_previousWindowRectangle = windowRect;
|
||||
_lastWindowRectangleRetrieveTime = now;
|
||||
return windowRect;
|
||||
|
@ -685,13 +689,13 @@ namespace Greenshot.Base.Core
|
|||
// Only if the border size can be retrieved
|
||||
if (GetBorderSize(out var size))
|
||||
{
|
||||
windowRect = new Rectangle(windowRect.X + size.Width, windowRect.Y + size.Height, windowRect.Width - (2 * size.Width),
|
||||
windowRect = new NativeRect(windowRect.X + size.Width, windowRect.Y + size.Height, windowRect.Width - (2 * size.Width),
|
||||
windowRect.Height - (2 * size.Height));
|
||||
}
|
||||
}
|
||||
|
||||
_lastWindowRectangleRetrieveTime = now;
|
||||
// Try to return something valid, by getting returning the previous size if the window doesn't have a Rectangle anymore
|
||||
// Try to return something valid, by getting returning the previous size if the window doesn't have a NativeRect anymore
|
||||
if (windowRect.IsEmpty)
|
||||
{
|
||||
return _previousWindowRectangle;
|
||||
|
@ -708,31 +712,23 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Gets the location of the window relative to the screen.
|
||||
/// </summary>
|
||||
public Point Location
|
||||
public NativePoint Location
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle tmpRectangle = WindowRectangle;
|
||||
return new Point(tmpRectangle.Left, tmpRectangle.Top);
|
||||
}
|
||||
get => WindowRectangle.Location;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size of the window.
|
||||
/// </summary>
|
||||
public Size Size
|
||||
public NativeSize Size
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle tmpRectangle = WindowRectangle;
|
||||
return new Size(tmpRectangle.Right - tmpRectangle.Left, tmpRectangle.Bottom - tmpRectangle.Top);
|
||||
}
|
||||
get => WindowRectangle.Size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the client rectangle, this is the part of the window inside the borders (drawable area)
|
||||
/// </summary>
|
||||
public Rectangle ClientRectangle
|
||||
public NativeRect ClientRectangle
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -751,7 +747,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="p">Point with the coordinates to check</param>
|
||||
/// <returns>true if the point lies within</returns>
|
||||
public bool Contains(Point p)
|
||||
public bool Contains(NativePoint p)
|
||||
{
|
||||
return WindowRectangle.Contains(p);
|
||||
}
|
||||
|
@ -764,11 +760,11 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
if (Iconic)
|
||||
{
|
||||
User32.SendMessage(Handle, (int) WindowsMessages.WM_SYSCOMMAND, (IntPtr) User32.SC_RESTORE, IntPtr.Zero);
|
||||
User32Api.SendMessage(Handle, WindowsMessages.WM_SYSCOMMAND, SysCommands.SC_RESTORE, IntPtr.Zero);
|
||||
}
|
||||
|
||||
User32.BringWindowToTop(Handle);
|
||||
User32.SetForegroundWindow(Handle);
|
||||
User32Api.BringWindowToTop(Handle);
|
||||
User32Api.SetForegroundWindow(Handle);
|
||||
// Make sure windows has time to perform the action
|
||||
// TODO: this is BAD practice!
|
||||
while (Iconic)
|
||||
|
@ -783,9 +779,9 @@ namespace Greenshot.Base.Core
|
|||
public WindowStyleFlags WindowStyle
|
||||
{
|
||||
get => unchecked(
|
||||
(WindowStyleFlags)User32.GetWindowLongWrapper(Handle, (int)WindowLongIndex.GWL_STYLE).ToInt64()
|
||||
(WindowStyleFlags)User32Api.GetWindowLongWrapper(Handle, WindowLongIndex.GWL_STYLE).ToInt64()
|
||||
);
|
||||
set => User32.SetWindowLongWrapper(Handle, (int) WindowLongIndex.GWL_STYLE, new IntPtr((long) value));
|
||||
set => User32Api.SetWindowLongWrapper(Handle, WindowLongIndex.GWL_STYLE, new IntPtr((long) value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -795,11 +791,11 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
get
|
||||
{
|
||||
var placement = WindowPlacement.Default;
|
||||
User32.GetWindowPlacement(Handle, ref placement);
|
||||
var placement = WindowPlacement.Create();
|
||||
User32Api.GetWindowPlacement(Handle, ref placement);
|
||||
return placement;
|
||||
}
|
||||
set { User32.SetWindowPlacement(Handle, ref value); }
|
||||
set { User32Api.SetWindowPlacement(Handle, ref value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -807,8 +803,8 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public ExtendedWindowStyleFlags ExtendedWindowStyle
|
||||
{
|
||||
get => (ExtendedWindowStyleFlags) User32.GetWindowLongWrapper(Handle, (int) WindowLongIndex.GWL_EXSTYLE);
|
||||
set => User32.SetWindowLongWrapper(Handle, (int) WindowLongIndex.GWL_EXSTYLE, new IntPtr((uint) value));
|
||||
get => (ExtendedWindowStyleFlags) User32Api.GetWindowLongWrapper(Handle, WindowLongIndex.GWL_EXSTYLE);
|
||||
set => User32Api.SetWindowLongWrapper(Handle, WindowLongIndex.GWL_EXSTYLE, new IntPtr((uint) value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -848,10 +844,10 @@ namespace Greenshot.Base.Core
|
|||
};
|
||||
|
||||
// Register the Thumbnail
|
||||
DWM.DwmRegisterThumbnail(tempForm.Handle, Handle, out thumbnailHandle);
|
||||
DwmApi.DwmRegisterThumbnail(tempForm.Handle, Handle, out thumbnailHandle);
|
||||
|
||||
// Get the original size
|
||||
DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out var sourceSize);
|
||||
DwmApi.DwmQueryThumbnailSourceSize(thumbnailHandle, out var sourceSize);
|
||||
|
||||
if (sourceSize.Width <= 0 || sourceSize.Height <= 0)
|
||||
{
|
||||
|
@ -859,9 +855,9 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// Calculate the location of the temp form
|
||||
Rectangle windowRectangle = WindowRectangle;
|
||||
Point formLocation = windowRectangle.Location;
|
||||
Size borderSize = new Size();
|
||||
NativeRect windowRectangle = WindowRectangle;
|
||||
NativePoint formLocation = windowRectangle.Location;
|
||||
NativeSize borderSize = new NativeSize();
|
||||
bool doesCaptureFit = false;
|
||||
if (!Maximised)
|
||||
{
|
||||
|
@ -882,12 +878,13 @@ namespace Greenshot.Base.Core
|
|||
if (!workingArea.AreRectangleCornersVisisble(windowRectangle))
|
||||
{
|
||||
// If none found we find the biggest screen
|
||||
foreach (Screen screen in Screen.AllScreens)
|
||||
|
||||
foreach (var displayInfo in DisplayInfo.AllDisplayInfos)
|
||||
{
|
||||
Rectangle newWindowRectangle = new Rectangle(screen.WorkingArea.Location, windowRectangle.Size);
|
||||
var newWindowRectangle = new NativeRect(displayInfo.WorkingArea.Location, windowRectangle.Size);
|
||||
if (workingArea.AreRectangleCornersVisisble(newWindowRectangle))
|
||||
{
|
||||
formLocation = screen.Bounds.Location;
|
||||
formLocation = displayInfo.Bounds.Location;
|
||||
doesCaptureFit = true;
|
||||
break;
|
||||
}
|
||||
|
@ -902,26 +899,26 @@ namespace Greenshot.Base.Core
|
|||
{
|
||||
//GetClientRect(out windowRectangle);
|
||||
GetBorderSize(out borderSize);
|
||||
formLocation = new Point(windowRectangle.X - borderSize.Width, windowRectangle.Y - borderSize.Height);
|
||||
formLocation = new NativePoint(windowRectangle.X - borderSize.Width, windowRectangle.Y - borderSize.Height);
|
||||
}
|
||||
|
||||
tempForm.Location = formLocation;
|
||||
tempForm.Size = sourceSize.ToSize();
|
||||
tempForm.Size = sourceSize;
|
||||
|
||||
// Prepare rectangle to capture from the screen.
|
||||
Rectangle captureRectangle = new Rectangle(formLocation.X, formLocation.Y, sourceSize.Width, sourceSize.Height);
|
||||
var captureRectangle = new NativeRect(formLocation.X, formLocation.Y, sourceSize.Width, sourceSize.Height);
|
||||
if (Maximised)
|
||||
{
|
||||
// Correct capture size for maximized window by offsetting the X,Y with the border size
|
||||
// and subtracting the border from the size (2 times, as we move right/down for the capture without resizing)
|
||||
captureRectangle.Inflate(borderSize.Width, borderSize.Height);
|
||||
captureRectangle = captureRectangle.Inflate(borderSize.Width, borderSize.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Also 8.x?
|
||||
if (WindowsVersion.IsWindows10OrLater)
|
||||
{
|
||||
captureRectangle.Inflate(Conf.Win10BorderCrop);
|
||||
captureRectangle = captureRectangle.Inflate(Conf.Win10BorderCrop);
|
||||
}
|
||||
|
||||
if (autoMode)
|
||||
|
@ -941,18 +938,18 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// Prepare the displaying of the Thumbnail
|
||||
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES
|
||||
var props = new DwmThumbnailProperties()
|
||||
{
|
||||
Opacity = 255,
|
||||
Visible = true,
|
||||
Destination = new RECT(0, 0, sourceSize.Width, sourceSize.Height)
|
||||
Destination = new NativeRect(0, 0, sourceSize.Width, sourceSize.Height)
|
||||
};
|
||||
DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
|
||||
DwmApi.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
|
||||
tempForm.Show();
|
||||
tempFormShown = true;
|
||||
|
||||
// Intersect with screen
|
||||
captureRectangle.Intersect(capture.ScreenBounds);
|
||||
captureRectangle = captureRectangle.Intersect(capture.ScreenBounds);
|
||||
|
||||
// Destination bitmap for the capture
|
||||
Bitmap capturedBitmap = null;
|
||||
|
@ -1009,10 +1006,9 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
else
|
||||
{
|
||||
Color colorizationColor = DWM.ColorizationColor;
|
||||
var colorizationColor = DwmApi.ColorizationColor;
|
||||
// Modify by losing the transparency and increasing the intensity (as if the background color is white)
|
||||
colorizationColor = Color.FromArgb(255, (colorizationColor.R + 255) >> 1, (colorizationColor.G + 255) >> 1, (colorizationColor.B + 255) >> 1);
|
||||
tempForm.BackColor = colorizationColor;
|
||||
tempForm.BackColor = Color.FromArgb(255, (colorizationColor.R + 255) >> 1, (colorizationColor.G + 255) >> 1, (colorizationColor.B + 255) >> 1);
|
||||
}
|
||||
|
||||
// Make sure everything is visible
|
||||
|
@ -1069,7 +1065,7 @@ namespace Greenshot.Base.Core
|
|||
if (thumbnailHandle != IntPtr.Zero)
|
||||
{
|
||||
// Un-register (cleanup), as we are finished we don't need the form or the thumbnail anymore
|
||||
DWM.DwmUnregisterThumbnail(thumbnailHandle);
|
||||
DwmApi.DwmUnregisterThumbnail(thumbnailHandle);
|
||||
}
|
||||
|
||||
if (tempForm != null)
|
||||
|
@ -1108,7 +1104,7 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Apply transparency by comparing a transparent capture with a black and white background
|
||||
/// A "Math.min" makes sure there is no overflow, but this could cause the picture to have shifted colors.
|
||||
/// The pictures should have been taken without differency, except for the colors.
|
||||
/// The pictures should have been taken without difference, except for the colors.
|
||||
/// </summary>
|
||||
/// <param name="blackBitmap">Bitmap with the black image</param>
|
||||
/// <param name="whiteBitmap">Bitmap with the black image</param>
|
||||
|
@ -1161,46 +1157,46 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Helper method to get the window size for DWM Windows
|
||||
/// </summary>
|
||||
/// <param name="rectangle">out Rectangle</param>
|
||||
/// <param name="rectangle">out NativeRect</param>
|
||||
/// <returns>bool true if it worked</returns>
|
||||
private bool GetExtendedFrameBounds(out Rectangle rectangle)
|
||||
private bool GetExtendedFrameBounds(out NativeRect rectangle)
|
||||
{
|
||||
int result = DWM.DwmGetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, out RECT rect, Marshal.SizeOf(typeof(RECT)));
|
||||
if (result >= 0)
|
||||
var result = DwmApi.DwmGetWindowAttribute(Handle, DwmWindowAttributes.ExtendedFrameBounds, out NativeRect rect, Marshal.SizeOf(typeof(NativeRect)));
|
||||
if (result.Succeeded())
|
||||
{
|
||||
rectangle = rect.ToRectangle();
|
||||
rectangle = rect;
|
||||
return true;
|
||||
}
|
||||
|
||||
rectangle = Rectangle.Empty;
|
||||
rectangle = NativeRect.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to get the window size for GDI Windows
|
||||
/// </summary>
|
||||
/// <param name="rectangle">out Rectangle</param>
|
||||
/// <param name="rectangle">out NativeRect</param>
|
||||
/// <returns>bool true if it worked</returns>
|
||||
private bool GetClientRect(out Rectangle rectangle)
|
||||
private bool GetClientRect(out NativeRect rectangle)
|
||||
{
|
||||
var windowInfo = new WindowInfo();
|
||||
// Get the Window Info for this window
|
||||
bool result = User32.GetWindowInfo(Handle, ref windowInfo);
|
||||
rectangle = result ? windowInfo.rcClient.ToRectangle() : Rectangle.Empty;
|
||||
bool result = User32Api.GetWindowInfo(Handle, ref windowInfo);
|
||||
rectangle = result ? windowInfo.ClientBounds : NativeRect.Empty;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to get the window size for GDI Windows
|
||||
/// </summary>
|
||||
/// <param name="rectangle">out Rectangle</param>
|
||||
/// <param name="rectangle">out NativeRect</param>
|
||||
/// <returns>bool true if it worked</returns>
|
||||
private bool GetWindowRect(out Rectangle rectangle)
|
||||
private bool GetWindowRect(out NativeRect rectangle)
|
||||
{
|
||||
var windowInfo = new WindowInfo();
|
||||
// Get the Window Info for this window
|
||||
bool result = User32.GetWindowInfo(Handle, ref windowInfo);
|
||||
rectangle = result ? windowInfo.rcWindow.ToRectangle() : Rectangle.Empty;
|
||||
bool result = User32Api.GetWindowInfo(Handle, ref windowInfo);
|
||||
rectangle = result ? windowInfo.Bounds : NativeRect.Empty;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1209,12 +1205,12 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
/// <param name="size">out Size</param>
|
||||
/// <returns>bool true if it worked</returns>
|
||||
private bool GetBorderSize(out Size size)
|
||||
private bool GetBorderSize(out NativeSize size)
|
||||
{
|
||||
var windowInfo = new WindowInfo();
|
||||
// Get the Window Info for this window
|
||||
bool result = User32.GetWindowInfo(Handle, ref windowInfo);
|
||||
size = result ? new Size((int) windowInfo.cxWindowBorders, (int) windowInfo.cyWindowBorders) : Size.Empty;
|
||||
bool result = User32Api.GetWindowInfo(Handle, ref windowInfo);
|
||||
size = result ? windowInfo.BorderSize : NativeSize.Empty;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1224,7 +1220,7 @@ namespace Greenshot.Base.Core
|
|||
/// <param name="hWnd">hWnd of the window to bring to the foreground</param>
|
||||
public static void ToForeground(IntPtr hWnd)
|
||||
{
|
||||
var foregroundWindow = User32.GetForegroundWindow();
|
||||
var foregroundWindow = User32Api.GetForegroundWindow();
|
||||
if (hWnd == foregroundWindow)
|
||||
{
|
||||
return;
|
||||
|
@ -1237,22 +1233,22 @@ namespace Greenshot.Base.Core
|
|||
return;
|
||||
}
|
||||
|
||||
var threadId1 = User32.GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero);
|
||||
var threadId2 = User32.GetWindowThreadProcessId(hWnd, IntPtr.Zero);
|
||||
var threadId1 = User32Api.GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero);
|
||||
var threadId2 = User32Api.GetWindowThreadProcessId(hWnd, IntPtr.Zero);
|
||||
|
||||
// Show window in foreground.
|
||||
if (threadId1 != threadId2)
|
||||
{
|
||||
User32.AttachThreadInput(threadId1, threadId2, 1);
|
||||
User32.SetForegroundWindow(hWnd);
|
||||
User32.AttachThreadInput(threadId1, threadId2, 0);
|
||||
User32Api.AttachThreadInput(threadId1, threadId2, 1);
|
||||
User32Api.SetForegroundWindow(hWnd);
|
||||
User32Api.AttachThreadInput(threadId1, threadId2, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
User32.SetForegroundWindow(hWnd);
|
||||
User32Api.SetForegroundWindow(hWnd);
|
||||
}
|
||||
|
||||
User32.BringWindowToTop(hWnd);
|
||||
User32Api.BringWindowToTop(hWnd);
|
||||
|
||||
if (window.Iconic)
|
||||
{
|
||||
|
@ -1273,12 +1269,12 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
private Region GetRegion()
|
||||
{
|
||||
using (SafeRegionHandle region = GDI32.CreateRectRgn(0, 0, 0, 0))
|
||||
using (SafeRegionHandle region = Gdi32Api.CreateRectRgn(0, 0, 0, 0))
|
||||
{
|
||||
if (!region.IsInvalid)
|
||||
{
|
||||
RegionResult result = User32.GetWindowRgn(Handle, region);
|
||||
if (result != RegionResult.REGION_ERROR && result != RegionResult.REGION_NULLREGION)
|
||||
var result = User32Api.GetWindowRgn(Handle, region);
|
||||
if (result != RegionResults.Error && result != RegionResults.NullRegion)
|
||||
{
|
||||
return Region.FromHrgn(region.DangerousGetHandle());
|
||||
}
|
||||
|
@ -1338,7 +1334,7 @@ namespace Greenshot.Base.Core
|
|||
|
||||
foreach (ProcessThread pT in proc.Threads)
|
||||
{
|
||||
IntPtr pOpenThread = Kernel32.OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint) pT.Id);
|
||||
IntPtr pOpenThread = Kernel32Api.OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint) pT.Id);
|
||||
|
||||
if (pOpenThread == IntPtr.Zero)
|
||||
{
|
||||
|
@ -1346,7 +1342,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
frozen = true;
|
||||
Kernel32.SuspendThread(pOpenThread);
|
||||
Kernel32Api.SuspendThread(pOpenThread);
|
||||
pT.Dispose();
|
||||
}
|
||||
}
|
||||
|
@ -1377,14 +1373,14 @@ namespace Greenshot.Base.Core
|
|||
|
||||
foreach (ProcessThread pT in proc.Threads)
|
||||
{
|
||||
IntPtr pOpenThread = Kernel32.OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint) pT.Id);
|
||||
IntPtr pOpenThread = Kernel32Api.OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint) pT.Id);
|
||||
|
||||
if (pOpenThread == IntPtr.Zero)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Kernel32.ResumeThread(pOpenThread);
|
||||
Kernel32Api.ResumeThread(pOpenThread);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1395,7 +1391,7 @@ namespace Greenshot.Base.Core
|
|||
/// </summary>
|
||||
public Image PrintWindow()
|
||||
{
|
||||
Rectangle windowRect = WindowRectangle;
|
||||
NativeRect windowRect = WindowRectangle;
|
||||
// Start the capture
|
||||
Exception exceptionOccurred = null;
|
||||
Image returnImage;
|
||||
|
@ -1412,14 +1408,14 @@ namespace Greenshot.Base.Core
|
|||
|
||||
returnImage = ImageHelper.CreateEmpty(windowRect.Width, windowRect.Height, pixelFormat, backgroundColor, 96,96);
|
||||
using Graphics graphics = Graphics.FromImage(returnImage);
|
||||
using (SafeDeviceContextHandle graphicsDc = graphics.GetSafeDeviceContext())
|
||||
using (SafeGraphicsDcHandle graphicsDc = graphics.GetSafeDeviceContext())
|
||||
{
|
||||
var pwFlags = WindowsVersion.IsWindows10OrLater ? PrintWindowFlags.PW_RENDERFULLCONTENT : PrintWindowFlags.PW_ENTIREWINDOW;
|
||||
bool printSucceeded = User32.PrintWindow(Handle, graphicsDc.DangerousGetHandle(), pwFlags);
|
||||
var pwFlags = WindowsVersion.IsWindows10OrLater ? PrintWindowFlags.PW_RENDERFULLCONTENT : PrintWindowFlags.PW_COMPLETE;
|
||||
bool printSucceeded = User32Api.PrintWindow(Handle, graphicsDc.DangerousGetHandle(), pwFlags);
|
||||
if (!printSucceeded)
|
||||
{
|
||||
// something went wrong, most likely a "0x80004005" (Access Denied) when using UAC
|
||||
exceptionOccurred = User32.CreateWin32Exception("PrintWindow");
|
||||
exceptionOccurred = User32Api.CreateWin32Exception("PrintWindow");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1443,10 +1439,9 @@ namespace Greenshot.Base.Core
|
|||
|
||||
if (!HasParent && Maximised)
|
||||
{
|
||||
Log.Debug("Correcting for maximalization");
|
||||
Log.Debug("Correcting for maximized window");
|
||||
GetBorderSize(out var borderSize);
|
||||
Rectangle borderRectangle = new Rectangle(borderSize.Width, borderSize.Height, windowRect.Width - (2 * borderSize.Width),
|
||||
windowRect.Height - (2 * borderSize.Height));
|
||||
NativeRect borderRectangle = new NativeRect(borderSize.Width, borderSize.Height, windowRect.Width - (2 * borderSize.Width), windowRect.Height - (2 * borderSize.Height));
|
||||
ImageHelper.Crop(ref returnImage, ref borderRectangle);
|
||||
}
|
||||
|
||||
|
@ -1469,7 +1464,7 @@ namespace Greenshot.Base.Core
|
|||
/// <returns>WindowDetails of the current window</returns>
|
||||
public static WindowDetails GetActiveWindow()
|
||||
{
|
||||
IntPtr hWnd = User32.GetForegroundWindow();
|
||||
IntPtr hWnd = User32Api.GetForegroundWindow();
|
||||
if (hWnd != IntPtr.Zero)
|
||||
{
|
||||
if (IgnoreHandles.Contains(hWnd))
|
||||
|
@ -1496,7 +1491,7 @@ namespace Greenshot.Base.Core
|
|||
/// <returns>WindowDetails for the desktop window</returns>
|
||||
public static WindowDetails GetDesktopWindow()
|
||||
{
|
||||
return new WindowDetails(User32.GetDesktopWindow());
|
||||
return new WindowDetails(User32Api.GetDesktopWindow());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1520,9 +1515,9 @@ namespace Greenshot.Base.Core
|
|||
/// <summary>
|
||||
/// Recursive "find children which"
|
||||
/// </summary>
|
||||
/// <param name="point">point to check for</param>
|
||||
/// <returns></returns>
|
||||
public WindowDetails FindChildUnderPoint(Point point)
|
||||
/// <param name="point">NativePoint to check for</param>
|
||||
/// <returns>WindowDetails</returns>
|
||||
public WindowDetails FindChildUnderPoint(NativePoint point)
|
||||
{
|
||||
if (!Contains(point))
|
||||
{
|
||||
|
@ -1548,25 +1543,13 @@ namespace Greenshot.Base.Core
|
|||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the classname for a hWnd
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr with the windows handle</param>
|
||||
/// <returns>String with ClassName</returns>
|
||||
public static string GetClassName(IntPtr hWnd)
|
||||
{
|
||||
var classNameBuilder = new StringBuilder(260, 260);
|
||||
User32.GetClassName(hWnd, classNameBuilder, classNameBuilder.Capacity);
|
||||
return classNameBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to decide if a top level window is visible
|
||||
/// </summary>
|
||||
/// <param name="window"></param>
|
||||
/// <param name="screenBounds"></param>
|
||||
/// <returns></returns>
|
||||
private static bool IsVisible(WindowDetails window, Rectangle screenBounds)
|
||||
private static bool IsVisible(WindowDetails window, NativeRect screenBounds)
|
||||
{
|
||||
// Ignore invisible
|
||||
if (!window.Visible)
|
||||
|
@ -1586,8 +1569,7 @@ namespace Greenshot.Base.Core
|
|||
}
|
||||
|
||||
// On windows which are visible on the screen
|
||||
var windowRect = window.WindowRectangle;
|
||||
windowRect.Intersect(screenBounds);
|
||||
var windowRect = window.WindowRectangle.Intersect(screenBounds);
|
||||
if (windowRect.IsEmpty)
|
||||
{
|
||||
return false;
|
||||
|
@ -1609,7 +1591,7 @@ namespace Greenshot.Base.Core
|
|||
/// <returns>List WindowDetails with all the visible top level windows</returns>
|
||||
public static IEnumerable<WindowDetails> GetVisibleWindows()
|
||||
{
|
||||
Rectangle screenBounds = WindowCapture.GetScreenBounds();
|
||||
var screenBounds = DisplayInfo.ScreenBounds;
|
||||
foreach (var window in GetAppWindows())
|
||||
{
|
||||
if (IsVisible(window, screenBounds))
|
||||
|
@ -1640,7 +1622,7 @@ namespace Greenshot.Base.Core
|
|||
yield break;
|
||||
}
|
||||
|
||||
var nextHandle = User32.FindWindow(AppWindowClass, null);
|
||||
var nextHandle = User32Api.FindWindow(AppWindowClass, null);
|
||||
while (nextHandle != IntPtr.Zero)
|
||||
{
|
||||
var metroApp = new WindowDetails(nextHandle);
|
||||
|
@ -1648,14 +1630,14 @@ namespace Greenshot.Base.Core
|
|||
// Check if we have a gutter!
|
||||
if (metroApp.Visible && !metroApp.Maximised)
|
||||
{
|
||||
var gutterHandle = User32.FindWindow(GutterClass, null);
|
||||
var gutterHandle = User32Api.FindWindow(GutterClass, null);
|
||||
if (gutterHandle != IntPtr.Zero)
|
||||
{
|
||||
yield return new WindowDetails(gutterHandle);
|
||||
}
|
||||
}
|
||||
|
||||
nextHandle = User32.FindWindowEx(IntPtr.Zero, nextHandle, AppWindowClass, null);
|
||||
nextHandle = User32Api.FindWindowEx(IntPtr.Zero, nextHandle, AppWindowClass, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1820,7 +1802,7 @@ namespace Greenshot.Base.Core
|
|||
return null;
|
||||
}
|
||||
|
||||
IntPtr appLauncher = User32.FindWindow(ApplauncherClass, null);
|
||||
IntPtr appLauncher = User32Api.FindWindow(ApplauncherClass, null);
|
||||
if (appLauncher != IntPtr.Zero)
|
||||
{
|
||||
return new WindowDetails(appLauncher);
|
||||
|
@ -1862,7 +1844,7 @@ namespace Greenshot.Base.Core
|
|||
result.AppendLine($"IsWin10App: {IsWin10App}");
|
||||
result.AppendLine($"IsApp: {IsApp}");
|
||||
result.AppendLine($"Visible: {Visible}");
|
||||
result.AppendLine($"IsWindowVisible: {User32.IsWindowVisible(Handle)}");
|
||||
result.AppendLine($"IsWindowVisible: {User32Api.IsWindowVisible(Handle)}");
|
||||
result.AppendLine($"IsCloaked: {IsCloaked}");
|
||||
result.AppendLine($"Iconic: {Iconic}");
|
||||
result.AppendLine($"IsBackgroundWin10App: {IsBackgroundWin10App}");
|
||||
|
|
|
@ -21,8 +21,7 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Dapplo.Windows.User32;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
{
|
||||
|
@ -44,15 +43,13 @@ namespace Greenshot.Base.Core
|
|||
public WindowsEnumerator GetWindows(IntPtr hWndParent, string classname)
|
||||
{
|
||||
Items = new List<WindowDetails>();
|
||||
User32.EnumChildWindows(hWndParent, WindowEnum, IntPtr.Zero);
|
||||
User32Api.EnumChildWindows(hWndParent, OnWindowEnum, IntPtr.Zero);
|
||||
|
||||
bool hasParent = !IntPtr.Zero.Equals(hWndParent);
|
||||
string parentText = null;
|
||||
if (hasParent)
|
||||
{
|
||||
var title = new StringBuilder(260, 260);
|
||||
User32.GetWindowText(hWndParent, title, title.Capacity);
|
||||
parentText = title.ToString();
|
||||
parentText = User32Api.GetText(hWndParent);
|
||||
}
|
||||
|
||||
var windows = new List<WindowDetails>();
|
||||
|
@ -74,17 +71,6 @@ namespace Greenshot.Base.Core
|
|||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The enum Windows callback.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">Window Handle</param>
|
||||
/// <param name="lParam">Application defined value</param>
|
||||
/// <returns>1 to continue enumeration, 0 to stop</returns>
|
||||
private int WindowEnum(IntPtr hWnd, int lParam)
|
||||
{
|
||||
return OnWindowEnum(hWnd) ? 1 : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever a new window is about to be added
|
||||
/// by the Window enumeration called from GetWindows.
|
||||
|
@ -94,8 +80,9 @@ namespace Greenshot.Base.Core
|
|||
/// be empty.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">Window handle to add</param>
|
||||
/// <param name="lParam"></param>
|
||||
/// <returns>True to continue enumeration, False to stop</returns>
|
||||
private bool OnWindowEnum(IntPtr hWnd)
|
||||
private bool OnWindowEnum(IntPtr hWnd, IntPtr lParam)
|
||||
{
|
||||
if (!WindowDetails.IsIgnoreHandle(hWnd))
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Dapplo.Windows.Messages.Enumerations;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.Core
|
||||
|
|
|
@ -23,6 +23,7 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Core;
|
||||
|
||||
namespace Greenshot.Base.Effects
|
||||
|
@ -42,7 +43,7 @@ namespace Greenshot.Base.Effects
|
|||
|
||||
public int ShadowSize { get; set; }
|
||||
|
||||
public Point ShadowOffset { get; set; }
|
||||
public NativePoint ShadowOffset { get; set; }
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
|
|
|
@ -5,10 +5,16 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="1.0.16" />
|
||||
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="1.0.18" />
|
||||
<PackageReference Include="Dapplo.Windows.Clipboard" Version="1.0.21" />
|
||||
<PackageReference Include="Dapplo.Windows.Dpi" Version="1.0.21" />
|
||||
<PackageReference Include="Dapplo.Windows.Gdi32" Version="1.0.21" />
|
||||
<PackageReference Include="Dapplo.Windows.Icons" Version="1.0.21" />
|
||||
<PackageReference Include="Dapplo.Windows.Kernel32" Version="1.0.21" />
|
||||
<PackageReference Include="Dapplo.Windows.Multimedia" Version="1.0.21" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
|
||||
<PackageReference Include="log4net" version="2.0.14" />
|
||||
<PackageReference Include="Svg" Version="3.4.0" />
|
||||
<PackageReference Include="Svg" Version="3.4.1" />
|
||||
<Reference Include="Accessibility" />
|
||||
<Reference Include="CustomMarshalers" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.Hooking
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class WindowsEventHook : IDisposable
|
||||
{
|
||||
private readonly WinEventDelegate _winEventHandler;
|
||||
private GCHandle _gcHandle;
|
||||
|
||||
/// <summary>
|
||||
/// Used with Register hook
|
||||
/// </summary>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="idObject"></param>
|
||||
/// <param name="idChild"></param>
|
||||
/// <param name="dwEventThread"></param>
|
||||
/// <param name="dwmsEventTime"></param>
|
||||
public delegate void WinEventHandler(WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
|
||||
|
||||
/// <summary>
|
||||
/// Create a WindowsEventHook object
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Used with SetWinEventHook
|
||||
/// </summary>
|
||||
/// <param name="hWinEventHook"></param>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="idObject"></param>
|
||||
/// <param name="idChild"></param>
|
||||
/// <param name="dwEventThread"></param>
|
||||
/// <param name="dwmsEventTime"></param>
|
||||
private delegate void WinEventDelegate(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
|
||||
|
||||
private readonly IDictionary<IntPtr, WinEventHandler> _winEventHandlers = new Dictionary<IntPtr, WinEventHandler>();
|
||||
|
||||
/// <summary>
|
||||
/// Are hooks active?
|
||||
/// </summary>
|
||||
public bool IsHooked => _winEventHandlers.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Hook a WinEvent
|
||||
/// </summary>
|
||||
/// <param name="winEvent"></param>
|
||||
/// <param name="winEventHandler"></param>
|
||||
/// <returns>true if success</returns>
|
||||
public void Hook(WinEvent winEvent, WinEventHandler winEventHandler)
|
||||
{
|
||||
Hook(winEvent, winEvent, winEventHandler);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hook a WinEvent
|
||||
/// </summary>
|
||||
/// <param name="winEventStart"></param>
|
||||
/// <param name="winEventEnd"></param>
|
||||
/// <param name="winEventHandler"></param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all hooks
|
||||
/// </summary>
|
||||
private void Unhook()
|
||||
{
|
||||
foreach (var hookPtr in _winEventHandlers.Keys)
|
||||
{
|
||||
if (hookPtr != IntPtr.Zero)
|
||||
{
|
||||
UnhookWinEvent(hookPtr);
|
||||
}
|
||||
}
|
||||
|
||||
_winEventHandlers.Clear();
|
||||
_gcHandle.Free();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Unhook();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call the WinEventHandler for this event
|
||||
/// </summary>
|
||||
/// <param name="hWinEventHook"></param>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="idObject"></param>
|
||||
/// <param name="idChild"></param>
|
||||
/// <param name="dwEventThread"></param>
|
||||
/// <param name="dwmsEventTime"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Greenshot.Base.Core;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.Hooking
|
||||
{
|
||||
/// <summary>
|
||||
/// Event arguments for the WindowOpenCloseEvent
|
||||
/// </summary>
|
||||
public class WindowOpenCloseEventArgs : EventArgs
|
||||
{
|
||||
public bool IsOpen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HWnd of the window which has a changed title
|
||||
/// </summary>
|
||||
public IntPtr HWnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Title which is changed
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
public string ClassName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for the window open close event
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
public delegate void WindowOpenCloseEventDelegate(WindowOpenCloseEventArgs eventArgs);
|
||||
|
||||
/// <summary>
|
||||
/// Monitor all new and destroyed windows
|
||||
/// </summary>
|
||||
public sealed class WindowsOpenCloseMonitor : IDisposable
|
||||
{
|
||||
private WindowsEventHook _hook;
|
||||
private readonly object _lockObject = new object();
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private event WindowOpenCloseEventDelegate _windowOpenCloseEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Add / remove event handler to the title monitor
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WinEventDelegate for the creation and destruction
|
||||
/// </summary>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="idObject"></param>
|
||||
/// <param name="idChild"></param>
|
||||
/// <param name="dwEventThread"></param>
|
||||
/// <param name="dwmsEventTime"></param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the underlying hook
|
||||
/// </summary>
|
||||
public void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposedValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
_hook?.Dispose();
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make sure the finalizer disposes the underlying hook
|
||||
/// </summary>
|
||||
~WindowsOpenCloseMonitor()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the underlying hook
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Greenshot.Base.Core;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.Hooking
|
||||
{
|
||||
/// <summary>
|
||||
/// Event arguments for the TitleChangeEvent
|
||||
/// </summary>
|
||||
public class TitleChangeEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// HWnd of the window which has a changed title
|
||||
/// </summary>
|
||||
public IntPtr HWnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Title which is changed
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for the title change event
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
public delegate void TitleChangeEventDelegate(TitleChangeEventArgs eventArgs);
|
||||
|
||||
/// <summary>
|
||||
/// Monitor all title changes
|
||||
/// </summary>
|
||||
public sealed class WindowsTitleMonitor : IDisposable
|
||||
{
|
||||
private WindowsEventHook _hook;
|
||||
private readonly object _lockObject = new object();
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private event TitleChangeEventDelegate _titleChangeEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Add / remove event handler to the title monitor
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WinEventDelegate for the creation & destruction
|
||||
/// </summary>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="idObject"></param>
|
||||
/// <param name="idChild"></param>
|
||||
/// <param name="dwEventThread"></param>
|
||||
/// <param name="dwmsEventTime"></param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the underlying hook
|
||||
/// </summary>
|
||||
public void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposedValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_lockObject)
|
||||
{
|
||||
_hook?.Dispose();
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make sure the finalizer disposes the underlying hook
|
||||
/// </summary>
|
||||
~WindowsTitleMonitor()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose the underlying hook
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Interfaces.Drawing.Adorners
|
||||
{
|
||||
|
@ -35,7 +36,7 @@ namespace Greenshot.Base.Interfaces.Drawing.Adorners
|
|||
/// <summary>
|
||||
/// These are the bounds of the adorner
|
||||
/// </summary>
|
||||
Rectangle Bounds { get; }
|
||||
NativeRect Bounds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The current edit status, this is needed to locate the adorner to send events to
|
||||
|
@ -53,7 +54,7 @@ namespace Greenshot.Base.Interfaces.Drawing.Adorners
|
|||
/// </summary>
|
||||
/// <param name="point">Point to test</param>
|
||||
/// <returns>true if so</returns>
|
||||
bool HitTest(Point point);
|
||||
bool HitTest(NativePoint point);
|
||||
|
||||
/// <summary>
|
||||
/// Handle the MouseDown event
|
||||
|
@ -97,7 +98,7 @@ namespace Greenshot.Base.Interfaces.Drawing.Adorners
|
|||
/// Adjust UI elements to the supplied DPI settings
|
||||
/// </summary>
|
||||
/// <param name="dpi"></param>
|
||||
void AdjustToDpi(uint dpi);
|
||||
void AdjustToDpi(int dpi);
|
||||
|
||||
/// <summary>
|
||||
/// The color of the lines around the adorner
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces.Drawing.Adorners;
|
||||
|
||||
namespace Greenshot.Base.Interfaces.Drawing
|
||||
|
@ -49,15 +49,15 @@ namespace Greenshot.Base.Interfaces.Drawing
|
|||
|
||||
int Height { get; set; }
|
||||
|
||||
Point Location { get; }
|
||||
NativePoint Location { get; }
|
||||
|
||||
Size Size { get; }
|
||||
NativeSize Size { get; }
|
||||
|
||||
Rectangle Bounds { get; }
|
||||
NativeRect Bounds { get; }
|
||||
|
||||
Rectangle DrawingBounds { get; }
|
||||
NativeRect DrawingBounds { get; }
|
||||
|
||||
void ApplyBounds(RectangleF newBounds);
|
||||
void ApplyBounds(NativeRectFloat newBounds);
|
||||
|
||||
bool HasFilters { get; }
|
||||
|
||||
|
@ -101,8 +101,8 @@ namespace Greenshot.Base.Interfaces.Drawing
|
|||
/// <summary>
|
||||
/// Adjust UI elements to the supplied DPI settings
|
||||
/// </summary>
|
||||
/// <param name="dpi">uint</param>
|
||||
void AdjustToDpi(uint dpi);
|
||||
/// <param name="dpi">int</param>
|
||||
void AdjustToDpi(int dpi);
|
||||
|
||||
/// <summary>
|
||||
/// Enable a way for elements to add a context menu entry
|
||||
|
|
|
@ -24,6 +24,7 @@ using System.Collections.Generic;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Interfaces.Drawing
|
||||
{
|
||||
|
@ -35,16 +36,16 @@ namespace Greenshot.Base.Interfaces.Drawing
|
|||
|
||||
ISurface Parent { get; set; }
|
||||
EditStatus Status { get; set; }
|
||||
Rectangle DrawingBounds { get; }
|
||||
NativeRect DrawingBounds { get; }
|
||||
void MakeBoundsChangeUndoable(bool allowMerge);
|
||||
void Transform(Matrix matrix);
|
||||
void MoveBy(int dx, int dy);
|
||||
bool ClickableAt(int x, int y);
|
||||
IDrawableContainer ClickableElementAt(int x, int y);
|
||||
void OnDoubleClick();
|
||||
bool HasIntersectingFilters(Rectangle clipRectangle);
|
||||
bool IntersectsWith(Rectangle clipRectangle);
|
||||
void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, Rectangle clipRectangle);
|
||||
bool HasIntersectingFilters(NativeRect clipRectangle);
|
||||
bool IntersectsWith(NativeRect clipRectangle);
|
||||
void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, NativeRect clipRectangle);
|
||||
void SetForegroundColor(Color color);
|
||||
void SetBackgroundColor(Color color);
|
||||
int IncreaseLineThickness(int increaseBy);
|
||||
|
@ -58,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);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Interfaces
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ namespace Greenshot.Base.Interfaces
|
|||
/// <summary>
|
||||
/// Bounds on the screen from which the capture comes
|
||||
/// </summary>
|
||||
Rectangle ScreenBounds { get; set; }
|
||||
NativeRect ScreenBounds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The cursor
|
||||
|
@ -62,18 +63,18 @@ namespace Greenshot.Base.Interfaces
|
|||
/// <summary>
|
||||
/// Location of the cursor
|
||||
/// </summary>
|
||||
Point CursorLocation { get; set; }
|
||||
NativePoint CursorLocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Location of the capture
|
||||
/// </summary>
|
||||
Point Location { get; set; }
|
||||
NativePoint Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Crops the capture to the specified rectangle (with Bitmap coordinates!)
|
||||
/// </summary>
|
||||
/// <param name="cropRectangle">Rectangle with bitmap coordinates</param>
|
||||
bool Crop(Rectangle cropRectangle);
|
||||
/// <param name="cropRectangle">NativeRect with bitmap coordinates</param>
|
||||
bool Crop(NativeRect cropRectangle);
|
||||
|
||||
/// <summary>
|
||||
/// Apply a translate to the mouse location. e.g. needed for crop
|
||||
|
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
namespace Greenshot.Base.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Used with EnumWindows or EnumChildWindows
|
||||
/// IProvideDeviceDpi can provide the current DPI for a component
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr</param>
|
||||
/// <param name="lParam">int</param>
|
||||
/// <returns>int</returns>
|
||||
public delegate int EnumWindowsProc(IntPtr hWnd, int lParam);
|
||||
public interface IProvideDeviceDpi
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple getter for the current DPI
|
||||
/// </summary>
|
||||
int DeviceDpi { get; }
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ using System.Drawing;
|
|||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Core;
|
||||
using Greenshot.Base.Effects;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
|
@ -185,8 +186,8 @@ namespace Greenshot.Base.Interfaces
|
|||
/// Invalidates the specified region of the Surface.
|
||||
/// Takes care of the Surface zoom level, accepts rectangle in the coordinate space of the Image.
|
||||
/// </summary>
|
||||
/// <param name="rectangleToInvalidate">Bounding rectangle for updated elements, in the coordinate space of the Image.</param>
|
||||
void InvalidateElements(Rectangle rectangleToInvalidate);
|
||||
/// <param name="rectangleToInvalidate">NativeRect Bounding rectangle for updated elements, in the coordinate space of the Image.</param>
|
||||
void InvalidateElements(NativeRect rectangleToInvalidate);
|
||||
|
||||
bool Modified { get; set; }
|
||||
string LastSaveFullPath { get; set; }
|
||||
|
@ -214,28 +215,28 @@ namespace Greenshot.Base.Interfaces
|
|||
Fraction ZoomFactor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Translate a point from image coorditate space to surface coordinate space.
|
||||
/// Translate a point from image coordinate space to surface coordinate space.
|
||||
/// </summary>
|
||||
/// <param name="point">A point in the coordinate space of the image.</param>
|
||||
Point ToSurfaceCoordinates(Point point);
|
||||
NativePoint ToSurfaceCoordinates(NativePoint point);
|
||||
|
||||
/// <summary>
|
||||
/// Translate a rectangle from image coorditate space to surface coordinate space.
|
||||
/// Translate a rectangle from image coordinate space to surface coordinate space.
|
||||
/// </summary>
|
||||
/// <param name="rc">A rectangle in the coordinate space of the image.</param>
|
||||
Rectangle ToSurfaceCoordinates(Rectangle rc);
|
||||
/// <param name="rc">NativeRect in the coordinate space of the image.</param>
|
||||
NativeRect ToSurfaceCoordinates(NativeRect rc);
|
||||
|
||||
/// <summary>
|
||||
/// Translate a point from surface coorditate space to image coordinate space.
|
||||
/// Translate a point from surface coordinate space to image coordinate space.
|
||||
/// </summary>
|
||||
/// <param name="point">A point in the coordinate space of the surface.</param>
|
||||
Point ToImageCoordinates(Point point);
|
||||
/// <param name="point">NativePoint in the coordinate space of the surface.</param>
|
||||
NativePoint ToImageCoordinates(NativePoint point);
|
||||
|
||||
/// <summary>
|
||||
/// Translate a rectangle from surface coorditate space to image coordinate space.
|
||||
/// Translate a NativeRect from surface coordinate space to image coordinate space.
|
||||
/// </summary>
|
||||
/// <param name="rc">A rectangle in the coordinate space of the surface.</param>
|
||||
Rectangle ToImageCoordinates(Rectangle rc);
|
||||
/// <param name="rc">NativeRect in the coordinate space of the surface.</param>
|
||||
NativeRect ToImageCoordinates(NativeRect rc);
|
||||
|
||||
/// <summary>
|
||||
/// Make it possible to undo the specified IMemento
|
||||
|
|
|
@ -1,4 +1,26 @@
|
|||
using System.Drawing;
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Interfaces.Ocr
|
||||
{
|
||||
|
@ -7,7 +29,7 @@ namespace Greenshot.Base.Interfaces.Ocr
|
|||
/// </summary>
|
||||
public class Line
|
||||
{
|
||||
private Rectangle? _calculatedBounds;
|
||||
private NativeRect? _calculatedBounds;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor will preallocate the number of words
|
||||
|
@ -35,18 +57,18 @@ namespace Greenshot.Base.Interfaces.Ocr
|
|||
/// <summary>
|
||||
/// Calculate the bounds of the words
|
||||
/// </summary>
|
||||
/// <returns>Rectangle</returns>
|
||||
private Rectangle CalculateBounds()
|
||||
/// <returns>NativeRect</returns>
|
||||
private NativeRect CalculateBounds()
|
||||
{
|
||||
if (Words.Length == 0)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
return NativeRect.Empty;
|
||||
}
|
||||
|
||||
var result = Words[0].Bounds;
|
||||
for (var index = 0; index < Words.Length; index++)
|
||||
{
|
||||
result = Rectangle.Union(result, Words[index].Bounds);
|
||||
result = result.Union(Words[index].Bounds);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -55,7 +77,7 @@ namespace Greenshot.Base.Interfaces.Ocr
|
|||
/// <summary>
|
||||
/// Return the calculated bounds for the whole line
|
||||
/// </summary>
|
||||
public Rectangle CalculatedBounds
|
||||
public NativeRect CalculatedBounds
|
||||
{
|
||||
get { return _calculatedBounds ??= CalculateBounds(); }
|
||||
}
|
||||
|
@ -69,9 +91,7 @@ namespace Greenshot.Base.Interfaces.Ocr
|
|||
{
|
||||
foreach (var word in Words)
|
||||
{
|
||||
var location = word.Bounds;
|
||||
location.Offset(x, y);
|
||||
word.Bounds = location;
|
||||
word.Bounds = word.Bounds.Offset(x, y);
|
||||
}
|
||||
|
||||
_calculatedBounds = null;
|
||||
|
|
|
@ -1,4 +1,25 @@
|
|||
using System.Collections.Generic;
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
|
|
|
@ -1,4 +1,25 @@
|
|||
using System.Drawing;
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Base.Interfaces.Ocr
|
||||
{
|
||||
|
@ -15,6 +36,6 @@ namespace Greenshot.Base.Interfaces.Ocr
|
|||
/// <summary>
|
||||
/// The bounds of the word
|
||||
/// </summary>
|
||||
public Rectangle Bounds { get; set; }
|
||||
public NativeRect Bounds { get; set; }
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Greenshot.Base.Interfaces
|
||||
{
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Greenshot.Base.Interfaces
|
||||
{
|
||||
|
|
|
@ -1,123 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Base.Core;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Desktop Window Manager helper code
|
||||
/// </summary>
|
||||
public static class DWM
|
||||
{
|
||||
// DWM
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb);
|
||||
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern int DwmUnregisterThumbnail(IntPtr thumb);
|
||||
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern HResult DwmQueryThumbnailSourceSize(IntPtr thumb, out SIZE size);
|
||||
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern HResult DwmUpdateThumbnailProperties(IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props);
|
||||
|
||||
// Deprecated as of Windows 8 Release Preview
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern int DwmIsCompositionEnabled(out bool enabled);
|
||||
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern int DwmGetWindowAttribute(IntPtr hWnd, DWMWINDOWATTRIBUTE dwAttribute, out RECT lpRect, int size);
|
||||
|
||||
[DllImport("dwmapi", SetLastError = true)]
|
||||
public static extern int DwmGetWindowAttribute(IntPtr hWnd, DWMWINDOWATTRIBUTE dwAttribute, out bool pvAttribute, int cbAttribute);
|
||||
|
||||
// Key to ColorizationColor for DWM
|
||||
private const string COLORIZATION_COLOR_KEY = @"SOFTWARE\Microsoft\Windows\DWM";
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the window is cloaked, this should solve some issues with the window selection code
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr as hWmd</param>
|
||||
/// <returns>bool</returns>
|
||||
public static bool IsWindowCloaked(IntPtr hWnd)
|
||||
{
|
||||
if (!WindowsVersion.IsWindows8OrLater)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DwmGetWindowAttribute(hWnd, DWMWINDOWATTRIBUTE.DWMWA_CLOAKED, out bool isCloaked, Marshal.SizeOf(typeof(bool)));
|
||||
return isCloaked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method for an easy DWM check
|
||||
/// </summary>
|
||||
/// <returns>bool true if DWM is available AND active</returns>
|
||||
public static bool IsDwmEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
// According to: https://technet.microsoft.com/en-us/subscriptions/aa969538%28v=vs.85%29.aspx
|
||||
// And: https://docs.microsoft.com/en-gb/windows/win32/api/dwmapi/nf-dwmapi-dwmenablecomposition
|
||||
// DMW is always enabled on Windows 8! So return true and save a check! ;-)
|
||||
if (WindowsVersion.IsWindows8OrLater)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WindowsVersion.IsWindowsVistaOrLater)
|
||||
{
|
||||
DwmIsCompositionEnabled(out var dwmEnabled);
|
||||
return dwmEnabled;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color ColorizationColor
|
||||
{
|
||||
get
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(COLORIZATION_COLOR_KEY, false))
|
||||
{
|
||||
object dwordValue = key?.GetValue("ColorizationColor");
|
||||
if (dwordValue != null)
|
||||
{
|
||||
return Color.FromArgb((int) dwordValue);
|
||||
}
|
||||
}
|
||||
|
||||
return Color.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum ClassLongIndex
|
||||
{
|
||||
GCL_HICON = -14, // a handle to the icon associated with the class.
|
||||
GCL_HICONSM = -34, // a handle to the small icon associated with the class.
|
||||
}
|
||||
}
|
|
@ -1,46 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum DWMWINDOWATTRIBUTE : uint
|
||||
{
|
||||
DWMWA_NCRENDERING_ENABLED = 1,
|
||||
DWMWA_NCRENDERING_POLICY,
|
||||
DWMWA_TRANSITIONS_FORCEDISABLED,
|
||||
DWMWA_ALLOW_NCPAINT,
|
||||
DWMWA_CAPTION_BUTTON_BOUNDS,
|
||||
DWMWA_NONCLIENT_RTL_LAYOUT,
|
||||
DWMWA_FORCE_ICONIC_REPRESENTATION,
|
||||
DWMWA_FLIP3D_POLICY,
|
||||
DWMWA_EXTENDED_FRAME_BOUNDS, // This is the one we need for retrieving the Window size since Windows Vista
|
||||
DWMWA_HAS_ICONIC_BITMAP, // Since Windows 7
|
||||
DWMWA_DISALLOW_PEEK, // Since Windows 7
|
||||
DWMWA_EXCLUDED_FROM_PEEK, // Since Windows 7
|
||||
DWMWA_CLOAK, // Since Windows 8
|
||||
DWMWA_CLOAKED, // Since Windows 8
|
||||
DWMWA_FREEZE_REPRESENTATION, // Since Windows 8
|
||||
DWMWA_LAST
|
||||
}
|
||||
}
|
|
@ -1,111 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// See <a href="https://docs.microsoft.com/en-gb/windows/win32/api/dwmapi/ns-dwmapi-dwm_thumbnail_properties">DWM_THUMBNAIL_PROPERTIES</a>
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DWM_THUMBNAIL_PROPERTIES
|
||||
{
|
||||
// A bitwise combination of DWM thumbnail constant values that indicates which members of this structure are set.
|
||||
public int dwFlags;
|
||||
|
||||
// The area in the destination window where the thumbnail will be rendered.
|
||||
public RECT rcDestination;
|
||||
|
||||
// The region of the source window to use as the thumbnail. By default, the entire window is used as the thumbnail.
|
||||
public RECT rcSource;
|
||||
|
||||
// The opacity with which to render the thumbnail. 0 is fully transparent while 255 is fully opaque. The default value is 255.
|
||||
public byte opacity;
|
||||
|
||||
// TRUE to make the thumbnail visible; otherwise, FALSE. The default is FALSE.
|
||||
public bool fVisible;
|
||||
|
||||
// TRUE to use only the thumbnail source's client area; otherwise, FALSE. The default is FALSE.
|
||||
public bool fSourceClientAreaOnly;
|
||||
|
||||
public RECT Destination
|
||||
{
|
||||
set
|
||||
{
|
||||
dwFlags |= DWM_TNP_RECTDESTINATION;
|
||||
rcDestination = value;
|
||||
}
|
||||
}
|
||||
|
||||
public RECT Source
|
||||
{
|
||||
set
|
||||
{
|
||||
dwFlags |= DWM_TNP_RECTSOURCE;
|
||||
rcSource = value;
|
||||
}
|
||||
}
|
||||
|
||||
public byte Opacity
|
||||
{
|
||||
set
|
||||
{
|
||||
dwFlags |= DWM_TNP_OPACITY;
|
||||
opacity = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Visible
|
||||
{
|
||||
set
|
||||
{
|
||||
dwFlags |= DWM_TNP_VISIBLE;
|
||||
fVisible = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SourceClientAreaOnly
|
||||
{
|
||||
set
|
||||
{
|
||||
dwFlags |= DWM_TNP_SOURCECLIENTAREAONLY;
|
||||
fSourceClientAreaOnly = value;
|
||||
}
|
||||
}
|
||||
|
||||
// A value for the rcDestination member has been specified.
|
||||
public const int DWM_TNP_RECTDESTINATION = 0x00000001;
|
||||
|
||||
// A value for the rcSource member has been specified.
|
||||
public const int DWM_TNP_RECTSOURCE = 0x00000002;
|
||||
|
||||
// A value for the opacity member has been specified.
|
||||
public const int DWM_TNP_OPACITY = 0x00000004;
|
||||
|
||||
// A value for the fVisible member has been specified.
|
||||
public const int DWM_TNP_VISIBLE = 0x00000008;
|
||||
|
||||
// A value for the fSourceClientAreaOnly member has been specified.
|
||||
public const int DWM_TNP_SOURCECLIENTAREAONLY = 0x00000010;
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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)
|
||||
};
|
||||
}
|
|
@ -1,43 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Used by GDI32.GetDeviceCaps
|
||||
/// See <a href="https://docs.microsoft.com/en-gb/windows/win32/api/wingdi/nf-wingdi-getdevicecaps">GetDeviceCaps</a>
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum DeviceCaps
|
||||
{
|
||||
/// <summary>
|
||||
/// Logical pixels inch in X
|
||||
/// </summary>
|
||||
LOGPIXELSX = 88,
|
||||
|
||||
/// <summary>
|
||||
/// Current vertical refresh rate of the display device (for displays only) in Hz
|
||||
/// </summary>
|
||||
VREFRESH = 116
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// See <a href="https://docs.microsoft.com/en-gb/windows/win32/winauto/object-identifiers">Object Identifiers</a>
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum EventObjects
|
||||
{
|
||||
OBJID_WINDOW = 0
|
||||
}
|
||||
}
|
|
@ -1,71 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum ExtendedWindowStyleFlags : uint
|
||||
{
|
||||
WS_EX_DLGMODALFRAME = 0x00000001,
|
||||
WS_EX_NOPARENTNOTIFY = 0x00000004,
|
||||
WS_EX_TOPMOST = 0x00000008,
|
||||
WS_EX_ACCEPTFILES = 0x00000010,
|
||||
WS_EX_TRANSPARENT = 0x00000020,
|
||||
|
||||
//#if(WINVER >= 0x0400)
|
||||
WS_EX_MDICHILD = 0x00000040,
|
||||
WS_EX_TOOLWINDOW = 0x00000080,
|
||||
WS_EX_WINDOWEDGE = 0x00000100,
|
||||
WS_EX_CLIENTEDGE = 0x00000200,
|
||||
WS_EX_CONTEXTHELP = 0x00000400,
|
||||
|
||||
WS_EX_RIGHT = 0x00001000,
|
||||
WS_EX_LEFT = 0x00000000,
|
||||
WS_EX_RTLREADING = 0x00002000,
|
||||
WS_EX_LTRREADING = 0x00000000,
|
||||
WS_EX_LEFTSCROLLBAR = 0x00004000,
|
||||
WS_EX_RIGHTSCROLLBAR = 0x00000000,
|
||||
|
||||
WS_EX_CONTROLPARENT = 0x00010000,
|
||||
WS_EX_STATICEDGE = 0x00020000,
|
||||
WS_EX_APPWINDOW = 0x00040000,
|
||||
|
||||
//WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE),
|
||||
//WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST),
|
||||
|
||||
WS_EX_LAYERED = 0x00080000,
|
||||
WS_EX_NOINHERITLAYOUT = 0x00100000, // Disable inheritence of mirroring by children
|
||||
WS_EX_NOREDIRECTIONBITMAP = 0x00200000, //The window does not render to a redirection surface. This is for windows that do not have visible content or that use mechanisms other than surfaces to provide their visual.
|
||||
WS_EX_LAYOUTRTL = 0x00400000, // Right to left mirroring
|
||||
/// <summary>
|
||||
/// Paints all descendants of a window in bottom-to-top painting order using double-buffering.
|
||||
/// Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set.
|
||||
/// Double-buffering allows the window and its descendents to be painted without flicker.
|
||||
/// This cannot be used if the window has a class style of either CS_OWNDC or CS_CLASSDC.
|
||||
/// </summary>
|
||||
WS_EX_COMPOSITED = 0x02000000,
|
||||
WS_EX_NOACTIVATE = 0x08000000 // A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window.
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum ProcessAccessFlags : uint
|
||||
{
|
||||
VMRead = 0x00000010,
|
||||
QueryInformation = 0x00000400,
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum RegionResult
|
||||
{
|
||||
REGION_ERROR = 0,
|
||||
REGION_NULLREGION = 1,
|
||||
SIMPLEREGION = 2,
|
||||
COMPLEXREGION = 3
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// See: https://www.pinvoke.net/default.aspx/Enums/SendMessageTimeoutFlags.html
|
||||
/// </summary>
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum SendMessageTimeoutFlags : uint
|
||||
{
|
||||
SMTO_NORMAL = 0x0
|
||||
}
|
||||
}
|
|
@ -1,110 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum ShowWindowCommand : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Hides the window and activates another window.
|
||||
/// </summary>
|
||||
Hide = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Activates and displays a window. If the window is minimized or
|
||||
/// maximized, the system restores it to its original size and position.
|
||||
/// An application should specify this flag when displaying the window
|
||||
/// for the first time.
|
||||
/// </summary>
|
||||
Normal = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Activates the window and displays it as a minimized window.
|
||||
/// </summary>
|
||||
ShowMinimized = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Maximizes the specified window.
|
||||
/// </summary>
|
||||
Maximize = 3, // is this the right value?
|
||||
|
||||
/// <summary>
|
||||
/// Activates the window and displays it as a maximized window.
|
||||
/// </summary>
|
||||
ShowMaximized = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Displays a window in its most recent size and position. This value
|
||||
/// is similar to <see cref="Normal"/>, except
|
||||
/// the window is not actived.
|
||||
/// </summary>
|
||||
ShowNoActivate = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Activates the window and displays it in its current size and position.
|
||||
/// </summary>
|
||||
Show = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Minimizes the specified window and activates the next top-level
|
||||
/// window in the Z order.
|
||||
/// </summary>
|
||||
Minimize = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Displays the window as a minimized window. This value is similar to
|
||||
/// <see cref="ShowMinimized"/>, except the
|
||||
/// window is not activated.
|
||||
/// </summary>
|
||||
ShowMinNoActive = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Displays the window in its current size and position. This value is
|
||||
/// similar to <see cref="Show"/>, except the
|
||||
/// window is not activated.
|
||||
/// </summary>
|
||||
ShowNA = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Activates and displays the window. If the window is minimized or
|
||||
/// maximized, the system restores it to its original size and position.
|
||||
/// An application should specify this flag when restoring a minimized window.
|
||||
/// </summary>
|
||||
Restore = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Sets the show state based on the SW_* value specified in the
|
||||
/// STARTUPINFO structure passed to the CreateProcess function by the
|
||||
/// program that started the application.
|
||||
/// </summary>
|
||||
ShowDefault = 10,
|
||||
|
||||
/// <summary>
|
||||
/// <b>Windows 2000/XP:</b> Minimizes a window, even if the thread
|
||||
/// that owns the window is not responding. This flag should only be
|
||||
/// used when minimizing windows from a different thread.
|
||||
/// </summary>
|
||||
ForceMinimize = 11
|
||||
}
|
||||
}
|
|
@ -1,39 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// See: https://msdn.microsoft.com/en-us/library/aa909766.aspx
|
||||
/// </summary>
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum SoundFlags
|
||||
{
|
||||
SND_ASYNC = 0x0001, // play asynchronously
|
||||
SND_MEMORY = 0x0004, // pszSound points to a memory file
|
||||
SND_NOSTOP = 0x0010, // don't stop any currently playing sound
|
||||
SND_NOWAIT = 0x00002000, // don't wait if the driver is busy
|
||||
}
|
||||
}
|
|
@ -1,31 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[Flags]
|
||||
public enum ThreadAccess : int
|
||||
{
|
||||
SUSPEND_RESUME = (0x0002),
|
||||
}
|
||||
}
|
|
@ -1,89 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// A Win32 error code.
|
||||
/// </summary>
|
||||
public enum Win32Error : uint
|
||||
{
|
||||
Success = 0x0,
|
||||
InvalidFunction = 0x1,
|
||||
FileNotFound = 0x2,
|
||||
PathNotFound = 0x3,
|
||||
TooManyOpenFiles = 0x4,
|
||||
AccessDenied = 0x5,
|
||||
InvalidHandle = 0x6,
|
||||
ArenaTrashed = 0x7,
|
||||
NotEnoughMemory = 0x8,
|
||||
InvalidBlock = 0x9,
|
||||
BadEnvironment = 0xa,
|
||||
BadFormat = 0xb,
|
||||
InvalidAccess = 0xc,
|
||||
InvalidData = 0xd,
|
||||
OutOfMemory = 0xe,
|
||||
InvalidDrive = 0xf,
|
||||
CurrentDirectory = 0x10,
|
||||
NotSameDevice = 0x11,
|
||||
NoMoreFiles = 0x12,
|
||||
WriteProtect = 0x13,
|
||||
BadUnit = 0x14,
|
||||
NotReady = 0x15,
|
||||
BadCommand = 0x16,
|
||||
Crc = 0x17,
|
||||
BadLength = 0x18,
|
||||
Seek = 0x19,
|
||||
NotDosDisk = 0x1a,
|
||||
SectorNotFound = 0x1b,
|
||||
OutOfPaper = 0x1c,
|
||||
WriteFault = 0x1d,
|
||||
ReadFault = 0x1e,
|
||||
GenFailure = 0x1f,
|
||||
SharingViolation = 0x20,
|
||||
LockViolation = 0x21,
|
||||
WrongDisk = 0x22,
|
||||
SharingBufferExceeded = 0x24,
|
||||
HandleEof = 0x26,
|
||||
HandleDiskFull = 0x27,
|
||||
NotSupported = 0x32,
|
||||
RemNotList = 0x33,
|
||||
DupName = 0x34,
|
||||
BadNetPath = 0x35,
|
||||
NetworkBusy = 0x36,
|
||||
DevNotExist = 0x37,
|
||||
TooManyCmds = 0x38,
|
||||
FileExists = 0x50,
|
||||
CannotMake = 0x52,
|
||||
AlreadyAssigned = 0x55,
|
||||
InvalidPassword = 0x56,
|
||||
InvalidParameter = 0x57,
|
||||
NetWriteFault = 0x58,
|
||||
NoProcSlots = 0x59,
|
||||
TooManySemaphores = 0x64,
|
||||
ExclSemAlreadyOwned = 0x65,
|
||||
SemIsSet = 0x66,
|
||||
TooManySemRequests = 0x67,
|
||||
InvalidAtInterruptTime = 0x68,
|
||||
SemOwnerDied = 0x69,
|
||||
SemUserLimit = 0x6a
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for User32.SetWinEventHook
|
||||
/// See MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum WinEvent : uint
|
||||
{
|
||||
EVENT_OBJECT_CREATE = 32768,
|
||||
EVENT_OBJECT_DESTROY = 32769,
|
||||
EVENT_OBJECT_NAMECHANGE = 32780,
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for User32.SetWinEventHook
|
||||
/// See: https://msdn.microsoft.com/en-us/library/windows/desktop/dd373640%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming"), Flags]
|
||||
public enum WinEventHookFlags
|
||||
{
|
||||
WINEVENT_SKIPOWNTHREAD = 1,
|
||||
WINEVENT_SKIPOWNPROCESS = 2,
|
||||
WINEVENT_OUTOFCONTEXT = 0,
|
||||
WINEVENT_INCONTEXT = 4
|
||||
}
|
||||
}
|
|
@ -1,32 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum WindowLongIndex
|
||||
{
|
||||
GWL_EXSTYLE = -20, // Sets a new extended window style.
|
||||
GWL_STYLE = -16, // Sets a new window style.
|
||||
}
|
||||
}
|
|
@ -1,42 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum WindowPlacementFlags : uint
|
||||
{
|
||||
// The coordinates of the minimized window may be specified.
|
||||
// This flag must be specified if the coordinates are set in the ptMinPosition member.
|
||||
WPF_SETMINPOSITION = 0x0001,
|
||||
|
||||
// If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.
|
||||
WPF_ASYNCWINDOWPLACEMENT = 0x0004,
|
||||
|
||||
// The restored window will be maximized, regardless of whether it was maximized before it was minimized. This setting is only valid the next time the window is restored. It does not change the default restoration behavior.
|
||||
// This flag is only valid when the SW_SHOWMINIMIZED value is specified for the showCmd member.
|
||||
WPF_RESTORETOMAXIMIZED = 0x0002
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum WindowPos
|
||||
{
|
||||
SWP_NOACTIVATE =
|
||||
0x0010, // Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
|
||||
SWP_NOMOVE = 0x0002, //Retains the current position (ignores X and Y parameters).
|
||||
SWP_NOSIZE = 0x0001, // Retains the current size (ignores the cx and cy parameters).
|
||||
}
|
||||
}
|
|
@ -1,52 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// Window Style Flags
|
||||
/// </summary>
|
||||
[Flags]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum WindowStyleFlags : int
|
||||
{
|
||||
//WS_OVERLAPPED = 0x00000000,
|
||||
WS_POPUP = -2147483648, // 0x80000000
|
||||
WS_CHILD = 0x40000000,
|
||||
WS_MINIMIZE = 0x20000000,
|
||||
WS_VISIBLE = 0x10000000,
|
||||
WS_DISABLED = 0x08000000,
|
||||
WS_CLIPSIBLINGS = 0x04000000,
|
||||
WS_CLIPCHILDREN = 0x02000000,
|
||||
WS_MAXIMIZE = 0x01000000,
|
||||
WS_BORDER = 0x00800000,
|
||||
WS_DLGFRAME = 0x00400000,
|
||||
WS_VSCROLL = 0x00200000,
|
||||
WS_HSCROLL = 0x00100000,
|
||||
WS_SYSMENU = 0x00080000,
|
||||
WS_THICKFRAME = 0x00040000,
|
||||
WS_GROUP = 0x00020000,
|
||||
WS_TABSTOP = 0x00010000
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// All possible windows messages
|
||||
/// See also <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#system_defined">here</a>
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
public enum WindowsMessages : uint
|
||||
{
|
||||
WM_MOUSEACTIVATE = 0x0021,
|
||||
WM_INPUTLANGCHANGEREQUEST = 0x0050,
|
||||
WM_INPUTLANGCHANGE = 0x0051,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sent to a window to retrieve a handle to the large or small icon associated with a window. The system displays the large icon in the ALT+TAB dialog, and the small icon in the window caption.
|
||||
/// A window receives this message through its WindowProc function.
|
||||
/// <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms632625.aspx">WM_GETICON message</a>
|
||||
/// </summary>
|
||||
WM_GETICON = 0x007F,
|
||||
WM_CHAR = 0x0102,
|
||||
WM_SYSCOMMAND = 0x0112
|
||||
}
|
||||
}
|
|
@ -1,596 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
public static class GDIExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if all the corners of the rectangle are visible in the specified region.
|
||||
/// Not a perfect check, but this currently a workaround for checking if a window is completely visible
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <param name="rectangle"></param>
|
||||
/// <returns></returns>
|
||||
public static bool AreRectangleCornersVisisble(this Region region, Rectangle rectangle)
|
||||
{
|
||||
Point topLeft = new Point(rectangle.X, rectangle.Y);
|
||||
Point topRight = new Point(rectangle.X + rectangle.Width, rectangle.Y);
|
||||
Point bottomLeft = new Point(rectangle.X, rectangle.Y + rectangle.Height);
|
||||
Point bottomRight = new Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height);
|
||||
bool topLeftVisible = region.IsVisible(topLeft);
|
||||
bool topRightVisible = region.IsVisible(topRight);
|
||||
bool bottomLeftVisible = region.IsVisible(bottomLeft);
|
||||
bool bottomRightVisible = region.IsVisible(bottomRight);
|
||||
|
||||
return topLeftVisible && topRightVisible && bottomLeftVisible && bottomRightVisible;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a SafeHandle for the GetHdc, so one can use using to automatically cleanup the devicecontext
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <returns>SafeDeviceContextHandle</returns>
|
||||
public static SafeDeviceContextHandle GetSafeDeviceContext(this Graphics graphics)
|
||||
{
|
||||
return SafeDeviceContextHandle.FromGraphics(graphics);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class SafeObjectHandle which contains all handles that are cleaned with DeleteObject
|
||||
/// </summary>
|
||||
public abstract class SafeObjectHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteObject(IntPtr hObject);
|
||||
|
||||
protected SafeObjectHandle(bool ownsHandle) : base(ownsHandle)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return DeleteObject(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A hbitmap SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeHBitmapHandle : SafeObjectHandle
|
||||
{
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeHBitmapHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeHBitmapHandle(IntPtr preexistingHandle) : base(true)
|
||||
{
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A hRegion SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeRegionHandle : SafeObjectHandle
|
||||
{
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeRegionHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeRegionHandle(IntPtr preexistingHandle) : base(true)
|
||||
{
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dibsection SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeDibSectionHandle : SafeObjectHandle
|
||||
{
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeDibSectionHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeDibSectionHandle(IntPtr preexistingHandle) : base(true)
|
||||
{
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A select object safehandle implementation
|
||||
/// This impl will select the passed SafeHandle to the HDC and replace the returned value when disposing
|
||||
/// </summary>
|
||||
public class SafeSelectObjectHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
|
||||
|
||||
private readonly SafeHandle _hdc;
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeSelectObjectHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeSelectObjectHandle(SafeDCHandle hdc, SafeHandle newHandle) : base(true)
|
||||
{
|
||||
_hdc = hdc;
|
||||
SetHandle(SelectObject(hdc.DangerousGetHandle(), newHandle.DangerousGetHandle()));
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
SelectObject(_hdc.DangerousGetHandle(), handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class SafeDCHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
protected SafeDCHandle(bool ownsHandle) : base(ownsHandle)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A CompatibleDC SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeCompatibleDCHandle : SafeDCHandle
|
||||
{
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteDC(IntPtr hDC);
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeCompatibleDCHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeCompatibleDCHandle(IntPtr preexistingHandle) : base(true)
|
||||
{
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
|
||||
public SafeSelectObjectHandle SelectObject(SafeHandle newHandle)
|
||||
{
|
||||
return new SafeSelectObjectHandle(this, newHandle);
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return DeleteDC(handle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A DeviceContext SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeDeviceContextHandle : SafeDCHandle
|
||||
{
|
||||
private readonly Graphics _graphics;
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeDeviceContextHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeDeviceContextHandle(Graphics graphics, IntPtr preexistingHandle) : base(true)
|
||||
{
|
||||
_graphics = graphics;
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
_graphics.ReleaseHdc(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static SafeDeviceContextHandle FromGraphics(Graphics graphics)
|
||||
{
|
||||
return new SafeDeviceContextHandle(graphics, graphics.GetHdc());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GDI32 Helpers
|
||||
/// </summary>
|
||||
public static class GDI32
|
||||
{
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
public static extern bool BitBlt(SafeHandle hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, SafeHandle hdcSrc, int nXSrc, int nYSrc, CopyPixelOperation dwRop);
|
||||
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
public static extern SafeCompatibleDCHandle CreateCompatibleDC(SafeHandle hDC);
|
||||
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
public static extern SafeDibSectionHandle CreateDIBSection(SafeHandle hdc, ref BITMAPINFOHEADERV5 bmi, uint usage, out IntPtr bits, IntPtr hSection, uint dwOffset);
|
||||
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
public static extern SafeRegionHandle CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
|
||||
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
public static extern uint GetPixel(SafeHandle hdc, int nXPos, int nYPos);
|
||||
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
public static extern int GetDeviceCaps(SafeHandle hdc, DeviceCaps nIndex);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
public struct BITMAPFILEHEADER
|
||||
{
|
||||
public static readonly short BM = 0x4d42; // BM
|
||||
public short bfType;
|
||||
public int bfSize;
|
||||
public short bfReserved1;
|
||||
public short bfReserved2;
|
||||
public int bfOffBits;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct BitfieldColorMask
|
||||
{
|
||||
public uint blue;
|
||||
public uint green;
|
||||
public uint red;
|
||||
|
||||
public void InitValues()
|
||||
{
|
||||
red = (uint) 255 << 8;
|
||||
green = (uint) 255 << 16;
|
||||
blue = (uint) 255 << 24;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CIEXYZ
|
||||
{
|
||||
public uint ciexyzX; //FXPT2DOT30
|
||||
public uint ciexyzY; //FXPT2DOT30
|
||||
public uint ciexyzZ; //FXPT2DOT30
|
||||
|
||||
public CIEXYZ(uint FXPT2DOT30)
|
||||
{
|
||||
ciexyzX = FXPT2DOT30;
|
||||
ciexyzY = FXPT2DOT30;
|
||||
ciexyzZ = FXPT2DOT30;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RGBQUAD
|
||||
{
|
||||
public byte rgbBlue;
|
||||
public byte rgbGreen;
|
||||
public byte rgbRed;
|
||||
public byte rgbReserved;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CIEXYZTRIPLE
|
||||
{
|
||||
public CIEXYZ ciexyzRed;
|
||||
public CIEXYZ ciexyzGreen;
|
||||
public CIEXYZ ciexyzBlue;
|
||||
}
|
||||
|
||||
public enum BI_COMPRESSION : uint
|
||||
{
|
||||
BI_RGB = 0, // Uncompressed
|
||||
BI_RLE8 = 1, // RLE 8BPP
|
||||
BI_RLE4 = 2, // RLE 4BPP
|
||||
|
||||
BI_BITFIELDS =
|
||||
3, // Specifies that the bitmap is not compressed and that the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bpp bitmaps.
|
||||
BI_JPEG = 4, // Indicates that the image is a JPEG image.
|
||||
BI_PNG = 5 // Indicates that the image is a PNG image.
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct BITMAPINFOHEADER
|
||||
{
|
||||
[FieldOffset(0)] public uint biSize;
|
||||
[FieldOffset(4)] public int biWidth;
|
||||
[FieldOffset(8)] public int biHeight;
|
||||
[FieldOffset(12)] public ushort biPlanes;
|
||||
[FieldOffset(14)] public ushort biBitCount;
|
||||
[FieldOffset(16)] public BI_COMPRESSION biCompression;
|
||||
[FieldOffset(20)] public uint biSizeImage;
|
||||
[FieldOffset(24)] public int biXPelsPerMeter;
|
||||
[FieldOffset(28)] public int biYPelsPerMeter;
|
||||
[FieldOffset(32)] public uint biClrUsed;
|
||||
[FieldOffset(36)] public uint biClrImportant;
|
||||
|
||||
public const int DIB_RGB_COLORS = 0;
|
||||
|
||||
public BITMAPINFOHEADER(int width, int height, ushort bpp)
|
||||
{
|
||||
biSize = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADER)); // BITMAPINFOHEADER < DIBV4 is 40 bytes
|
||||
biPlanes = 1; // Should allways be 1
|
||||
biCompression = BI_COMPRESSION.BI_RGB;
|
||||
biWidth = width;
|
||||
biHeight = height;
|
||||
biBitCount = bpp;
|
||||
biSizeImage = (uint)(width * height * (bpp >> 3));
|
||||
biXPelsPerMeter = 0;
|
||||
biYPelsPerMeter = 0;
|
||||
biClrUsed = 0;
|
||||
biClrImportant = 0;
|
||||
}
|
||||
|
||||
public bool IsDibV4
|
||||
{
|
||||
get
|
||||
{
|
||||
uint sizeOfBMI = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV4));
|
||||
return biSize >= sizeOfBMI;
|
||||
}
|
||||
}
|
||||
public bool IsDibV5
|
||||
{
|
||||
get
|
||||
{
|
||||
uint sizeOfBMI = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV5));
|
||||
return biSize >= sizeOfBMI;
|
||||
}
|
||||
}
|
||||
|
||||
public uint OffsetToPixels
|
||||
{
|
||||
get
|
||||
{
|
||||
if (biCompression == BI_COMPRESSION.BI_BITFIELDS)
|
||||
{
|
||||
// Add 3x4 bytes for the bitfield color mask
|
||||
return biSize + 3 * 4;
|
||||
}
|
||||
|
||||
return biSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct BITMAPINFOHEADERV4
|
||||
{
|
||||
[FieldOffset(0)] public uint biSize;
|
||||
[FieldOffset(4)] public int biWidth;
|
||||
[FieldOffset(8)] public int biHeight;
|
||||
[FieldOffset(12)] public ushort biPlanes;
|
||||
[FieldOffset(14)] public ushort biBitCount;
|
||||
[FieldOffset(16)] public BI_COMPRESSION biCompression;
|
||||
[FieldOffset(20)] public uint biSizeImage;
|
||||
[FieldOffset(24)] public int biXPelsPerMeter;
|
||||
[FieldOffset(28)] public int biYPelsPerMeter;
|
||||
[FieldOffset(32)] public uint biClrUsed;
|
||||
[FieldOffset(36)] public uint biClrImportant;
|
||||
[FieldOffset(40)] public uint bV4RedMask;
|
||||
[FieldOffset(44)] public uint bV4GreenMask;
|
||||
[FieldOffset(48)] public uint bV4BlueMask;
|
||||
[FieldOffset(52)] public uint bV4AlphaMask;
|
||||
[FieldOffset(56)] public uint bV4CSType;
|
||||
[FieldOffset(60)] public CIEXYZTRIPLE bV4Endpoints;
|
||||
[FieldOffset(96)] public uint bV4GammaRed;
|
||||
[FieldOffset(100)] public uint bV4GammaGreen;
|
||||
[FieldOffset(104)] public uint bV4GammaBlue;
|
||||
|
||||
public const int DIB_RGB_COLORS = 0;
|
||||
|
||||
public BITMAPINFOHEADERV4(int width, int height, ushort bpp)
|
||||
{
|
||||
biSize = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV4)); // BITMAPINFOHEADER < DIBV5 is 40 bytes
|
||||
biPlanes = 1; // Should allways be 1
|
||||
biCompression = BI_COMPRESSION.BI_RGB;
|
||||
biWidth = width;
|
||||
biHeight = height;
|
||||
biBitCount = bpp;
|
||||
biSizeImage = (uint)(width * height * (bpp >> 3));
|
||||
biXPelsPerMeter = 0;
|
||||
biYPelsPerMeter = 0;
|
||||
biClrUsed = 0;
|
||||
biClrImportant = 0;
|
||||
|
||||
// V4
|
||||
bV4RedMask = (uint)255 << 16;
|
||||
bV4GreenMask = (uint)255 << 8;
|
||||
bV4BlueMask = 255;
|
||||
bV4AlphaMask = (uint)255 << 24;
|
||||
bV4CSType = 0x73524742; // LCS_sRGB
|
||||
bV4Endpoints = new CIEXYZTRIPLE
|
||||
{
|
||||
ciexyzBlue = new CIEXYZ(0),
|
||||
ciexyzGreen = new CIEXYZ(0),
|
||||
ciexyzRed = new CIEXYZ(0)
|
||||
};
|
||||
bV4GammaRed = 0;
|
||||
bV4GammaGreen = 0;
|
||||
bV4GammaBlue = 0;
|
||||
}
|
||||
|
||||
public bool IsDibV4
|
||||
{
|
||||
get
|
||||
{
|
||||
uint sizeOfBMI = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV4));
|
||||
return biSize >= sizeOfBMI;
|
||||
}
|
||||
}
|
||||
public bool IsDibV5
|
||||
{
|
||||
get
|
||||
{
|
||||
uint sizeOfBMI = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV5));
|
||||
return biSize >= sizeOfBMI;
|
||||
}
|
||||
}
|
||||
|
||||
public uint OffsetToPixels
|
||||
{
|
||||
get
|
||||
{
|
||||
if (biCompression == BI_COMPRESSION.BI_BITFIELDS)
|
||||
{
|
||||
// Add 3x4 bytes for the bitfield color mask
|
||||
return biSize + 3 * 4;
|
||||
}
|
||||
|
||||
return biSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct BITMAPINFOHEADERV5
|
||||
{
|
||||
[FieldOffset(0)] public uint biSize;
|
||||
[FieldOffset(4)] public int biWidth;
|
||||
[FieldOffset(8)] public int biHeight;
|
||||
[FieldOffset(12)] public ushort biPlanes;
|
||||
[FieldOffset(14)] public ushort biBitCount;
|
||||
[FieldOffset(16)] public BI_COMPRESSION biCompression;
|
||||
[FieldOffset(20)] public uint biSizeImage;
|
||||
[FieldOffset(24)] public int biXPelsPerMeter;
|
||||
[FieldOffset(28)] public int biYPelsPerMeter;
|
||||
[FieldOffset(32)] public uint biClrUsed;
|
||||
[FieldOffset(36)] public uint biClrImportant;
|
||||
[FieldOffset(40)] public uint bV4RedMask;
|
||||
[FieldOffset(44)] public uint bV4GreenMask;
|
||||
[FieldOffset(48)] public uint bV4BlueMask;
|
||||
[FieldOffset(52)] public uint bV4AlphaMask;
|
||||
[FieldOffset(56)] public uint bV4CSType;
|
||||
[FieldOffset(60)] public CIEXYZTRIPLE bV4Endpoints;
|
||||
[FieldOffset(96)] public uint bV4GammaRed;
|
||||
[FieldOffset(100)] public uint bV4GammaGreen;
|
||||
[FieldOffset(104)] public uint bV4GammaBlue;
|
||||
[FieldOffset(108)] public uint bV5Intent; // Rendering intent for bitmap
|
||||
[FieldOffset(112)] public uint bV5ProfileData;
|
||||
[FieldOffset(116)] public uint bV5ProfileSize;
|
||||
[FieldOffset(120)] public uint bV5Reserved;
|
||||
|
||||
public const int DIB_RGB_COLORS = 0;
|
||||
|
||||
public BITMAPINFOHEADERV5(int width, int height, ushort bpp)
|
||||
{
|
||||
biSize = (uint) Marshal.SizeOf(typeof(BITMAPINFOHEADERV5)); // BITMAPINFOHEADER < DIBV5 is 40 bytes
|
||||
biPlanes = 1; // Should allways be 1
|
||||
biCompression = BI_COMPRESSION.BI_RGB;
|
||||
biWidth = width;
|
||||
biHeight = height;
|
||||
biBitCount = bpp;
|
||||
biSizeImage = (uint) (width * height * (bpp >> 3));
|
||||
biXPelsPerMeter = 0;
|
||||
biYPelsPerMeter = 0;
|
||||
biClrUsed = 0;
|
||||
biClrImportant = 0;
|
||||
|
||||
// V4
|
||||
bV4RedMask = (uint) 255 << 16;
|
||||
bV4GreenMask = (uint) 255 << 8;
|
||||
bV4BlueMask = 255;
|
||||
bV4AlphaMask = (uint) 255 << 24;
|
||||
bV4CSType = 0x73524742; // LCS_sRGB
|
||||
bV4Endpoints = new CIEXYZTRIPLE
|
||||
{
|
||||
ciexyzBlue = new CIEXYZ(0),
|
||||
ciexyzGreen = new CIEXYZ(0),
|
||||
ciexyzRed = new CIEXYZ(0)
|
||||
};
|
||||
bV4GammaRed = 0;
|
||||
bV4GammaGreen = 0;
|
||||
bV4GammaBlue = 0;
|
||||
// V5
|
||||
bV5Intent = 4;
|
||||
bV5ProfileData = 0;
|
||||
bV5ProfileSize = 0;
|
||||
bV5Reserved = 0;
|
||||
}
|
||||
|
||||
public bool IsDibV4
|
||||
{
|
||||
get
|
||||
{
|
||||
uint sizeOfBMI = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV4));
|
||||
return biSize >= sizeOfBMI;
|
||||
}
|
||||
}
|
||||
public bool IsDibV5
|
||||
{
|
||||
get
|
||||
{
|
||||
uint sizeOfBMI = (uint)Marshal.SizeOf(typeof(BITMAPINFOHEADERV5));
|
||||
return biSize >= sizeOfBMI;
|
||||
}
|
||||
}
|
||||
|
||||
public uint OffsetToPixels
|
||||
{
|
||||
get
|
||||
{
|
||||
if (biCompression == BI_COMPRESSION.BI_BITFIELDS)
|
||||
{
|
||||
// Add 3x4 bytes for the bitfield color mask
|
||||
return biSize + 3 * 4;
|
||||
}
|
||||
|
||||
return biSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,387 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains members that specify the nature of a Gaussian blur.
|
||||
/// </summary>
|
||||
/// <remarks>Cannot be pinned with GCHandle due to bool value.</remarks>
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
internal struct BlurParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Real number that specifies the blur radius (the radius of the Gaussian convolution kernel) in
|
||||
/// pixels. The radius must be in the range 0 through 255. As the radius increases, the resulting
|
||||
/// bitmap becomes more blurry.
|
||||
/// </summary>
|
||||
public float Radius;
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value that specifies whether the bitmap expands by an amount equal to the blur radius.
|
||||
/// If TRUE, the bitmap expands by an amount equal to the radius so that it can have soft edges.
|
||||
/// If FALSE, the bitmap remains the same size and the soft edges are clipped.
|
||||
/// </summary>
|
||||
public bool ExpandEdges;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GDI Plus unit description.
|
||||
/// </summary>
|
||||
public enum GpUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// World coordinate (non-physical unit).
|
||||
/// </summary>
|
||||
UnitWorld,
|
||||
|
||||
/// <summary>
|
||||
/// Variable - for PageTransform only.
|
||||
/// </summary>
|
||||
UnitDisplay,
|
||||
|
||||
/// <summary>
|
||||
/// Each unit is one device pixel.
|
||||
/// </summary>
|
||||
UnitPixel,
|
||||
|
||||
/// <summary>
|
||||
/// Each unit is a printer's point, or 1/72 inch.
|
||||
/// </summary>
|
||||
UnitPoint,
|
||||
|
||||
/// <summary>
|
||||
/// Each unit is 1 inch.
|
||||
/// </summary>
|
||||
UnitInch,
|
||||
|
||||
/// <summary>
|
||||
/// Each unit is 1/300 inch.
|
||||
/// </summary>
|
||||
UnitDocument,
|
||||
|
||||
/// <summary>
|
||||
/// Each unit is 1 millimeter.
|
||||
/// </summary>
|
||||
UnitMillimeter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GDIplus Helpers
|
||||
/// </summary>
|
||||
public static class GDIplus
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(GDIplus));
|
||||
|
||||
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true)]
|
||||
private static extern int GdipBitmapApplyEffect(IntPtr bitmap, IntPtr effect, ref RECT rectOfInterest, bool useAuxData, IntPtr auxData, int auxDataSize);
|
||||
|
||||
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true)]
|
||||
private static extern int GdipDrawImageFX(IntPtr graphics, IntPtr bitmap, ref RECTF source, IntPtr matrix, IntPtr effect, IntPtr imageAttributes, GpUnit srcUnit);
|
||||
|
||||
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true)]
|
||||
private static extern int GdipSetEffectParameters(IntPtr effect, IntPtr parameters, uint size);
|
||||
|
||||
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true)]
|
||||
private static extern int GdipCreateEffect(Guid guid, out IntPtr effect);
|
||||
|
||||
[DllImport("gdiplus.dll", SetLastError = true, ExactSpelling = true)]
|
||||
private static extern int GdipDeleteEffect(IntPtr effect);
|
||||
|
||||
private static readonly Guid BlurEffectGuid = new Guid("{633C80A4-1843-482B-9EF2-BE2834C5FDD4}");
|
||||
|
||||
// Constant "FieldInfo" for getting the nativeImage from the Bitmap
|
||||
private static readonly FieldInfo FIELD_INFO_NATIVE_IMAGE = typeof(Bitmap).GetField("nativeImage", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
// Constant "FieldInfo" for getting the NativeGraphics from the Graphics
|
||||
private static readonly FieldInfo FIELD_INFO_NATIVE_GRAPHICS =
|
||||
typeof(Graphics).GetField("nativeGraphics", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
// Constant "FieldInfo" for getting the nativeMatrix from the Matrix
|
||||
private static readonly FieldInfo FIELD_INFO_NATIVE_MATRIX =
|
||||
typeof(Matrix).GetField("nativeMatrix", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
// Constant "FieldInfo" for getting the nativeImageAttributes from the ImageAttributes
|
||||
private static readonly FieldInfo FIELD_INFO_NATIVE_IMAGEATTRIBUTES =
|
||||
typeof(ImageAttributes).GetField("nativeImageAttributes", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
private static bool _isBlurEnabled = Environment.OSVersion.Version.Major >= 6;
|
||||
|
||||
/// <summary>
|
||||
/// Get the nativeImage field from the bitmap
|
||||
/// </summary>
|
||||
/// <param name="bitmap"></param>
|
||||
/// <returns>IntPtr</returns>
|
||||
private static IntPtr GetNativeImage(Bitmap bitmap)
|
||||
{
|
||||
if (bitmap == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return (IntPtr) FIELD_INFO_NATIVE_IMAGE.GetValue(bitmap);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the NativeGraphics field from the graphics
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <returns>IntPtr</returns>
|
||||
private static IntPtr GetNativeGraphics(Graphics graphics)
|
||||
{
|
||||
if (graphics == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return (IntPtr) FIELD_INFO_NATIVE_GRAPHICS.GetValue(graphics);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the nativeMatrix field from the matrix
|
||||
/// </summary>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns>IntPtr</returns>
|
||||
private static IntPtr GetNativeMatrix(Matrix matrix)
|
||||
{
|
||||
if (matrix == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return (IntPtr) FIELD_INFO_NATIVE_MATRIX.GetValue(matrix);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the nativeImageAttributes field from the ImageAttributes
|
||||
/// </summary>
|
||||
/// <param name="imageAttributes"></param>
|
||||
/// <returns>IntPtr</returns>
|
||||
private static IntPtr GetNativeImageAttributes(ImageAttributes imageAttributes)
|
||||
{
|
||||
if (imageAttributes == null)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return (IntPtr) FIELD_INFO_NATIVE_IMAGEATTRIBUTES.GetValue(imageAttributes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if a GDIPlus blur can be made for the supplied radius.
|
||||
/// This accounts for the "bug" I reported here: https://social.technet.microsoft.com/Forums/en/w8itprogeneral/thread/99ddbe9d-556d-475a-8bab-84e25aa13a2c
|
||||
/// </summary>
|
||||
/// <param name="radius"></param>
|
||||
/// <returns>false if blur is not possible</returns>
|
||||
public static bool IsBlurPossible(int radius)
|
||||
{
|
||||
if (!_isBlurEnabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor < 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Environment.OSVersion.Version.Major > 6 && radius >= 20;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use the GDI+ blur effect on the bitmap
|
||||
/// </summary>
|
||||
/// <param name="destinationBitmap">Bitmap to apply the effect to</param>
|
||||
/// <param name="area">Rectangle to apply the blur effect to</param>
|
||||
/// <param name="radius">0-255</param>
|
||||
/// <param name="expandEdges">bool true if the edges are expanded with the radius</param>
|
||||
/// <returns>false if there is no GDI+ available or an exception occurred</returns>
|
||||
public static bool ApplyBlur(Bitmap destinationBitmap, Rectangle area, int radius, bool expandEdges)
|
||||
{
|
||||
if (!IsBlurPossible(radius))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IntPtr hBlurParams = IntPtr.Zero;
|
||||
IntPtr hEffect = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
// Create the GDI+ BlurEffect, using the Guid
|
||||
int status = GdipCreateEffect(BlurEffectGuid, out hEffect);
|
||||
if (status != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a BlurParams struct and set the values
|
||||
var blurParams = new BlurParams
|
||||
{
|
||||
Radius = radius,
|
||||
ExpandEdges = expandEdges
|
||||
};
|
||||
|
||||
// Allocate space in unmanaged memory
|
||||
hBlurParams = Marshal.AllocHGlobal(Marshal.SizeOf(blurParams));
|
||||
// Copy the structure to the unmanaged memory
|
||||
Marshal.StructureToPtr(blurParams, hBlurParams, false);
|
||||
|
||||
|
||||
// Set the blurParams to the effect
|
||||
GdipSetEffectParameters(hEffect, hBlurParams, (uint) Marshal.SizeOf(blurParams));
|
||||
|
||||
// Somewhere it said we can use destinationBitmap.GetHbitmap(), this doesn't work!!
|
||||
// Get the private nativeImage property from the Bitmap
|
||||
IntPtr hBitmap = GetNativeImage(destinationBitmap);
|
||||
|
||||
// Create a RECT from the Rectangle
|
||||
RECT rec = new RECT(area);
|
||||
// Apply the effect to the bitmap in the specified area
|
||||
GdipBitmapApplyEffect(hBitmap, hEffect, ref rec, false, IntPtr.Zero, 0);
|
||||
|
||||
// Everything worked, return true
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isBlurEnabled = false;
|
||||
Log.Error("Problem using GdipBitmapApplyEffect: ", ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (hEffect != IntPtr.Zero)
|
||||
{
|
||||
// Delete the effect
|
||||
GdipDeleteEffect(hEffect);
|
||||
}
|
||||
|
||||
if (hBlurParams != IntPtr.Zero)
|
||||
{
|
||||
// Free the memory
|
||||
Marshal.FreeHGlobal(hBlurParams);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isBlurEnabled = false;
|
||||
Log.Error("Problem cleaning up ApplyBlur: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw the image on the graphics with GDI+ blur effect
|
||||
/// </summary>
|
||||
/// <returns>false if there is no GDI+ available or an exception occurred</returns>
|
||||
public static bool DrawWithBlur(Graphics graphics, Bitmap image, Rectangle source, Matrix transform, ImageAttributes imageAttributes, int radius, bool expandEdges)
|
||||
{
|
||||
if (!IsBlurPossible(radius))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IntPtr hBlurParams = IntPtr.Zero;
|
||||
IntPtr hEffect = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
// Create the GDI+ BlurEffect, using the Guid
|
||||
int status = GdipCreateEffect(BlurEffectGuid, out hEffect);
|
||||
if (status != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create a BlurParams struct and set the values
|
||||
var blurParams = new BlurParams
|
||||
{
|
||||
Radius = radius,
|
||||
ExpandEdges = false
|
||||
};
|
||||
//blurParams.Padding = radius;
|
||||
|
||||
// Allocate space in unmanaged memory
|
||||
hBlurParams = Marshal.AllocHGlobal(Marshal.SizeOf(blurParams));
|
||||
// Copy the structure to the unmanaged memory
|
||||
Marshal.StructureToPtr(blurParams, hBlurParams, true);
|
||||
|
||||
// Set the blurParams to the effect
|
||||
GdipSetEffectParameters(hEffect, hBlurParams, (uint) Marshal.SizeOf(blurParams));
|
||||
|
||||
// Somewhere it said we can use destinationBitmap.GetHbitmap(), this doesn't work!!
|
||||
// Get the private nativeImage property from the Bitmap
|
||||
IntPtr hBitmap = GetNativeImage(image);
|
||||
IntPtr hGraphics = GetNativeGraphics(graphics);
|
||||
IntPtr hMatrix = GetNativeMatrix(transform);
|
||||
IntPtr hAttributes = GetNativeImageAttributes(imageAttributes);
|
||||
|
||||
// Create a RECT from the Rectangle
|
||||
RECTF sourceRecf = new RECTF(source);
|
||||
// Apply the effect to the bitmap in the specified area
|
||||
GdipDrawImageFX(hGraphics, hBitmap, ref sourceRecf, hMatrix, hEffect, hAttributes, GpUnit.UnitPixel);
|
||||
|
||||
// Everything worked, return true
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isBlurEnabled = false;
|
||||
Log.Error("Problem using GdipDrawImageFX: ", ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (hEffect != IntPtr.Zero)
|
||||
{
|
||||
// Delete the effect
|
||||
GdipDeleteEffect(hEffect);
|
||||
}
|
||||
|
||||
if (hBlurParams != IntPtr.Zero)
|
||||
{
|
||||
// Free the memory
|
||||
Marshal.FreeHGlobal(hBlurParams);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isBlurEnabled = false;
|
||||
Log.Error("Problem cleaning up DrawWithBlur: ", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,135 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of Kernel32.
|
||||
/// </summary>
|
||||
public class Kernel32
|
||||
{
|
||||
public const uint ATTACHCONSOLE_ATTACHPARENTPROCESS = 0x0ffffffff; // default value if not specifing a process ID
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool AttachConsole(uint dwProcessId);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool AllocConsole();
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
public static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
public static extern uint SuspendThread(IntPtr hThread);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
public static extern int ResumeThread(IntPtr hThread);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
public static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, bool bInheritHandle, int dwProcessId);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool QueryFullProcessImageName(IntPtr hProcess, uint dwFlags, StringBuilder lpExeName, ref uint lpdwSize);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, uint uuchMax);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetPackageFullName(IntPtr hProcess, ref Int32 packageFullNameLength, StringBuilder fullName);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Method to get the process path
|
||||
/// </summary>
|
||||
/// <param name="processid"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetProcessPath(int processid)
|
||||
{
|
||||
StringBuilder _PathBuffer = new StringBuilder(512);
|
||||
// Try the GetModuleFileName method first since it's the fastest.
|
||||
// May return ACCESS_DENIED (due to VM_READ flag) if the process is not owned by the current user.
|
||||
// Will fail if we are compiled as x86 and we're trying to open a 64 bit process...not allowed.
|
||||
IntPtr hprocess = OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VMRead, false, processid);
|
||||
if (hprocess != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (PsAPI.GetModuleFileNameEx(hprocess, IntPtr.Zero, _PathBuffer, (uint) _PathBuffer.Capacity) > 0)
|
||||
{
|
||||
return _PathBuffer.ToString();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseHandle(hprocess);
|
||||
}
|
||||
}
|
||||
|
||||
hprocess = OpenProcess(ProcessAccessFlags.QueryInformation, false, processid);
|
||||
if (hprocess != IntPtr.Zero)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Try this method for Vista or higher operating systems
|
||||
uint size = (uint) _PathBuffer.Capacity;
|
||||
if ((Environment.OSVersion.Version.Major >= 6) && (QueryFullProcessImageName(hprocess, 0, _PathBuffer, ref size) && (size > 0)))
|
||||
{
|
||||
return _PathBuffer.ToString();
|
||||
}
|
||||
|
||||
// Try the GetProcessImageFileName method
|
||||
if (PsAPI.GetProcessImageFileName(hprocess, _PathBuffer, (uint) _PathBuffer.Capacity) > 0)
|
||||
{
|
||||
string dospath = _PathBuffer.ToString();
|
||||
foreach (string drive in Environment.GetLogicalDrives())
|
||||
{
|
||||
if (QueryDosDevice(drive.TrimEnd('\\'), _PathBuffer, (uint) _PathBuffer.Capacity) > 0)
|
||||
{
|
||||
if (dospath.StartsWith(_PathBuffer.ToString()))
|
||||
{
|
||||
return drive + dospath.Remove(0, _PathBuffer.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseHandle(hprocess);
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of PsAPI.
|
||||
/// </summary>
|
||||
public class PsAPI
|
||||
{
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(PsAPI));
|
||||
|
||||
[DllImport("psapi", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, StringBuilder lpFilename, uint nSize);
|
||||
|
||||
[DllImport("psapi", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize);
|
||||
|
||||
[DllImport("psapi")]
|
||||
private static extern int EmptyWorkingSet(IntPtr hwProc);
|
||||
|
||||
/// <summary>
|
||||
/// Make the process use less memory by emptying the working set
|
||||
/// </summary>
|
||||
public static void EmptyWorkingSet()
|
||||
{
|
||||
LOG.Info("Calling EmptyWorkingSet");
|
||||
using Process currentProcess = Process.GetCurrentProcess();
|
||||
EmptyWorkingSet(currentProcess.Handle);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
using System;
|
||||
using System.Security.Permissions;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using log4net;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A SafeHandle class implementation for the current input desktop
|
||||
/// </summary>
|
||||
public class SafeCurrentInputDesktopHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(SafeCurrentInputDesktopHandle));
|
||||
|
||||
public SafeCurrentInputDesktopHandle() : base(true)
|
||||
{
|
||||
IntPtr hDesktop = User32.OpenInputDesktop(0, true, DesktopAccessRight.GENERIC_ALL);
|
||||
if (hDesktop != IntPtr.Zero)
|
||||
{
|
||||
SetHandle(hDesktop);
|
||||
if (User32.SetThreadDesktop(hDesktop))
|
||||
{
|
||||
LOG.DebugFormat("Switched to desktop {0}", hDesktop);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.WarnFormat("Couldn't switch to desktop {0}", hDesktop);
|
||||
LOG.Error(User32.CreateWin32Exception("SetThreadDesktop"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.Warn("Couldn't get current desktop.");
|
||||
LOG.Error(User32.CreateWin32Exception("OpenInputDesktop"));
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return User32.CloseDesktop(handle);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A SafeHandle class implementation for the hIcon
|
||||
/// </summary>
|
||||
public class SafeIconHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
public SafeIconHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public SafeIconHandle(IntPtr hIcon) : base(true)
|
||||
{
|
||||
SetHandle(hIcon);
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
return User32.DestroyIcon(handle);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A WindowDC SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeWindowDcHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||
{
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
private readonly IntPtr _hWnd;
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
public SafeWindowDcHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeWindowDcHandle(IntPtr hWnd, IntPtr preexistingHandle) : base(true)
|
||||
{
|
||||
_hWnd = hWnd;
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
bool returnValue = ReleaseDC(_hWnd, handle);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a DC as SafeWindowDcHandle for the whole of the specified hWnd
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr</param>
|
||||
/// <returns>SafeWindowDcHandle</returns>
|
||||
public static SafeWindowDcHandle FromWindow(IntPtr hWnd)
|
||||
{
|
||||
if (hWnd == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var hDcDesktop = GetWindowDC(hWnd);
|
||||
return new SafeWindowDcHandle(hWnd, hDcDesktop);
|
||||
}
|
||||
|
||||
public static SafeWindowDcHandle FromDesktop()
|
||||
{
|
||||
IntPtr hWndDesktop = User32.GetDesktopWindow();
|
||||
IntPtr hDCDesktop = GetWindowDC(hWndDesktop);
|
||||
return new SafeWindowDcHandle(hWndDesktop, hDCDesktop);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,123 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of Shell32.
|
||||
/// </summary>
|
||||
public static class Shell32
|
||||
{
|
||||
[DllImport("shell32", CharSet = CharSet.Unicode)]
|
||||
public static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons);
|
||||
|
||||
[DllImport("shell32", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private struct SHFILEINFO
|
||||
{
|
||||
public readonly IntPtr hIcon;
|
||||
public readonly int iIcon;
|
||||
public readonly uint dwAttributes;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
||||
public readonly string szDisplayName;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
|
||||
public readonly string szTypeName;
|
||||
};
|
||||
|
||||
// Browsing for directory.
|
||||
|
||||
private const uint SHGFI_ICON = 0x000000100; // get icon
|
||||
private const uint SHGFI_LINKOVERLAY = 0x000008000; // put a link overlay on icon
|
||||
private const uint SHGFI_LARGEICON = 0x000000000; // get large icon
|
||||
private const uint SHGFI_SMALLICON = 0x000000001; // get small icon
|
||||
private const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; // use passed dwFileAttribute
|
||||
private const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
|
||||
|
||||
/// <summary>
|
||||
/// Options to specify the size of icons to return.
|
||||
/// </summary>
|
||||
public enum IconSize
|
||||
{
|
||||
/// <summary>
|
||||
/// Specify large icon - 32 pixels by 32 pixels.
|
||||
/// </summary>
|
||||
Large = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Specify small icon - 16 pixels by 16 pixels.
|
||||
/// </summary>
|
||||
Small = 1
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an icon for a given file extension - indicated by the name parameter.
|
||||
/// See: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762179(v=vs.85).aspx
|
||||
/// </summary>
|
||||
/// <param name="filename">Filename</param>
|
||||
/// <param name="size">Large or small</param>
|
||||
/// <param name="linkOverlay">Whether to include the link icon</param>
|
||||
/// <returns>System.Drawing.Icon</returns>
|
||||
public static Icon GetFileIcon(string filename, IconSize size, bool linkOverlay)
|
||||
{
|
||||
SHFILEINFO shfi = new SHFILEINFO();
|
||||
// SHGFI_USEFILEATTRIBUTES makes it simulate, just gets the icon for the extension
|
||||
uint flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
|
||||
|
||||
if (linkOverlay)
|
||||
{
|
||||
flags += SHGFI_LINKOVERLAY;
|
||||
}
|
||||
|
||||
// Check the size specified for return.
|
||||
if (IconSize.Small == size)
|
||||
{
|
||||
flags += SHGFI_SMALLICON;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags += SHGFI_LARGEICON;
|
||||
}
|
||||
|
||||
SHGetFileInfo(Path.GetFileName(filename), FILE_ATTRIBUTE_NORMAL, ref shfi, (uint) Marshal.SizeOf(shfi), flags);
|
||||
|
||||
// Only return an icon if we really got one
|
||||
if (shfi.hIcon != IntPtr.Zero)
|
||||
{
|
||||
// Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
|
||||
Icon icon = (Icon) Icon.FromHandle(shfi.hIcon).Clone();
|
||||
// Cleanup
|
||||
User32.DestroyIcon(shfi.hIcon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CursorInfo
|
||||
{
|
||||
public int cbSize;
|
||||
public int flags;
|
||||
public IntPtr hCursor;
|
||||
public POINT ptScreenPos;
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,66 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||
public struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
|
||||
public POINT(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public POINT(Point point)
|
||||
{
|
||||
X = point.X;
|
||||
Y = point.Y;
|
||||
}
|
||||
|
||||
public static implicit operator Point(POINT p)
|
||||
{
|
||||
return new Point(p.X, p.Y);
|
||||
}
|
||||
|
||||
public static implicit operator POINT(Point p)
|
||||
{
|
||||
return new POINT(p.X, p.Y);
|
||||
}
|
||||
|
||||
public Point ToPoint()
|
||||
{
|
||||
return new Point(X, Y);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return X + "," + Y;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,176 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||
public struct RECT
|
||||
{
|
||||
private int _Left;
|
||||
private int _Top;
|
||||
private int _Right;
|
||||
private int _Bottom;
|
||||
|
||||
public RECT(RECT rectangle)
|
||||
: this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)
|
||||
{
|
||||
}
|
||||
|
||||
public RECT(Rectangle rectangle)
|
||||
: this(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom)
|
||||
{
|
||||
}
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
_Left = left;
|
||||
_Top = top;
|
||||
_Right = right;
|
||||
_Bottom = bottom;
|
||||
}
|
||||
|
||||
public int X
|
||||
{
|
||||
get { return _Left; }
|
||||
set { _Left = value; }
|
||||
}
|
||||
|
||||
public int Y
|
||||
{
|
||||
get { return _Top; }
|
||||
set { _Top = value; }
|
||||
}
|
||||
|
||||
public int Left
|
||||
{
|
||||
get { return _Left; }
|
||||
set { _Left = value; }
|
||||
}
|
||||
|
||||
public int Top
|
||||
{
|
||||
get { return _Top; }
|
||||
set { _Top = value; }
|
||||
}
|
||||
|
||||
public int Right
|
||||
{
|
||||
get { return _Right; }
|
||||
set { _Right = value; }
|
||||
}
|
||||
|
||||
public int Bottom
|
||||
{
|
||||
get { return _Bottom; }
|
||||
set { _Bottom = value; }
|
||||
}
|
||||
|
||||
public int Height
|
||||
{
|
||||
get { return _Bottom - _Top; }
|
||||
set { _Bottom = value - _Top; }
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get { return _Right - _Left; }
|
||||
set { _Right = value + _Left; }
|
||||
}
|
||||
|
||||
public Point Location
|
||||
{
|
||||
get { return new Point(Left, Top); }
|
||||
set
|
||||
{
|
||||
_Left = value.X;
|
||||
_Top = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public Size Size
|
||||
{
|
||||
get { return new Size(Width, Height); }
|
||||
set
|
||||
{
|
||||
_Right = value.Width + _Left;
|
||||
_Bottom = value.Height + _Top;
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator Rectangle(RECT rectangle)
|
||||
{
|
||||
return new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
|
||||
}
|
||||
|
||||
public static implicit operator RECT(Rectangle rectangle)
|
||||
{
|
||||
return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
|
||||
}
|
||||
|
||||
public static bool operator ==(RECT rectangle1, RECT rectangle2)
|
||||
{
|
||||
return rectangle1.Equals(rectangle2);
|
||||
}
|
||||
|
||||
public static bool operator !=(RECT rectangle1, RECT rectangle2)
|
||||
{
|
||||
return !rectangle1.Equals(rectangle2);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ToString().GetHashCode();
|
||||
}
|
||||
|
||||
public bool Equals(RECT rectangle)
|
||||
{
|
||||
return rectangle.Left == _Left && rectangle.Top == _Top && rectangle.Right == _Right && rectangle.Bottom == _Bottom;
|
||||
}
|
||||
|
||||
public Rectangle ToRectangle()
|
||||
{
|
||||
return new Rectangle(Left, Top, Width, Height);
|
||||
}
|
||||
|
||||
public override bool Equals(object Object)
|
||||
{
|
||||
if (Object is RECT)
|
||||
{
|
||||
return Equals((RECT) Object);
|
||||
}
|
||||
else if (Object is Rectangle)
|
||||
{
|
||||
return Equals(new RECT((Rectangle) Object));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,131 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
/// <summary>
|
||||
/// A floating point GDI Plus width/hight based rectangle.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECTF
|
||||
{
|
||||
/// <summary>
|
||||
/// The X corner location of the rectangle.
|
||||
/// </summary>
|
||||
public float X;
|
||||
|
||||
/// <summary>
|
||||
/// The Y corner location of the rectangle.
|
||||
/// </summary>
|
||||
public float Y;
|
||||
|
||||
/// <summary>
|
||||
/// The width of the rectangle.
|
||||
/// </summary>
|
||||
public float Width;
|
||||
|
||||
/// <summary>
|
||||
/// The height of the rectangle.
|
||||
/// </summary>
|
||||
public float Height;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new GDI Plus rectangle.
|
||||
/// </summary>
|
||||
/// <param name="x">The X corner location of the rectangle.</param>
|
||||
/// <param name="y">The Y corner location of the rectangle.</param>
|
||||
/// <param name="width">The width of the rectangle.</param>
|
||||
/// <param name="height">The height of the rectangle.</param>
|
||||
public RECTF(float x, float y, float width, float height)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new GDI Plus rectangle from a System.Drawing.RectangleF.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to base this GDI Plus rectangle on.</param>
|
||||
public RECTF(RectangleF rect)
|
||||
{
|
||||
X = rect.X;
|
||||
Y = rect.Y;
|
||||
Width = rect.Width;
|
||||
Height = rect.Height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new GDI Plus rectangle from a System.Drawing.Rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to base this GDI Plus rectangle on.</param>
|
||||
public RECTF(Rectangle rect)
|
||||
{
|
||||
X = rect.X;
|
||||
Y = rect.Y;
|
||||
Width = rect.Width;
|
||||
Height = rect.Height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a RectangleF for this GDI Plus rectangle.
|
||||
/// </summary>
|
||||
/// <returns>A System.Drawing.RectangleF structure.</returns>
|
||||
public RectangleF ToRectangle()
|
||||
{
|
||||
return new RectangleF(X, Y, Width, Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a RectangleF for a GDI Plus rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rect">The GDI Plus rectangle to get the RectangleF for.</param>
|
||||
/// <returns>A System.Drawing.RectangleF structure.</returns>
|
||||
public static RectangleF ToRectangle(RECTF rect)
|
||||
{
|
||||
return rect.ToRectangle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a GDI Plus rectangle for a RectangleF structure.
|
||||
/// </summary>
|
||||
/// <param name="rect">The RectangleF to get the GDI Plus rectangle for.</param>
|
||||
/// <returns>A GDI Plus rectangle structure.</returns>
|
||||
public static RECTF FromRectangle(RectangleF rect)
|
||||
{
|
||||
return new RECTF(rect);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a GDI Plus rectangle for a Rectangle structure.
|
||||
/// </summary>
|
||||
/// <param name="rect">The Rectangle to get the GDI Plus rectangle for.</param>
|
||||
/// <returns>A GDI Plus rectangle structure.</returns>
|
||||
public static RECTF FromRectangle(Rectangle rect)
|
||||
{
|
||||
return new RECTF(rect);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,51 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||
public struct SIZE
|
||||
{
|
||||
public int Width;
|
||||
public int Height;
|
||||
|
||||
public SIZE(Size size) : this(size.Width, size.Height)
|
||||
{
|
||||
}
|
||||
|
||||
public SIZE(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public Size ToSize()
|
||||
{
|
||||
return new Size(Width, Height);
|
||||
}
|
||||
|
||||
public bool IsEmpty => Width * Height == 0;
|
||||
}
|
||||
}
|
|
@ -1,52 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
/// <summary>
|
||||
/// The structure for the WindowInfo
|
||||
/// See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632610%28v=vs.85%29.aspx
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential), Serializable]
|
||||
public struct WindowInfo
|
||||
{
|
||||
public uint cbSize;
|
||||
public RECT rcWindow;
|
||||
public RECT rcClient;
|
||||
public uint dwStyle;
|
||||
public uint dwExStyle;
|
||||
public uint dwWindowStatus;
|
||||
public uint cxWindowBorders;
|
||||
public uint cyWindowBorders;
|
||||
public ushort atomWindowType;
|
||||
|
||||
public ushort wCreatorVersion;
|
||||
|
||||
// Allows automatic initialization of "cbSize" with "new WINDOWINFO(null/true/false)".
|
||||
public WindowInfo(bool? filler) : this()
|
||||
{
|
||||
cbSize = (uint) (Marshal.SizeOf(typeof(WindowInfo)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,80 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers.Structs
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains information about the placement of a window on the screen.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||
public struct WindowPlacement
|
||||
{
|
||||
/// <summary>
|
||||
/// The length of the structure, in bytes. Before calling the GetWindowPlacement or SetWindowPlacement functions, set this member to sizeof(WINDOWPLACEMENT).
|
||||
/// <para>
|
||||
/// GetWindowPlacement and SetWindowPlacement fail if this member is not set correctly.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public int Length;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies flags that control the position of the minimized window and the method by which the window is restored.
|
||||
/// </summary>
|
||||
public WindowPlacementFlags Flags;
|
||||
|
||||
/// <summary>
|
||||
/// The current show state of the window.
|
||||
/// </summary>
|
||||
public ShowWindowCommand ShowCmd;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinates of the window's upper-left corner when the window is minimized.
|
||||
/// </summary>
|
||||
public POINT MinPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinates of the window's upper-left corner when the window is maximized.
|
||||
/// </summary>
|
||||
public POINT MaxPosition;
|
||||
|
||||
/// <summary>
|
||||
/// The window's coordinates when the window is in the restored position.
|
||||
/// </summary>
|
||||
public RECT NormalPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default (empty) value.
|
||||
/// </summary>
|
||||
public static WindowPlacement Default
|
||||
{
|
||||
get
|
||||
{
|
||||
WindowPlacement result = new WindowPlacement();
|
||||
result.Length = Marshal.SizeOf(result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,331 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Base.Core.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using log4net;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// User32 Wrappers
|
||||
/// </summary>
|
||||
public static class User32
|
||||
{
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(User32));
|
||||
private static bool _CanCallGetPhysicalCursorPos = true;
|
||||
public const int SC_RESTORE = 0xF120;
|
||||
public const int SC_MAXIMIZE = 0xF030;
|
||||
public const int SC_MINIMIZE = 0xF020;
|
||||
|
||||
// For MonitorFromWindow
|
||||
public const int MONITOR_DEFAULTTONULL = 0;
|
||||
public const int MONITOR_DEFAULTTONEAREST = 2;
|
||||
public const int CURSOR_SHOWING = 0x00000001;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified window handle identifies an existing window.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">A handle to the window to be tested.</param>
|
||||
/// <returns>
|
||||
/// If the window handle identifies an existing window, the return value is true.
|
||||
/// If the window handle does not identify an existing window, the return value is false.
|
||||
/// </returns>
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern int GetWindowThreadProcessId(IntPtr hWnd, IntPtr processId);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern IntPtr AttachThreadInput(int idAttach, int idAttachTo, int fAttach);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr GetParent(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int cch);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool BringWindowToTop(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr GetForegroundWindow();
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WindowPlacement lpwndpl);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WindowPlacement lpwndpl);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsIconic(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsZoomed(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern uint GetClassLong(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32", SetLastError = true, EntryPoint = "GetClassLongPtr")]
|
||||
public static extern IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool PrintWindow(IntPtr hWnd, IntPtr hDc, PrintWindowFlags pwFlags);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint wMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32", SetLastError = true, EntryPoint = "GetWindowLong")]
|
||||
public static extern IntPtr GetWindowLong(IntPtr hWnd, int index);
|
||||
|
||||
[DllImport("user32", SetLastError = true, EntryPoint = "GetWindowLongPtr")]
|
||||
public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern int SetWindowLong(IntPtr hWnd, int index, int styleFlags);
|
||||
|
||||
[DllImport("user32", SetLastError = true, EntryPoint = "SetWindowLongPtr")]
|
||||
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int index, IntPtr styleFlags);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr MonitorFromWindow(IntPtr hWnd, MonitorFrom dwFlags);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr MonitorFromRect([In] ref RECT lprc, uint dwFlags);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetWindowInfo(IntPtr hWnd, ref WindowInfo pwi);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern int EnumChildWindows(IntPtr hWndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern RegionResult GetWindowRgn(IntPtr hWnd, SafeHandle hRgn);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, WindowPos uFlags);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr GetClipboardOwner();
|
||||
|
||||
// Added for finding Metro apps, Greenshot 1.1
|
||||
[DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow);
|
||||
|
||||
/// uiFlags: 0 - Count of GDI objects
|
||||
/// uiFlags: 1 - Count of USER objects
|
||||
/// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers)
|
||||
/// - Win32 USER objects:
|
||||
/// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, menu resources, raw data resources, string table entries, message table entries, cursors/icons)
|
||||
/// - Other USER objects (windows, menus)
|
||||
///
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern uint GetGuiResources(IntPtr hProcess, uint uiFlags);
|
||||
|
||||
[DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern uint RegisterWindowMessage(string lpString);
|
||||
|
||||
[DllImport("user32", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam, SendMessageTimeoutFlags fuFlags, uint uTimeout, out UIntPtr lpdwResult);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
private static extern bool GetPhysicalCursorPos(out POINT cursorLocation);
|
||||
|
||||
/// <summary>
|
||||
/// The following is used for Icon handling
|
||||
/// </summary>
|
||||
/// <param name="hIcon"></param>
|
||||
/// <returns></returns>
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern SafeIconHandle CopyIcon(IntPtr hIcon);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern bool DestroyIcon(IntPtr hIcon);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern bool GetCursorInfo(out CursorInfo cursorInfo);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern bool GetIconInfo(SafeIconHandle iconHandle, out IconInfo iconInfo);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr SetCapture(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool ReleaseCapture();
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern IntPtr OpenInputDesktop(uint dwFlags, bool fInherit, DesktopAccessRight dwDesiredAccess);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern bool SetThreadDesktop(IntPtr hDesktop);
|
||||
|
||||
[DllImport("user32", SetLastError = true)]
|
||||
public static extern bool CloseDesktop(IntPtr hDesktop);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the cursor location safely, accounting for DPI settings in Vista/Windows 7.
|
||||
/// </summary>
|
||||
/// <returns>Point with cursor location, relative to the origin of the monitor setup
|
||||
/// (i.e. negative coordinates arepossible in multiscreen setups)</returns>
|
||||
public static Point GetCursorLocation()
|
||||
{
|
||||
if (Environment.OSVersion.Version.Major >= 6 && _CanCallGetPhysicalCursorPos)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (GetPhysicalCursorPos(out var cursorLocation))
|
||||
{
|
||||
return new Point(cursorLocation.X, cursorLocation.Y);
|
||||
}
|
||||
|
||||
Win32Error error = Win32.GetLastErrorCode();
|
||||
LOG.ErrorFormat("Error retrieving PhysicalCursorPos : {0}", Win32.GetMessage(error));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LOG.Error("Exception retrieving PhysicalCursorPos, no longer calling this. Cause :", ex);
|
||||
_CanCallGetPhysicalCursorPos = false;
|
||||
}
|
||||
}
|
||||
|
||||
return new Point(Cursor.Position.X, Cursor.Position.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for the GetClassLong which decides if the system is 64-bit or not and calls the right one.
|
||||
/// </summary>
|
||||
/// <param name="hWnd">IntPtr</param>
|
||||
/// <param name="nIndex">int</param>
|
||||
/// <returns>IntPtr</returns>
|
||||
public static IntPtr GetClassLongWrapper(IntPtr hWnd, int nIndex)
|
||||
{
|
||||
if (IntPtr.Size > 4)
|
||||
{
|
||||
return GetClassLongPtr(hWnd, nIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new IntPtr(GetClassLong(hWnd, nIndex));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for the GetWindowLong which decides if the system is 64-bit or not and calls the right one.
|
||||
/// </summary>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="nIndex"></param>
|
||||
/// <returns></returns>
|
||||
public static IntPtr GetWindowLongWrapper(IntPtr hWnd, int nIndex)
|
||||
{
|
||||
if (IntPtr.Size == 8)
|
||||
{
|
||||
return GetWindowLongPtr(hWnd, nIndex);
|
||||
}
|
||||
|
||||
return GetWindowLong(hWnd, nIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper for the SetWindowLong which decides if the system is 64-bit or not and calls the right one.
|
||||
/// </summary>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="nIndex"></param>
|
||||
/// <param name="styleFlags"></param>
|
||||
public static void SetWindowLongWrapper(IntPtr hWnd, int nIndex, IntPtr styleFlags)
|
||||
{
|
||||
if (IntPtr.Size == 8)
|
||||
{
|
||||
SetWindowLongPtr(hWnd, nIndex, styleFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowLong(hWnd, nIndex, styleFlags.ToInt32());
|
||||
}
|
||||
}
|
||||
|
||||
public static uint GetGuiResourcesGDICount()
|
||||
{
|
||||
using var currentProcess = Process.GetCurrentProcess();
|
||||
return GetGuiResources(currentProcess.Handle, 0);
|
||||
}
|
||||
|
||||
public static uint GetGuiResourcesUserCount()
|
||||
{
|
||||
using var currentProcess = Process.GetCurrentProcess();
|
||||
return GetGuiResources(currentProcess.Handle, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to create a Win32 exception with the windows message in it
|
||||
/// </summary>
|
||||
/// <param name="method">string with current method</param>
|
||||
/// <returns>Exception</returns>
|
||||
public static Exception CreateWin32Exception(string method)
|
||||
{
|
||||
var exceptionToThrow = new Win32Exception();
|
||||
exceptionToThrow.Data.Add("Method", method);
|
||||
return exceptionToThrow;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
public static class Win32
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, [Out] StringBuilder lpBuffer, int nSize, IntPtr arguments);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern void SetLastError(uint dwErrCode);
|
||||
|
||||
public static Win32Error GetLastErrorCode()
|
||||
{
|
||||
return (Win32Error) Marshal.GetLastWin32Error();
|
||||
}
|
||||
|
||||
public static string GetMessage(Win32Error errorCode)
|
||||
{
|
||||
var buffer = new StringBuilder(0x100);
|
||||
|
||||
if (FormatMessage(0x3200, IntPtr.Zero, (uint) errorCode, 0, buffer, buffer.Capacity, IntPtr.Zero) == 0)
|
||||
{
|
||||
return "Unknown error (0x" + ((int) errorCode).ToString("x") + ")";
|
||||
}
|
||||
|
||||
var result = new StringBuilder();
|
||||
int i = 0;
|
||||
|
||||
while (i < buffer.Length)
|
||||
{
|
||||
if (!char.IsLetterOrDigit(buffer[i]) &&
|
||||
!char.IsPunctuation(buffer[i]) &&
|
||||
!char.IsSymbol(buffer[i]) &&
|
||||
!char.IsWhiteSpace(buffer[i]))
|
||||
break;
|
||||
|
||||
result.Append(buffer[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
return result.ToString().Replace("\r\n", string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
using System;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Used with SetWinEventHook
|
||||
/// </summary>
|
||||
/// <param name="hWinEventHook"></param>
|
||||
/// <param name="eventType"></param>
|
||||
/// <param name="hWnd"></param>
|
||||
/// <param name="idObject"></param>
|
||||
/// <param name="idChild"></param>
|
||||
/// <param name="dwEventThread"></param>
|
||||
/// <param name="dwmsEventTime"></param>
|
||||
public delegate void WinEventDelegate(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd, EventObjects idObject, int idChild, uint dwEventThread, uint dwmsEventTime);
|
||||
}
|
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Greenshot.Base.UnmanagedHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Windows Media
|
||||
/// </summary>
|
||||
public class WinMM
|
||||
{
|
||||
[DllImport("winmm.dll", SetLastError = true)]
|
||||
public static extern bool PlaySound(byte[] ptrToSound, UIntPtr hmod, uint fdwSound);
|
||||
|
||||
[DllImport("winmm.dll", SetLastError = true)]
|
||||
public static extern bool PlaySound(IntPtr ptrToSound, UIntPtr hmod, uint fdwSound);
|
||||
}
|
||||
}
|
|
@ -22,11 +22,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.User32.Enums;
|
||||
using Dapplo.Windows.User32.Structs;
|
||||
using Greenshot.Base.Effects;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Greenshot.Base.UnmanagedHelpers.Structs;
|
||||
using Greenshot.Editor.Drawing.Fields;
|
||||
|
||||
namespace Greenshot.Editor.Configuration
|
||||
|
@ -50,16 +51,16 @@ namespace Greenshot.Editor.Configuration
|
|||
public WindowPlacementFlags WindowPlacementFlags { get; set; }
|
||||
|
||||
[IniProperty("WindowShowCommand", Description = "Show command", DefaultValue = "Normal")]
|
||||
public ShowWindowCommand ShowWindowCommand { get; set; }
|
||||
public ShowWindowCommands ShowWindowCommand { get; set; }
|
||||
|
||||
[IniProperty("WindowMinPosition", Description = "Position of minimized window", DefaultValue = "-1,-1")]
|
||||
public Point WindowMinPosition { get; set; }
|
||||
public NativePoint WindowMinPosition { get; set; }
|
||||
|
||||
[IniProperty("WindowMaxPosition", Description = "Position of maximized window", DefaultValue = "-1,-1")]
|
||||
public Point WindowMaxPosition { get; set; }
|
||||
public NativePoint WindowMaxPosition { get; set; }
|
||||
|
||||
[IniProperty("WindowNormalPosition", Description = "Position of normal window", DefaultValue = "100,100,400,400")]
|
||||
public Rectangle WindowNormalPosition { get; set; }
|
||||
public NativeRect WindowNormalPosition { get; set; }
|
||||
|
||||
[IniProperty("ReuseEditor", Description = "Reuse already open editor", DefaultValue = "false")]
|
||||
public bool ReuseEditor { get; set; }
|
||||
|
@ -77,7 +78,7 @@ namespace Greenshot.Editor.Configuration
|
|||
public TornEdgeEffect TornEdgeEffectSettings { get; set; }
|
||||
|
||||
[IniProperty("DefaultEditorSize", Description = "The size for the editor when it's opened without a capture", DefaultValue = "500,500")]
|
||||
public Size DefaultEditorSize { get; set; }
|
||||
public NativeSize DefaultEditorSize { get; set; }
|
||||
|
||||
|
||||
public override void AfterLoad()
|
||||
|
@ -151,19 +152,19 @@ namespace Greenshot.Editor.Configuration
|
|||
|
||||
public void ResetEditorPlacement()
|
||||
{
|
||||
WindowNormalPosition = new Rectangle(100, 100, 400, 400);
|
||||
WindowMaxPosition = new Point(-1, -1);
|
||||
WindowMinPosition = new Point(-1, -1);
|
||||
WindowNormalPosition = new NativeRect(100, 100, 400, 400);
|
||||
WindowMaxPosition = new NativePoint(-1, -1);
|
||||
WindowMinPosition = new NativePoint(-1, -1);
|
||||
WindowPlacementFlags = 0;
|
||||
ShowWindowCommand = ShowWindowCommand.Normal;
|
||||
ShowWindowCommand = ShowWindowCommands.Normal;
|
||||
}
|
||||
|
||||
public WindowPlacement GetEditorPlacement()
|
||||
{
|
||||
WindowPlacement placement = WindowPlacement.Default;
|
||||
placement.NormalPosition = new RECT(WindowNormalPosition);
|
||||
placement.MaxPosition = new POINT(WindowMaxPosition);
|
||||
placement.MinPosition = new POINT(WindowMinPosition);
|
||||
WindowPlacement placement = WindowPlacement.Create();
|
||||
placement.NormalPosition = WindowNormalPosition;
|
||||
placement.MaxPosition = WindowMaxPosition;
|
||||
placement.MinPosition = WindowMinPosition;
|
||||
placement.ShowCmd = ShowWindowCommand;
|
||||
placement.Flags = WindowPlacementFlags;
|
||||
return placement;
|
||||
|
@ -171,9 +172,9 @@ namespace Greenshot.Editor.Configuration
|
|||
|
||||
public void SetEditorPlacement(WindowPlacement placement)
|
||||
{
|
||||
WindowNormalPosition = placement.NormalPosition.ToRectangle();
|
||||
WindowMaxPosition = placement.MaxPosition.ToPoint();
|
||||
WindowMinPosition = placement.MinPosition.ToPoint();
|
||||
WindowNormalPosition = placement.NormalPosition;
|
||||
WindowMaxPosition = placement.MaxPosition;
|
||||
WindowMinPosition = placement.MinPosition;
|
||||
ShowWindowCommand = placement.ShowCmd;
|
||||
WindowPlacementFlags = placement.Flags;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Controls;
|
||||
using ColorDialog = Greenshot.Editor.Forms.ColorDialog;
|
||||
|
||||
|
@ -65,7 +66,7 @@ namespace Greenshot.Editor.Controls
|
|||
if (Image != null)
|
||||
{
|
||||
using Graphics graphics = Graphics.FromImage(Image);
|
||||
graphics.FillRectangle(brush, new Rectangle(4, 17, 16, 3));
|
||||
graphics.FillRectangle(brush, new NativeRect(4, 17, 16, 3));
|
||||
}
|
||||
|
||||
// cleanup GDI Object
|
||||
|
|
|
@ -23,6 +23,7 @@ using System;
|
|||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
|
||||
namespace Greenshot.Editor.Controls
|
||||
{
|
||||
|
@ -113,12 +114,12 @@ namespace Greenshot.Editor.Controls
|
|||
/// <summary>
|
||||
/// Helper method to draw the string
|
||||
/// </summary>
|
||||
/// <param name="graphics"></param>
|
||||
/// <param name="fontFamily"></param>
|
||||
/// <param name="fontStyle"></param>
|
||||
/// <param name="bounds"></param>
|
||||
/// <param name="text"></param>
|
||||
private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, Rectangle bounds, string text)
|
||||
/// <param name="graphics">Graphics</param>
|
||||
/// <param name="fontFamily">FontFamily</param>
|
||||
/// <param name="fontStyle">FontStyle</param>
|
||||
/// <param name="bounds">NativeRect</param>
|
||||
/// <param name="text">string</param>
|
||||
private void DrawText(Graphics graphics, FontFamily fontFamily, FontStyle fontStyle, NativeRect bounds, string text)
|
||||
{
|
||||
using Font font = new Font(fontFamily, Font.Size + 5, fontStyle, GraphicsUnit.Pixel);
|
||||
// Make sure the text is visible by centering it in the line
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Dapplo.Windows.Messages.Enumerations;
|
||||
|
||||
namespace Greenshot.Editor.Controls
|
||||
{
|
||||
|
|
|
@ -23,8 +23,11 @@ using System;
|
|||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Base.UnmanagedHelpers;
|
||||
using Greenshot.Base.UnmanagedHelpers.Enums;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.Icons;
|
||||
using Dapplo.Windows.Icons.SafeHandles;
|
||||
using Dapplo.Windows.Messages.Enumerations;
|
||||
using Dapplo.Windows.User32;
|
||||
using Greenshot.Editor.Forms;
|
||||
using ColorDialog = Greenshot.Editor.Forms.ColorDialog;
|
||||
|
||||
|
@ -65,11 +68,10 @@ namespace Greenshot.Editor.Controls
|
|||
private static Cursor CreateCursor(Bitmap bitmap, int hotspotX, int hotspotY)
|
||||
{
|
||||
using SafeIconHandle iconHandle = new SafeIconHandle(bitmap.GetHicon());
|
||||
User32.GetIconInfo(iconHandle, out var iconInfo);
|
||||
iconInfo.xHotspot = hotspotX;
|
||||
iconInfo.yHotspot = hotspotY;
|
||||
iconInfo.fIcon = false;
|
||||
var icon = User32.CreateIconIndirect(ref iconInfo);
|
||||
NativeIconMethods.GetIconInfo(iconHandle, out var iconInfo);
|
||||
iconInfo.Hotspot = new NativePoint(hotspotX, hotspotY);
|
||||
iconInfo.IsIcon = false;
|
||||
var icon = NativeIconMethods.CreateIconIndirect(ref iconInfo);
|
||||
return new Cursor(icon);
|
||||
}
|
||||
|
||||
|
@ -110,7 +112,7 @@ namespace Greenshot.Editor.Controls
|
|||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
User32.SetCapture(Handle);
|
||||
User32Api.SetCapture(Handle);
|
||||
_movableShowColorForm.MoveTo(PointToScreen(new Point(e.X, e.Y)));
|
||||
}
|
||||
|
||||
|
@ -126,8 +128,8 @@ namespace Greenshot.Editor.Controls
|
|||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
//Release Capture should consume MouseUp when canceled with the escape key
|
||||
User32.ReleaseCapture();
|
||||
PipetteUsed?.Invoke(this, new PipetteUsedArgs(_movableShowColorForm.color));
|
||||
User32Api.ReleaseCapture();
|
||||
PipetteUsed?.Invoke(this, new PipetteUsedArgs(_movableShowColorForm.Color));
|
||||
}
|
||||
|
||||
base.OnMouseUp(e);
|
||||
|
@ -183,7 +185,7 @@ namespace Greenshot.Editor.Controls
|
|||
{
|
||||
if ((int) m.WParam == VkEsc)
|
||||
{
|
||||
User32.ReleaseCapture();
|
||||
User32Api.ReleaseCapture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ using System.ComponentModel;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Controls;
|
||||
using ColorDialog = Greenshot.Editor.Forms.ColorDialog;
|
||||
|
||||
|
@ -63,7 +64,7 @@ namespace Greenshot.Editor.Controls
|
|||
if (Image != null)
|
||||
{
|
||||
using Graphics graphics = Graphics.FromImage(Image);
|
||||
graphics.FillRectangle(brush, new Rectangle(0, 13, 16, 3));
|
||||
graphics.FillRectangle(brush, new NativeRect(0, 13, 16, 3));
|
||||
}
|
||||
|
||||
// cleanup GDI Object
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Greenshot.Base.Core;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Dapplo.Windows.Dpi;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Base.Interfaces.Drawing.Adorners;
|
||||
|
||||
|
@ -32,12 +34,12 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
{
|
||||
public virtual EditStatus EditStatus { get; protected set; } = EditStatus.IDLE;
|
||||
|
||||
private static readonly Size DefaultSize = new Size(6, 6);
|
||||
protected Size _size;
|
||||
private static readonly NativeSize DefaultSize = new NativeSize(6, 6);
|
||||
protected NativeSize _size;
|
||||
|
||||
public AbstractAdorner(IDrawableContainer owner)
|
||||
{
|
||||
_size = DpiHelper.ScaleWithDpi(DefaultSize, 0);
|
||||
_size = DpiCalculator.ScaleWithDpi(DefaultSize, 0);
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
|
@ -54,12 +56,11 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// <summary>
|
||||
/// Test if the point is inside the adorner
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool HitTest(Point point)
|
||||
/// <param name="point">NativePoint</param>
|
||||
/// <returns>bool</returns>
|
||||
public virtual bool HitTest(NativePoint point)
|
||||
{
|
||||
Rectangle hitBounds = Bounds;
|
||||
hitBounds.Inflate(3, 3);
|
||||
NativeRect hitBounds = Bounds.Inflate(3, 3);
|
||||
return hitBounds.Contains(point);
|
||||
}
|
||||
|
||||
|
@ -94,29 +95,29 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// <summary>
|
||||
/// Return the location of the adorner
|
||||
/// </summary>
|
||||
public virtual Point Location { get; set; }
|
||||
public virtual NativePoint Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Return the bounds of the Adorner
|
||||
/// </summary>
|
||||
public virtual Rectangle Bounds
|
||||
public virtual NativeRect Bounds
|
||||
{
|
||||
get
|
||||
{
|
||||
Point location = Location;
|
||||
return new Rectangle(location.X - (_size.Width / 2), location.Y - (_size.Height / 2), _size.Width, _size.Height);
|
||||
NativePoint location = Location;
|
||||
return new NativeRect(location.X - (_size.Width / 2), location.Y - (_size.Height / 2), _size.Width, _size.Height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the bounds of the Adorner as displayed on the parent Surface
|
||||
/// </summary>
|
||||
protected virtual Rectangle BoundsOnSurface
|
||||
protected virtual NativeRect BoundsOnSurface
|
||||
{
|
||||
get
|
||||
{
|
||||
Point displayLocation = Owner.Parent.ToSurfaceCoordinates(Location);
|
||||
return new Rectangle(displayLocation.X - _size.Width / 2, displayLocation.Y - _size.Height / 2, _size.Width, _size.Height);
|
||||
NativePoint displayLocation = Owner.Parent.ToSurfaceCoordinates(Location);
|
||||
return new NativeRect(displayLocation.X - _size.Width / 2, displayLocation.Y - _size.Height / 2, _size.Width, _size.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,9 +133,9 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// Adjust UI elements to the supplied DPI settings
|
||||
/// </summary>
|
||||
/// <param name="dpi">uint</param>
|
||||
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;
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Editor.Helpers;
|
||||
|
||||
|
@ -32,8 +32,8 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// </summary>
|
||||
public class MoveAdorner : AbstractAdorner
|
||||
{
|
||||
private Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||
private RectangleF _boundsAfterResize = RectangleF.Empty;
|
||||
private NativeRect _boundsBeforeResize = NativeRect.Empty;
|
||||
private NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty;
|
||||
|
||||
public Positions Position { get; private set; }
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
public override void MouseDown(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
EditStatus = EditStatus.RESIZING;
|
||||
_boundsBeforeResize = new Rectangle(Owner.Left, Owner.Top, Owner.Width, Owner.Height);
|
||||
_boundsBeforeResize = new NativeRect(Owner.Left, Owner.Top, Owner.Width, Owner.Height);
|
||||
_boundsAfterResize = _boundsBeforeResize;
|
||||
}
|
||||
|
||||
|
@ -75,10 +75,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
Owner.MakeBoundsChangeUndoable(false);
|
||||
|
||||
// reset "workbench" rectangle to current bounds
|
||||
_boundsAfterResize.X = _boundsBeforeResize.X;
|
||||
_boundsAfterResize.Y = _boundsBeforeResize.Y;
|
||||
_boundsAfterResize.Width = _boundsBeforeResize.Width;
|
||||
_boundsAfterResize.Height = _boundsBeforeResize.Height;
|
||||
_boundsAfterResize = _boundsBeforeResize;
|
||||
|
||||
// calculate scaled rectangle
|
||||
ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());
|
||||
|
@ -92,7 +89,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// <summary>
|
||||
/// Return the location of the adorner
|
||||
/// </summary>
|
||||
public override Point Location
|
||||
public override NativePoint Location
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -133,7 +130,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
break;
|
||||
}
|
||||
|
||||
return new Point(x, y);
|
||||
return new NativePoint(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
*/
|
||||
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Editor.Helpers;
|
||||
|
||||
|
@ -32,8 +32,8 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// </summary>
|
||||
public class ResizeAdorner : AbstractAdorner
|
||||
{
|
||||
private Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||
private RectangleF _boundsAfterResize = RectangleF.Empty;
|
||||
private NativeRect _boundsBeforeResize = NativeRect.Empty;
|
||||
private NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty;
|
||||
|
||||
public Positions Position { get; private set; }
|
||||
|
||||
|
@ -55,23 +55,18 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
isNotSwitched = !isNotSwitched;
|
||||
}
|
||||
|
||||
switch (Position)
|
||||
return Position switch
|
||||
{
|
||||
case Positions.TopLeft:
|
||||
case Positions.BottomRight:
|
||||
return isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW;
|
||||
case Positions.TopRight:
|
||||
case Positions.BottomLeft:
|
||||
return isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE;
|
||||
case Positions.MiddleLeft:
|
||||
case Positions.MiddleRight:
|
||||
return Cursors.SizeWE;
|
||||
case Positions.TopCenter:
|
||||
case Positions.BottomCenter:
|
||||
return Cursors.SizeNS;
|
||||
default:
|
||||
return Cursors.SizeAll;
|
||||
}
|
||||
Positions.TopLeft => isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW,
|
||||
Positions.BottomRight => isNotSwitched ? Cursors.SizeNWSE : Cursors.SizeNESW,
|
||||
Positions.TopRight => isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE,
|
||||
Positions.BottomLeft => isNotSwitched ? Cursors.SizeNESW : Cursors.SizeNWSE,
|
||||
Positions.MiddleLeft => Cursors.SizeWE,
|
||||
Positions.MiddleRight => Cursors.SizeWE,
|
||||
Positions.TopCenter => Cursors.SizeNS,
|
||||
Positions.BottomCenter => Cursors.SizeNS,
|
||||
_ => Cursors.SizeAll
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +78,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
public override void MouseDown(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
EditStatus = EditStatus.RESIZING;
|
||||
_boundsBeforeResize = new Rectangle(Owner.Left, Owner.Top, Owner.Width, Owner.Height);
|
||||
_boundsBeforeResize = new NativeRect(Owner.Left, Owner.Top, Owner.Width, Owner.Height);
|
||||
_boundsAfterResize = _boundsBeforeResize;
|
||||
}
|
||||
|
||||
|
@ -103,10 +98,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
Owner.MakeBoundsChangeUndoable(false);
|
||||
|
||||
// reset "workbench" rectangle to current bounds
|
||||
_boundsAfterResize.X = _boundsBeforeResize.X;
|
||||
_boundsAfterResize.Y = _boundsBeforeResize.Y;
|
||||
_boundsAfterResize.Width = _boundsBeforeResize.Width;
|
||||
_boundsAfterResize.Height = _boundsBeforeResize.Height;
|
||||
_boundsAfterResize = _boundsBeforeResize;
|
||||
|
||||
// calculate scaled rectangle
|
||||
ScaleHelper.Scale(ref _boundsAfterResize, Position, new PointF(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());
|
||||
|
@ -120,7 +112,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
/// <summary>
|
||||
/// Return the location of the adorner
|
||||
/// </summary>
|
||||
public override Point Location
|
||||
public override NativePoint Location
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
|
||||
namespace Greenshot.Editor.Drawing.Adorners
|
||||
|
@ -61,30 +63,30 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
}
|
||||
|
||||
Owner.Invalidate();
|
||||
Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y);
|
||||
Rectangle imageBounds = new Rectangle(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height);
|
||||
NativePoint newGripperLocation = new NativePoint(mouseEventArgs.X, mouseEventArgs.Y);
|
||||
NativeRect imageBounds = new NativeRect(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height);
|
||||
// Check if gripper inside the parent (surface), if not we need to move it inside
|
||||
// This was made for BUG-1682
|
||||
if (!imageBounds.Contains(newGripperLocation))
|
||||
{
|
||||
if (newGripperLocation.X > imageBounds.Right)
|
||||
{
|
||||
newGripperLocation.X = imageBounds.Right - 5;
|
||||
newGripperLocation = newGripperLocation.ChangeX(imageBounds.Right - 5);
|
||||
}
|
||||
|
||||
if (newGripperLocation.X < imageBounds.Left)
|
||||
{
|
||||
newGripperLocation.X = imageBounds.Left;
|
||||
newGripperLocation = newGripperLocation.ChangeX(imageBounds.Left);
|
||||
}
|
||||
|
||||
if (newGripperLocation.Y > imageBounds.Bottom)
|
||||
{
|
||||
newGripperLocation.Y = imageBounds.Bottom - 5;
|
||||
newGripperLocation = newGripperLocation.ChangeY(imageBounds.Bottom - 5);
|
||||
}
|
||||
|
||||
if (newGripperLocation.Y < imageBounds.Top)
|
||||
{
|
||||
newGripperLocation.Y = imageBounds.Top;
|
||||
newGripperLocation = newGripperLocation.ChangeY(imageBounds.Top);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,7 +105,7 @@ namespace Greenshot.Editor.Drawing.Adorners
|
|||
return;
|
||||
}
|
||||
|
||||
Point[] points = new[]
|
||||
Point[] points = new Point[]
|
||||
{
|
||||
Location
|
||||
};
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Editor.Drawing.Fields;
|
||||
|
@ -115,7 +117,7 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
public override Rectangle DrawingBounds
|
||||
public override NativeRect DrawingBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -130,12 +132,11 @@ namespace Greenshot.Editor.Drawing
|
|||
using GraphicsPath path = new GraphicsPath();
|
||||
path.AddLine(Left, Top, Left + Width, Top + Height);
|
||||
using Matrix matrix = new Matrix();
|
||||
Rectangle drawingBounds = Rectangle.Round(path.GetBounds(matrix, pen));
|
||||
drawingBounds.Inflate(2, 2);
|
||||
return drawingBounds;
|
||||
NativeRect drawingBounds = Rectangle.Round(path.GetBounds(matrix, pen));
|
||||
return drawingBounds.Inflate(2, 2);
|
||||
}
|
||||
|
||||
return Rectangle.Empty;
|
||||
return NativeRect.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
using System.Drawing;
|
||||
using System.Runtime.Serialization;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Editor.Drawing.Adorners;
|
||||
|
@ -141,16 +143,16 @@ namespace Greenshot.Editor.Drawing
|
|||
/// We need to override the DrawingBound, return a rectangle in the size of the image, to make sure this element is always draw
|
||||
/// (we create a transparent brown over the complete picture)
|
||||
/// </summary>
|
||||
public override Rectangle DrawingBounds
|
||||
public override NativeRect DrawingBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_parent?.Image is { } image)
|
||||
{
|
||||
return new Rectangle(0, 0, image.Width, image.Height);
|
||||
return new NativeRect(0, 0, image.Width, image.Height);
|
||||
}
|
||||
|
||||
return Rectangle.Empty;
|
||||
return NativeRect.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,8 +165,8 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
|
||||
using Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100));
|
||||
Rectangle cropRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
Rectangle selectionRect = new Rectangle(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);
|
||||
var cropRectangle = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||
var selectionRect = new NativeRect(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);
|
||||
Size imageSize = _parent.Image.Size;
|
||||
|
||||
DrawSelectionBorder(g, selectionRect);
|
||||
|
@ -225,10 +227,7 @@ namespace Greenshot.Editor.Drawing
|
|||
//allow only horizontal changes
|
||||
if (_parent?.Image is { } image)
|
||||
{
|
||||
_boundsAfterResize.X = 0;
|
||||
_boundsAfterResize.Y = _boundsBeforeResize.Top;
|
||||
_boundsAfterResize.Width = image.Width;
|
||||
_boundsAfterResize.Height = y - _boundsAfterResize.Top;
|
||||
_boundsAfterResize = new NativeRectFloat(0, _boundsBeforeResize.Top, image.Width, y - _boundsAfterResize.Top);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -238,23 +237,18 @@ namespace Greenshot.Editor.Drawing
|
|||
//allow only vertical changes
|
||||
if (_parent?.Image is { } image)
|
||||
{
|
||||
_boundsAfterResize.X = _boundsBeforeResize.Left;
|
||||
_boundsAfterResize.Y = 0;
|
||||
_boundsAfterResize.Width = x - _boundsAfterResize.Left;
|
||||
_boundsAfterResize.Height = image.Height;
|
||||
_boundsAfterResize = new NativeRectFloat(_boundsBeforeResize.Left, 0, x - _boundsAfterResize.Left, image.Height);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// reset "workbench" rectangle to current bounds
|
||||
_boundsAfterResize.X = _boundsBeforeResize.Left;
|
||||
_boundsAfterResize.Y = _boundsBeforeResize.Top;
|
||||
_boundsAfterResize.Width = x - _boundsAfterResize.Left;
|
||||
_boundsAfterResize.Height = y - _boundsAfterResize.Top;
|
||||
_boundsAfterResize = new NativeRectFloat(
|
||||
_boundsBeforeResize.Left, _boundsBeforeResize.Top,
|
||||
x - _boundsAfterResize.Left, y - _boundsAfterResize.Top);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor());
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ using System.Drawing.Drawing2D;
|
|||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using log4net;
|
||||
|
@ -124,6 +125,6 @@ namespace Greenshot.Editor.Drawing
|
|||
cursor.DrawStretched(graphics, Bounds);
|
||||
}
|
||||
|
||||
public override Size DefaultSize => cursor?.Size ?? new Size(16, 16);
|
||||
public override NativeSize DefaultSize => cursor?.Size ?? new NativeSize(16, 16);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ using System.Drawing.Drawing2D;
|
|||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.IniFile;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
|
@ -228,9 +230,9 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
public Point Location
|
||||
public NativePoint Location
|
||||
{
|
||||
get => new Point(left, top);
|
||||
get => new NativePoint(left, top);
|
||||
set
|
||||
{
|
||||
left = value.X;
|
||||
|
@ -238,9 +240,9 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
public Size Size
|
||||
public NativeSize Size
|
||||
{
|
||||
get => new Size(width, height);
|
||||
get => new NativeSize(width, height);
|
||||
set
|
||||
{
|
||||
width = value.Width;
|
||||
|
@ -257,15 +259,15 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
[NonSerialized]
|
||||
// will store current bounds of this DrawableContainer before starting a resize
|
||||
protected Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||
protected NativeRect _boundsBeforeResize = NativeRect.Empty;
|
||||
|
||||
[NonSerialized]
|
||||
// "workbench" rectangle - used for calculating bounds during resizing (to be applied to this DrawableContainer afterwards)
|
||||
protected RectangleF _boundsAfterResize = RectangleF.Empty;
|
||||
protected NativeRectFloat _boundsAfterResize = NativeRectFloat.Empty;
|
||||
|
||||
public Rectangle Bounds
|
||||
public NativeRect Bounds
|
||||
{
|
||||
get => GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
get => new NativeRect(Left, Top, Width, Height).Normalize();
|
||||
set
|
||||
{
|
||||
Left = Round(value.Left);
|
||||
|
@ -275,7 +277,7 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
}
|
||||
|
||||
public virtual void ApplyBounds(RectangleF newBounds)
|
||||
public virtual void ApplyBounds(NativeRectFloat newBounds)
|
||||
{
|
||||
Left = Round(newBounds.Left);
|
||||
Top = Round(newBounds.Top);
|
||||
|
@ -308,7 +310,7 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
private bool accountForShadowChange;
|
||||
|
||||
public virtual Rectangle DrawingBounds
|
||||
public virtual NativeRect DrawingBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -316,7 +318,7 @@ namespace Greenshot.Editor.Drawing
|
|||
{
|
||||
if (filter.Invert)
|
||||
{
|
||||
return new Rectangle(Point.Empty, _parent.Image.Size);
|
||||
return new NativeRect(Point.Empty, _parent.Image.Size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,7 +342,7 @@ namespace Greenshot.Editor.Drawing
|
|||
shadow += 10;
|
||||
}
|
||||
|
||||
return new Rectangle(Bounds.Left - offset, Bounds.Top - offset, Bounds.Width + lineThickness + shadow, Bounds.Height + lineThickness + shadow);
|
||||
return new NativeRect(Bounds.Left - offset, Bounds.Top - offset, Bounds.Width + lineThickness + shadow, Bounds.Height + lineThickness + shadow);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,8 +366,8 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <summary>
|
||||
/// Initialize a target gripper
|
||||
/// </summary>
|
||||
/// <param name="location">Point</param>
|
||||
protected void InitTargetAdorner(Point location)
|
||||
/// <param name="location">NativePoint</param>
|
||||
protected void InitTargetAdorner(NativePoint location)
|
||||
{
|
||||
_targetAdorner = new TargetAdorner(this, location);
|
||||
Adorners.Add(_targetAdorner);
|
||||
|
@ -396,7 +398,7 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
public abstract void Draw(Graphics graphics, RenderMode renderMode);
|
||||
|
||||
public virtual void DrawContent(Graphics graphics, Bitmap bmp, RenderMode renderMode, Rectangle clipRectangle)
|
||||
public virtual void DrawContent(Graphics graphics, Bitmap bmp, RenderMode renderMode, NativeRect clipRectangle)
|
||||
{
|
||||
if (Children.Count > 0)
|
||||
{
|
||||
|
@ -416,8 +418,7 @@ namespace Greenshot.Editor.Drawing
|
|||
}
|
||||
else
|
||||
{
|
||||
Rectangle drawingRect = new Rectangle(Bounds.Location, Bounds.Size);
|
||||
drawingRect.Intersect(clipRectangle);
|
||||
var drawingRect = new NativeRect(Bounds.Location, Bounds.Size).Intersect(clipRectangle);
|
||||
if (filter is MagnifierFilter)
|
||||
{
|
||||
// quick&dirty bugfix, because MagnifierFilter behaves differently when drawn only partially
|
||||
|
@ -441,7 +442,7 @@ namespace Greenshot.Editor.Drawing
|
|||
/// Adjust UI elements to the supplied DPI settings
|
||||
/// </summary>
|
||||
/// <param name="dpi">uint with dpi value</param>
|
||||
public void AdjustToDpi(uint dpi)
|
||||
public void AdjustToDpi(int dpi)
|
||||
{
|
||||
foreach (var adorner in Adorners)
|
||||
{
|
||||
|
@ -462,12 +463,12 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
public virtual bool ClickableAt(int x, int y)
|
||||
{
|
||||
Rectangle r = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
r.Inflate(5, 5);
|
||||
var r = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||
r = r.Inflate(5, 5);
|
||||
return r.Contains(x, y);
|
||||
}
|
||||
|
||||
protected void DrawSelectionBorder(Graphics g, Rectangle rect)
|
||||
protected void DrawSelectionBorder(Graphics g, NativeRect rect)
|
||||
{
|
||||
using Pen pen = new Pen(Color.MediumSeaGreen)
|
||||
{
|
||||
|
@ -513,8 +514,9 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <returns>true if the event is handled, false if the surface needs to handle it</returns>
|
||||
public virtual bool HandleMouseDown(int x, int y)
|
||||
{
|
||||
Left = _boundsBeforeResize.X = x;
|
||||
Top = _boundsBeforeResize.Y = y;
|
||||
_boundsBeforeResize = _boundsBeforeResize.MoveTo(x, y);
|
||||
Left = x;
|
||||
Top = y;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -529,10 +531,7 @@ namespace Greenshot.Editor.Drawing
|
|||
Invalidate();
|
||||
|
||||
// reset "workbench" rectangle to current bounds
|
||||
_boundsAfterResize.X = _boundsBeforeResize.Left;
|
||||
_boundsAfterResize.Y = _boundsBeforeResize.Top;
|
||||
_boundsAfterResize.Width = x - _boundsAfterResize.Left;
|
||||
_boundsAfterResize.Height = y - _boundsAfterResize.Top;
|
||||
_boundsAfterResize = _boundsBeforeResize;
|
||||
|
||||
ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor());
|
||||
|
||||
|
@ -676,7 +675,7 @@ namespace Greenshot.Editor.Drawing
|
|||
|
||||
public virtual bool HasDefaultSize => false;
|
||||
|
||||
public virtual Size DefaultSize => throw new NotSupportedException("Object doesn't have a default size");
|
||||
public virtual NativeSize DefaultSize => throw new NotSupportedException("Object doesn't have a default size");
|
||||
|
||||
/// <summary>
|
||||
/// Allows to override the initializing of the fields, so we can actually have our own defaults
|
||||
|
|
|
@ -27,6 +27,8 @@ using System.Drawing.Drawing2D;
|
|||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Core;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
|
@ -258,7 +260,7 @@ namespace Greenshot.Editor.Drawing
|
|||
/// </summary>
|
||||
/// <param name="clipRectangle"></param>
|
||||
/// <returns>true if an filter intersects</returns>
|
||||
public bool HasIntersectingFilters(Rectangle clipRectangle)
|
||||
public bool HasIntersectingFilters(NativeRect clipRectangle)
|
||||
{
|
||||
foreach (var dc in this)
|
||||
{
|
||||
|
@ -274,9 +276,9 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <summary>
|
||||
/// Check if any of the drawableContainers are inside the rectangle
|
||||
/// </summary>
|
||||
/// <param name="clipRectangle"></param>
|
||||
/// <param name="clipRectangle">NativeRect</param>
|
||||
/// <returns></returns>
|
||||
public bool IntersectsWith(Rectangle clipRectangle)
|
||||
public bool IntersectsWith(NativeRect clipRectangle)
|
||||
{
|
||||
foreach (var dc in this)
|
||||
{
|
||||
|
@ -293,19 +295,19 @@ namespace Greenshot.Editor.Drawing
|
|||
/// A rectangle containing DrawingBounds of all drawableContainers in this list,
|
||||
/// or empty rectangle if nothing is there.
|
||||
/// </summary>
|
||||
public Rectangle DrawingBounds
|
||||
public NativeRect DrawingBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
return NativeRect.Empty;
|
||||
}
|
||||
|
||||
var result = this[0].DrawingBounds;
|
||||
for (int i = 1; i < Count; i++)
|
||||
{
|
||||
result = Rectangle.Union(result, this[i].DrawingBounds);
|
||||
result = result.Union(this[i].DrawingBounds);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -318,8 +320,8 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <param name="g">the to the bitmap related Graphics object</param>
|
||||
/// <param name="bitmap">Bitmap to draw</param>
|
||||
/// <param name="renderMode">the RenderMode in which the element is to be drawn</param>
|
||||
/// <param name="clipRectangle"></param>
|
||||
public void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, Rectangle clipRectangle)
|
||||
/// <param name="clipRectangle">NativeRect</param>
|
||||
public void Draw(Graphics g, Bitmap bitmap, RenderMode renderMode, NativeRect clipRectangle)
|
||||
{
|
||||
if (Parent == null)
|
||||
{
|
||||
|
@ -365,10 +367,10 @@ namespace Greenshot.Editor.Drawing
|
|||
return;
|
||||
}
|
||||
|
||||
Rectangle region = Rectangle.Empty;
|
||||
NativeRect region = NativeRect.Empty;
|
||||
foreach (var dc in this)
|
||||
{
|
||||
region = Rectangle.Union(region, dc.DrawingBounds);
|
||||
region = region.Union(dc.DrawingBounds);
|
||||
}
|
||||
|
||||
Parent.InvalidateElements(region);
|
||||
|
@ -770,8 +772,8 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <summary>
|
||||
/// Adjust UI elements to the supplied DPI settings
|
||||
/// </summary>
|
||||
/// <param name="dpi"></param>
|
||||
public void AdjustToDpi(uint dpi)
|
||||
/// <param name="dpi">int</param>
|
||||
public void AdjustToDpi(int dpi)
|
||||
{
|
||||
foreach (var drawableContainer in this)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,8 @@ using System;
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Runtime.Serialization;
|
||||
using Dapplo.Windows.Common.Extensions;
|
||||
using Dapplo.Windows.Common.Structs;
|
||||
using Greenshot.Base.Interfaces;
|
||||
using Greenshot.Base.Interfaces.Drawing;
|
||||
using Greenshot.Editor.Drawing.Fields;
|
||||
|
@ -71,7 +73,7 @@ namespace Greenshot.Editor.Drawing
|
|||
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
|
||||
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
var rect = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||
DrawEllipse(rect, graphics, renderMode, lineThickness, lineColor, fillColor, shadow);
|
||||
}
|
||||
|
||||
|
@ -85,7 +87,7 @@ namespace Greenshot.Editor.Drawing
|
|||
/// <param name="lineColor"></param>
|
||||
/// <param name="fillColor"></param>
|
||||
/// <param name="shadow"></param>
|
||||
public static void DrawEllipse(Rectangle rect, Graphics graphics, RenderMode renderMode, int lineThickness, Color lineColor, Color fillColor, bool shadow)
|
||||
public static void DrawEllipse(NativeRect rect, Graphics graphics, RenderMode renderMode, int lineThickness, Color lineColor, Color fillColor, bool shadow)
|
||||
{
|
||||
bool lineVisible = lineThickness > 0 && Colors.IsVisible(lineColor);
|
||||
// draw shadow before anything else
|
||||
|
@ -101,7 +103,7 @@ namespace Greenshot.Editor.Drawing
|
|||
{
|
||||
Width = lineVisible ? lineThickness : 1
|
||||
};
|
||||
Rectangle shadowRect = GuiRectangle.GetGuiRectangle(rect.Left + currentStep, rect.Top + currentStep, rect.Width, rect.Height);
|
||||
var shadowRect = new NativeRect(rect.Left + currentStep, rect.Top + currentStep, rect.Width, rect.Height).Normalize();
|
||||
graphics.DrawEllipse(shadowPen, shadowRect);
|
||||
currentStep++;
|
||||
alpha -= basealpha / steps;
|
||||
|
@ -146,11 +148,11 @@ namespace Greenshot.Editor.Drawing
|
|||
{
|
||||
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS) + 10;
|
||||
Color fillColor = GetFieldValueAsColor(FieldType.FILL_COLOR);
|
||||
Rectangle rect = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
var rect = new NativeRect(Left, Top, Width, Height).Normalize();
|
||||
return EllipseClickableAt(rect, lineThickness, fillColor, x, y);
|
||||
}
|
||||
|
||||
public static bool EllipseClickableAt(Rectangle rect, int lineThickness, Color fillColor, int x, int y)
|
||||
public static bool EllipseClickableAt(NativeRect rect, int lineThickness, Color fillColor, int x, int y)
|
||||
{
|
||||
// If we clicked inside the rectangle and it's visible we are clickable at.
|
||||
if (!Color.Transparent.Equals(fillColor))
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue