@@ -42,21 +42,24 @@ public static void SetWindowPosition(Window passedWindow)
42
42
if ( storedPosition != null
43
43
&& storedPosition . Count == 4 )
44
44
{
45
- bool couldParseAll = false ;
46
- couldParseAll = double . TryParse ( storedPosition [ 0 ] , out double parsedX ) ;
47
- couldParseAll = double . TryParse ( storedPosition [ 1 ] , out double parsedY ) ;
48
- couldParseAll = double . TryParse ( storedPosition [ 2 ] , out double parsedWid ) ;
49
- couldParseAll = double . TryParse ( storedPosition [ 3 ] , out double parsedHei ) ;
45
+ bool couldParseX = double . TryParse ( storedPosition [ 0 ] , out double parsedX ) ;
46
+ bool couldParseY = double . TryParse ( storedPosition [ 1 ] , out double parsedY ) ;
47
+ bool couldParseW = double . TryParse ( storedPosition [ 2 ] , out double parsedWid ) ;
48
+ bool couldParseH = double . TryParse ( storedPosition [ 3 ] , out double parsedHei ) ;
49
+
50
+ bool couldParseAll = couldParseX && couldParseY && couldParseW && couldParseH ;
51
+
50
52
Rect storedSize = new ( ( int ) parsedX , ( int ) parsedY , ( int ) parsedWid , ( int ) parsedHei ) ;
51
53
DisplayInfo [ ] allScreens = DisplayInfo . AllDisplayInfos ;
52
- WindowCollection allWindows = Application . Current . Windows ;
53
54
54
55
if ( parsedHei < 10 || parsedWid < 10 )
55
56
return ;
56
57
57
58
foreach ( DisplayInfo screen in allScreens )
58
59
{
59
60
Rect screenRect = screen . Bounds ;
61
+ DpiScale dpi = System . Windows . Media . VisualTreeHelper . GetDpi ( passedWindow ) ;
62
+ screenRect = screenRect . GetScaledDownByDpi ( dpi ) ;
60
63
if ( screenRect . IntersectsWith ( storedSize ) )
61
64
isStoredRectWithinScreen = true ;
62
65
}
@@ -251,7 +254,7 @@ private static void TryInjectModifierKeyUp(ref List<INPUT> inputs, VirtualKeySho
251
254
{
252
255
WindowCollection allWindows = Application . Current . Windows ;
253
256
254
- foreach ( var window in allWindows )
257
+ foreach ( Window window in allWindows )
255
258
{
256
259
if ( window is T matchWindow )
257
260
{
@@ -262,7 +265,15 @@ private static void TryInjectModifierKeyUp(ref List<INPUT> inputs, VirtualKeySho
262
265
263
266
// No Window Found, open a new one
264
267
T newWindow = new ( ) ;
265
- newWindow . Show ( ) ;
268
+
269
+ try
270
+ {
271
+ newWindow . Show ( ) ;
272
+ }
273
+ catch ( Exception ex )
274
+ {
275
+ MessageBox . Show ( "An error occurred while trying to open a new window. Please try again." , ex . Message ) ;
276
+ }
266
277
return newWindow ;
267
278
}
268
279
0 commit comments