Skip to content

Commit 7e2c790

Browse files
committed
Fixed an error in the "Cursor Information" section of "Information" tab
1 parent e18f8c7 commit 7e2c790

File tree

5 files changed

+8
-52
lines changed

5 files changed

+8
-52
lines changed

WindowTextExtractor/Native/Constants.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ static class Constants
2727
public const int DWL_DLGPROC = 4;
2828
public const int DWL_USER = 8;
2929

30-
// MonitorFromWindow
31-
public const uint MONITOR_DEFAULTTONULL = 0;
32-
public const uint MONITOR_DEFAULTTOPRIMARY = 1;
33-
public const uint MONITOR_DEFAULTTONEAREST = 2;
34-
3530
public const int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
3631

3732
public const int EVENT_TYPE = 1;

WindowTextExtractor/Native/Structs/MonitorInfo.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

WindowTextExtractor/Native/User32.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,5 @@ static class User32
108108

109109
[DllImport("user32.dll")]
110110
public static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);
111-
112-
[DllImport("user32")]
113-
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MonitorInfo info);
114-
115-
[DllImport("user32.dll")]
116-
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
117111
}
118112
}

WindowTextExtractor/Utils/WindowUtils.cs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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; }

WindowTextExtractor/WindowTextExtractor.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@
150150
</Compile>
151151
<Compile Include="Native\Structs\CURSORINFO.cs" />
152152
<Compile Include="Native\Structs\ICONINFO.cs" />
153-
<Compile Include="Native\Structs\MonitorInfo.cs" />
154153
<Compile Include="Native\Winmm.cs" />
155154
<Compile Include="Utils\FileUtils.cs" />
156155
<Compile Include="Utils\ImageUtils.cs" />

0 commit comments

Comments
 (0)