diff --git a/src/Color/Win32.cs b/src/Color/Win32.cs index 6f97f4b..93da990 100644 --- a/src/Color/Win32.cs +++ b/src/Color/Win32.cs @@ -11,9 +11,15 @@ public static class Win32 private const string _USER32_DLL = "user32.dll"; + public const int SW_HIDE = 0; + + [DllImport(_USER32_DLL)] public static extern nint CallNextHookEx(nint hhk, int nCode, nint wParam, nint lParam); + [DllImport(_KERNEL32_DLL)] + public static extern nint GetConsoleWindow(); + [DllImport(_USER32_DLL)] public static extern nint GetDesktopWindow(); @@ -34,6 +40,9 @@ public static class Win32 [DllImport(_USER32_DLL)] public static extern nint SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, nint hMod, uint dwThreadId); + [DllImport(_USER32_DLL)] + public static extern bool ShowWindow(nint hWnd, int nCmdShow); + [DllImport(_USER32_DLL)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnhookWindowsHookEx(nint hhk); diff --git a/src/Color/WinInfo.cs b/src/Color/WinInfo.cs index 5a14ae8..8104c8a 100644 --- a/src/Color/WinInfo.cs +++ b/src/Color/WinInfo.cs @@ -4,8 +4,8 @@ namespace Dot.Color; public class WinInfo : Form { - private const int _WINDOW_SIZE = 480; - private const int _ZOOM_RATE = 16; + private const int _WINDOW_SIZE = 480; //窗口大小 + private const int _ZOOM_RATE = 16; //缩放倍率 private bool _disposed; private readonly Graphics _graphics; private readonly PictureBox _pbox; @@ -24,7 +24,7 @@ public class WinInfo : Form _pbox.Size = Size; _pbox.Image = new Bitmap(_WINDOW_SIZE, _WINDOW_SIZE); _graphics = Graphics.FromImage(_pbox.Image); - _graphics.InterpolationMode = InterpolationMode.NearestNeighbor; + _graphics.InterpolationMode = InterpolationMode.NearestNeighbor; //指定最临近插值法,禁止平滑缩放(模糊) _graphics.CompositingQuality = CompositingQuality.HighQuality; _graphics.SmoothingMode = SmoothingMode.None; Controls.Add(_pbox); @@ -52,19 +52,25 @@ public class WinInfo : Form public void UpdateImage(Bitmap img, int x, int y) { + // 计算复制小图的区域 var copySize = new Size(_WINDOW_SIZE / _ZOOM_RATE, _WINDOW_SIZE / _ZOOM_RATE); _graphics.DrawImage(img, new Rectangle(0, 0, _WINDOW_SIZE, _WINDOW_SIZE) // - , x - copySize.Width / 2 // - , y - copySize.Height / 2 // + , x - copySize.Width / 2 // 左移x,使光标位置居中 + , y - copySize.Height / 2 // 上移y,使光标位置居中 , copySize.Width, copySize.Height, GraphicsUnit.Pixel); - using var pen = new Pen(System.Drawing.Color.Aqua); + using var pen = new Pen(System.Drawing.Color.Aqua); //绘制准星 _graphics.DrawRectangle(pen, _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 // , _WINDOW_SIZE / 2 - _ZOOM_RATE / 2 // , _ZOOM_RATE, _ZOOM_RATE); + + // 取鼠标位置颜色 var posColor = img.GetPixel(x, y); + // 绘制底部文字信息 _graphics.FillRectangle(Brushes.Black, 0, _WINDOW_SIZE - 30, _WINDOW_SIZE, 30); _graphics.DrawString($"{Str.ClickCopyColor} X: {x} Y: {y} RGB({posColor.R},{posColor.G},{posColor.B})" - , new Font(FontFamily.GenericSerif, 10), Brushes.White, 0, _WINDOW_SIZE - 20); + , new Font(FontFamily.GenericSerif, 10) // + , Brushes.White, 0, _WINDOW_SIZE - 20); + // 触发重绘 _pbox.Refresh(); } } \ No newline at end of file diff --git a/src/Color/WinMain.cs b/src/Color/WinMain.cs index 290a2ce..9bd0e9d 100644 --- a/src/Color/WinMain.cs +++ b/src/Color/WinMain.cs @@ -6,15 +6,18 @@ public class WinMain : Form { private readonly Bitmap _bmp; private bool _disposed; - private readonly WinInfo _winInfo = new(); + private readonly WinInfo _winInfo = new(); //小图窗口 public WinMain() { + // 隐藏控制台窗口,避免捕获到截屏 + Win32.ShowWindow(Win32.GetConsoleWindow(), Win32.SW_HIDE); + FormBorderStyle = FormBorderStyle.None; Size = Screen.PrimaryScreen!.Bounds.Size; StartPosition = FormStartPosition.Manual; Location = new Point(0, 0); - Opacity = 0.01d; + Opacity = 0.01d; //主窗体加载截图过程设置为透明避免闪烁 _bmp = new Bitmap(Size.Width, Size.Height); using var g = Graphics.FromImage(_bmp); g.CopyFromScreen(0, 0, 0, 0, Size); @@ -57,6 +60,7 @@ public class WinMain : Form protected override void OnMouseMove(MouseEventArgs e) { + // 移动鼠标时更新小图窗口 _winInfo.UpdateImage(_bmp, e.X, e.Y); } diff --git a/src/Lang/Str.en-US.resx b/src/Lang/Str.en-US.resx index 219ee48..39e65fc 100644 --- a/src/Lang/Str.en-US.resx +++ b/src/Lang/Str.en-US.resx @@ -1,124 +1,125 @@ - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + + The input text is empty - + Find files... - + The specified path "{0}" does not exist - + Find files...OK - + Read: {0}/{1}, processed: {2}, skipped: {3} - + {0}(copied to clipboard) - + File wildcards - + Directory path to be processed - + Convert newline characters to LF - + GUID tool - + Use uppercase output - + Random password generator - + Password length - + BitSet 1:[0-9],2:[a-z],4:[A-Z],8:[ascii.0x21-0x2F] - + Remove line breaks and spaces at the end of the file - + Remove the uf8 bom of the file - + Text to be processed (clipboard value is taken by default) - + Press any key to continue... - + Read-only mode (only for testing, no actual modification) - + No documents to be processed - + Timeout for connecting to the NTP server (milliseconds) - + Synchronize local time - + Success {0}/{1}, the average value of the clock offset of the machine:{2}ms - + {0}/{1} NTP servers - + {0} In communication... - + {0}, local clock offset: {1} ms - + Local time has been synchronized - + Server - + Status - + Local clock offset - + Time synchronization tool - + Text encoding tool - + Screen coordinate color selection tool - + Click the left mouse button to copy the colors and coordinates to the clipboard \ No newline at end of file diff --git a/src/dot.csproj b/src/dot.csproj index aaa3ed5..607d74f 100644 --- a/src/dot.csproj +++ b/src/dot.csproj @@ -24,10 +24,10 @@ - - - - + + + +