77using System . Diagnostics ;
88using System . Runtime . InteropServices ;
99using System . Management ;
10+ using System . Windows . Forms ;
1011using mshtml ;
1112using WindowTextExtractor . Extensions ;
1213using WindowTextExtractor . Native ;
@@ -51,7 +52,7 @@ public static IList<string> GetPasswordsFromHtmlPage(IntPtr handle)
5152 return result ;
5253 }
5354
54- public static WindowInformation GetWindowInformation ( IntPtr handle )
55+ public static WindowInformation GetWindowInformation ( IntPtr handle , Point cursorPosition )
5556 {
5657 var text = GetWindowText ( handle ) ;
5758 var wmText = GetWmGettext ( handle ) ;
@@ -73,6 +74,18 @@ public static WindowInformation GetWindowInformation(IntPtr handle)
7374 var dwlDlgproc = User32 . GetClassLong ( handle , Constants . DWL_DLGPROC ) ;
7475 var dwlUser = User32 . GetClassLong ( handle , Constants . DWL_USER ) ;
7576
77+ var cursorDetailes = new Dictionary < string , string > ( ) ;
78+ cursorDetailes . Add ( "Position" , $ "X = { cursorPosition . X } , Y = { cursorPosition . Y } ") ;
79+
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 ( ) ) ;
85+
86+ var color = GetColorUnderCursor ( cursorPosition ) ;
87+ cursorDetailes . Add ( "Color Picker" , ColorTranslator . ToHtml ( color ) ) ;
88+
7689 var windowDetailes = new Dictionary < string , string > ( ) ;
7790 windowDetailes . Add ( "GetWindowText" , text ) ;
7891 windowDetailes . Add ( "WM_GETTEXT" , wmText ) ;
@@ -236,7 +249,7 @@ public static WindowInformation GetWindowInformation(IntPtr handle)
236249 {
237250 }
238251
239- return new WindowInformation ( windowDetailes , processDetailes ) ;
252+ return new WindowInformation ( cursorDetailes , windowDetailes , processDetailes ) ;
240253 }
241254
242255 public static Bitmap CaptureWindow ( IntPtr handle , bool captureCursor = false )
@@ -387,7 +400,6 @@ private static Rect GetFrameBounds(IntPtr handle)
387400 } ;
388401 }
389402
390-
391403 private static Process GetProcessByIdSafely ( int pId )
392404 {
393405 try
@@ -445,6 +457,34 @@ private static int EnumWindows(IntPtr handle, ref IntPtr lParam)
445457 return result ;
446458 }
447459
460+ private static Color GetColorUnderCursor ( Point cursorPosition )
461+ {
462+ using ( var bmp = new Bitmap ( 1 , 1 ) )
463+ using ( var graphics = Graphics . FromImage ( bmp ) )
464+ {
465+ graphics . CopyFromScreen ( cursorPosition , Point . Empty , new Size ( 1 , 1 ) ) ;
466+ var color = bmp . GetPixel ( 0 , 0 ) ;
467+ return color ;
468+ }
469+ }
470+
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+
448488 private class WmiProcessInfo
449489 {
450490 public string CommandLine { get ; set ; }
0 commit comments