mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 14:03:23 -07:00
BUG-1890: Fixed wrong cropping when window is maximized on Windows 10
This commit is contained in:
parent
5c04af1684
commit
728f49944f
3 changed files with 109 additions and 8 deletions
92
GreenshotPlugin/Core/OperatingSystemExtensions.cs
Normal file
92
GreenshotPlugin/Core/OperatingSystemExtensions.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
* For more information see: http://getgreenshot.org/
|
||||
* The Greenshot project is hosted on GitHub: https://github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace GreenshotPlugin.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Extensions to help with querying the Operating System
|
||||
/// </summary>
|
||||
public static class OperatingSystemExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Test if the current OS is Windows 10
|
||||
/// </summary>
|
||||
/// <param name="operatingSystem">OperatingSystem from Environment.OSVersion</param>
|
||||
/// <returns>true if we are running on Windows 10</returns>
|
||||
public static bool IsWindows10(this OperatingSystem operatingSystem)
|
||||
{
|
||||
return operatingSystem.Version.Major == 10;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the current OS is Windows 8(.1)
|
||||
/// </summary>
|
||||
/// <param name="operatingSystem">OperatingSystem from Environment.OSVersion</param>
|
||||
/// <returns>true if we are running on Windows 8(.1)</returns>
|
||||
public static bool IsWindows8(this OperatingSystem operatingSystem)
|
||||
{
|
||||
return operatingSystem.Version.Major == 6 && operatingSystem.Version.Minor >= 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the current OS is Windows 8 or later
|
||||
/// </summary>
|
||||
/// <param name="operatingSystem">OperatingSystem from Environment.OSVersion</param>
|
||||
/// <returns>true if we are running on Windows 8 or later</returns>
|
||||
public static bool IsWindows8OrLater(this OperatingSystem operatingSystem)
|
||||
{
|
||||
return (operatingSystem.Version.Major == 6 && operatingSystem.Version.Minor >= 2) || operatingSystem.Version.Major >= 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the current OS is Windows 7 or later
|
||||
/// </summary>
|
||||
/// <param name="operatingSystem">OperatingSystem from Environment.OSVersion</param>
|
||||
/// <returns>true if we are running on Windows 7 or later</returns>
|
||||
public static bool IsWindows7OrLater(this OperatingSystem operatingSystem)
|
||||
{
|
||||
return (operatingSystem.Version.Major == 6 && operatingSystem.Version.Minor >= 1) || operatingSystem.Version.Major >= 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the current OS is Windows Vista or later
|
||||
/// </summary>
|
||||
/// <param name="operatingSystem">OperatingSystem from Environment.OSVersion</param>
|
||||
/// <returns>true if we are running on Windows Vista or later</returns>
|
||||
public static bool IsWindowsVistaOrLater(this OperatingSystem operatingSystem)
|
||||
{
|
||||
return operatingSystem.Version.Major >= 6;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the current OS is Windows XP or later
|
||||
/// </summary>
|
||||
/// <param name="operatingSystem">OperatingSystem from Environment.OSVersion</param>
|
||||
/// <returns>true if we are running on Windows XP or later</returns>
|
||||
public static bool IsWindowsXpOrLater(this OperatingSystem operatingSystem)
|
||||
{
|
||||
// Windows 2000 is Major 5 minor 0
|
||||
return Environment.OSVersion.Version.Major > 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -768,7 +768,13 @@ namespace GreenshotPlugin.Core {
|
|||
if (previousWindowRectangle.IsEmpty || now - lastWindowRectangleRetrieveTime > CACHE_TIME) {
|
||||
Rectangle windowRect = Rectangle.Empty;
|
||||
if (DWM.isDWMEnabled()) {
|
||||
GetExtendedFrameBounds(out windowRect);
|
||||
if (GetExtendedFrameBounds(out windowRect) && Environment.OSVersion.IsWindows10())
|
||||
{
|
||||
lastWindowRectangleRetrieveTime = now;
|
||||
previousWindowRectangle = windowRect;
|
||||
// DWM does it corectly, just return the window rectangle we just gotten.
|
||||
return windowRect;
|
||||
}
|
||||
}
|
||||
|
||||
if (windowRect.IsEmpty) {
|
||||
|
@ -915,10 +921,12 @@ namespace GreenshotPlugin.Core {
|
|||
Form tempForm = null;
|
||||
bool tempFormShown = false;
|
||||
try {
|
||||
tempForm = new Form();
|
||||
tempForm.ShowInTaskbar = false;
|
||||
tempForm.FormBorderStyle = FormBorderStyle.None;
|
||||
tempForm.TopMost = true;
|
||||
tempForm = new Form
|
||||
{
|
||||
ShowInTaskbar = false,
|
||||
FormBorderStyle = FormBorderStyle.None,
|
||||
TopMost = true
|
||||
};
|
||||
|
||||
// Register the Thumbnail
|
||||
DWM.DwmRegisterThumbnail(tempForm.Handle, Handle, out thumbnailHandle);
|
||||
|
@ -932,8 +940,8 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
|
||||
// Calculate the location of the temp form
|
||||
Point formLocation;
|
||||
Rectangle windowRectangle = WindowRectangle;
|
||||
Point formLocation = formLocation = windowRectangle.Location;
|
||||
Size borderSize = new Size();
|
||||
bool doesCaptureFit = false;
|
||||
if (!Maximised) {
|
||||
|
@ -962,7 +970,7 @@ namespace GreenshotPlugin.Core {
|
|||
doesCaptureFit = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (!Environment.OSVersion.IsWindows8OrLater()) {
|
||||
//GetClientRect(out windowRectangle);
|
||||
GetBorderSize(out borderSize);
|
||||
formLocation = new Point(windowRectangle.X - borderSize.Width, windowRectangle.Y - borderSize.Height);
|
||||
|
@ -1067,7 +1075,7 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
if (capturedBitmap != null) {
|
||||
// Not needed for Windows 8
|
||||
if (!(Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor >= 2)) {
|
||||
if (!Environment.OSVersion.IsWindows8OrLater()) {
|
||||
// Only if the Inivalue is set, not maximized and it's not a tool window.
|
||||
if (conf.WindowCaptureRemoveCorners && !Maximised && (ExtendedWindowStyle & ExtendedWindowStyleFlags.WS_EX_TOOLWINDOW) == 0) {
|
||||
// Remove corners
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue