Skip to content

Commit

Permalink
Fixed an error in the "Cursor Information" section of "Information" tab
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPro committed Apr 3, 2023
1 parent e18f8c7 commit 7e2c790
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 52 deletions.
5 changes: 0 additions & 5 deletions WindowTextExtractor/Native/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ static class Constants
public const int DWL_DLGPROC = 4;
public const int DWL_USER = 8;

// MonitorFromWindow
public const uint MONITOR_DEFAULTTONULL = 0;
public const uint MONITOR_DEFAULTTOPRIMARY = 1;
public const uint MONITOR_DEFAULTTONEAREST = 2;

public const int DWMWA_EXTENDED_FRAME_BOUNDS = 9;

public const int EVENT_TYPE = 1;
Expand Down
18 changes: 0 additions & 18 deletions WindowTextExtractor/Native/Structs/MonitorInfo.cs

This file was deleted.

6 changes: 0 additions & 6 deletions WindowTextExtractor/Native/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,5 @@ static class User32

[DllImport("user32.dll")]
public static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);

[DllImport("user32")]
public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MonitorInfo info);

[DllImport("user32.dll")]
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
}
}
30 changes: 8 additions & 22 deletions WindowTextExtractor/Utils/WindowUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ public static WindowInformation GetWindowInformation(IntPtr handle, Point cursor
var cursorDetailes = new Dictionary<string, string>();
cursorDetailes.Add("Position", $"X = {cursorPosition.X}, Y = {cursorPosition.Y}");

var monitorInfo = GetMonitorInfo(handle);
cursorDetailes.Add("Monitor Position", $"X = {cursorPosition.X - monitorInfo.rcMonitor.Left}, Y = {cursorPosition.Y - monitorInfo.rcMonitor.Top}");

var monitorNumber = GetMonitorNumber(cursorPosition);
cursorDetailes.Add("Monitor", monitorNumber.ToString());
var screenFromPoint = Screen.FromPoint(cursorPosition);
var screens = Screen.AllScreens.Select((x, i) => new { Index = i + 1, Item = x }).ToList();
var screen = screens.FirstOrDefault(x => x.Item.Equals(screenFromPoint));
if (screen != null)
{
cursorDetailes.Add("Monitor Position", $"X = {cursorPosition.X - screen.Item.Bounds.Left}, Y = {cursorPosition.Y - screen.Item.Bounds.Top}");
cursorDetailes.Add("Monitor", screen.Index.ToString());
}

var color = GetColorUnderCursor(cursorPosition);
cursorDetailes.Add("Color Picker", ColorTranslator.ToHtml(color));
Expand Down Expand Up @@ -468,23 +471,6 @@ private static Color GetColorUnderCursor(Point cursorPosition)
}
}

private static int GetMonitorNumber(Point cursorPosition)
{
var screenFromPoint = Screen.FromPoint(cursorPosition);
var screens = Screen.AllScreens.Select((x, i) => new { Index = i + 1, Item = x }).ToList();
var screen = screens.FirstOrDefault(x => x.Item.Equals(screenFromPoint));
return screen?.Index ?? 0;
}

private static MonitorInfo GetMonitorInfo(IntPtr handle)
{
var monitorHandle = User32.MonitorFromWindow(handle, Constants.MONITOR_DEFAULTTONEAREST);
var monitorInfo = new MonitorInfo();
monitorInfo.Init();
User32.GetMonitorInfo(monitorHandle, ref monitorInfo);
return monitorInfo;
}

private class WmiProcessInfo
{
public string CommandLine { get; set; }
Expand Down
1 change: 0 additions & 1 deletion WindowTextExtractor/WindowTextExtractor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
</Compile>
<Compile Include="Native\Structs\CURSORINFO.cs" />
<Compile Include="Native\Structs\ICONINFO.cs" />
<Compile Include="Native\Structs\MonitorInfo.cs" />
<Compile Include="Native\Winmm.cs" />
<Compile Include="Utils\FileUtils.cs" />
<Compile Include="Utils\ImageUtils.cs" />
Expand Down

0 comments on commit 7e2c790

Please sign in to comment.