@@ -77,11 +77,14 @@ public static WindowInformation GetWindowInformation(IntPtr handle, Point cursor
7777 var cursorDetailes = new Dictionary < string , string > ( ) ;
7878 cursorDetailes . Add ( "Position" , $ "X = { cursorPosition . X } , Y = { cursorPosition . Y } ") ;
7979
80- var monitorInfo = GetMonitorInfo ( handle ) ;
81- cursorDetailes . Add ( "Monitor Position" , $ "X = { cursorPosition . X - monitorInfo . rcMonitor . Left } , Y = { cursorPosition . Y - monitorInfo . rcMonitor . Top } ") ;
82-
83- var monitorNumber = GetMonitorNumber ( cursorPosition ) ;
84- cursorDetailes . Add ( "Monitor" , monitorNumber . ToString ( ) ) ;
80+ var screenFromPoint = Screen . FromPoint ( cursorPosition ) ;
81+ var screens = Screen . AllScreens . Select ( ( x , i ) => new { Index = i + 1 , Item = x } ) . ToList ( ) ;
82+ var screen = screens . FirstOrDefault ( x => x . Item . Equals ( screenFromPoint ) ) ;
83+ if ( screen != null )
84+ {
85+ cursorDetailes . Add ( "Monitor Position" , $ "X = { cursorPosition . X - screen . Item . Bounds . Left } , Y = { cursorPosition . Y - screen . Item . Bounds . Top } ") ;
86+ cursorDetailes . Add ( "Monitor" , screen . Index . ToString ( ) ) ;
87+ }
8588
8689 var color = GetColorUnderCursor ( cursorPosition ) ;
8790 cursorDetailes . Add ( "Color Picker" , ColorTranslator . ToHtml ( color ) ) ;
@@ -468,23 +471,6 @@ private static Color GetColorUnderCursor(Point cursorPosition)
468471 }
469472 }
470473
471- private static int GetMonitorNumber ( Point cursorPosition )
472- {
473- var screenFromPoint = Screen . FromPoint ( cursorPosition ) ;
474- var screens = Screen . AllScreens . Select ( ( x , i ) => new { Index = i + 1 , Item = x } ) . ToList ( ) ;
475- var screen = screens . FirstOrDefault ( x => x . Item . Equals ( screenFromPoint ) ) ;
476- return screen ? . Index ?? 0 ;
477- }
478-
479- private static MonitorInfo GetMonitorInfo ( IntPtr handle )
480- {
481- var monitorHandle = User32 . MonitorFromWindow ( handle , Constants . MONITOR_DEFAULTTONEAREST ) ;
482- var monitorInfo = new MonitorInfo ( ) ;
483- monitorInfo . Init ( ) ;
484- User32 . GetMonitorInfo ( monitorHandle , ref monitorInfo ) ;
485- return monitorInfo ;
486- }
487-
488474 private class WmiProcessInfo
489475 {
490476 public string CommandLine { get ; set ; }
0 commit comments