|
|
@ -1,14 +1,12 @@ |
|
|
|
using System; |
|
|
|
using Dapplo.Windows.User32; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Windows; |
|
|
|
using System.Windows.Controls; |
|
|
|
using System.Windows.Input; |
|
|
|
using Text_Grab.Properties; |
|
|
|
using Text_Grab.Views; |
|
|
|
// using Screen = System.Windows.Forms.Screen;
|
|
|
|
using WpfScreenHelper; |
|
|
|
using static OSInterop; |
|
|
|
|
|
|
|
namespace Text_Grab.Utilities; |
|
|
@ -47,15 +45,18 @@ public static class WindowUtilities |
|
|
|
couldParseAll = double.TryParse(storedPosition[2], out double parsedWid); |
|
|
|
couldParseAll = double.TryParse(storedPosition[3], out double parsedHei); |
|
|
|
Rect storedSize = new((int)parsedX, (int)parsedY, (int)parsedWid, (int)parsedHei); |
|
|
|
IEnumerable<Screen> allScreens = Screen.AllScreens; |
|
|
|
DisplayInfo[] allScreens = DisplayInfo.AllDisplayInfos; |
|
|
|
WindowCollection allWindows = Application.Current.Windows; |
|
|
|
|
|
|
|
if (parsedHei < 10 || parsedWid < 10) |
|
|
|
return; |
|
|
|
|
|
|
|
foreach (Screen screen in allScreens) |
|
|
|
if (screen.WpfBounds.IntersectsWith(storedSize)) |
|
|
|
foreach (DisplayInfo screen in allScreens) |
|
|
|
{ |
|
|
|
Rect screenRect = screen.Bounds; |
|
|
|
if (screenRect.IntersectsWith(storedSize)) |
|
|
|
isStoredRectWithinScreen = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (isStoredRectWithinScreen && couldParseAll) |
|
|
|
{ |
|
|
@ -71,7 +72,7 @@ public static class WindowUtilities |
|
|
|
|
|
|
|
public static void LaunchFullScreenGrab(TextBox? destinationTextBox = null) |
|
|
|
{ |
|
|
|
IEnumerable<Screen> allScreens = Screen.AllScreens; |
|
|
|
DisplayInfo[] allScreens = DisplayInfo.AllDisplayInfos; |
|
|
|
WindowCollection allWindows = Application.Current.Windows; |
|
|
|
|
|
|
|
List<FullscreenGrab> allFullscreenGrab = new(); |
|
|
@ -93,7 +94,7 @@ public static class WindowUtilities |
|
|
|
|
|
|
|
double sideLength = 40; |
|
|
|
|
|
|
|
foreach (Screen screen in allScreens) |
|
|
|
foreach (DisplayInfo screen in allScreens) |
|
|
|
{ |
|
|
|
FullscreenGrab fullScreenGrab = allFullscreenGrab[count]; |
|
|
|
fullScreenGrab.WindowStartupLocation = WindowStartupLocation.Manual; |
|
|
@ -102,7 +103,8 @@ public static class WindowUtilities |
|
|
|
fullScreenGrab.DestinationTextBox = destinationTextBox; |
|
|
|
fullScreenGrab.WindowState = WindowState.Normal; |
|
|
|
|
|
|
|
Point screenCenterPoint = screen.GetCenterPoint(); |
|
|
|
Rect screenRect = screen.Bounds; |
|
|
|
Point screenCenterPoint = screenRect.CenterPoint(); |
|
|
|
|
|
|
|
fullScreenGrab.Left = screenCenterPoint.X - (sideLength / 2); |
|
|
|
fullScreenGrab.Top = screenCenterPoint.Y - (sideLength / 2); |
|
|
@ -114,10 +116,11 @@ public static class WindowUtilities |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static Point GetCenterPoint(this Screen screen) |
|
|
|
public static Point GetCenterPoint(this DisplayInfo screen) |
|
|
|
{ |
|
|
|
double x = screen.WpfBounds.Left + (screen.WpfBounds.Width / 2); |
|
|
|
double y = screen.WpfBounds.Top + (screen.WpfBounds.Height / 2); |
|
|
|
Rect screenRect = screen.Bounds; |
|
|
|
double x = screenRect.Left + (screenRect.Width / 2); |
|
|
|
double y = screenRect.Top + (screenRect.Height / 2); |
|
|
|
return new(x, y); |
|
|
|
} |
|
|
|
|
|
|
|