diff --git a/dot.sln.DotSettings b/dot.sln.DotSettings index 24a4bdd..e0c09a2 100644 --- a/dot.sln.DotSettings +++ b/dot.sln.DotSettings @@ -1,8 +1,4 @@ - True - True - True - True False 1 1 @@ -16,7 +12,6 @@ <Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <?xml version="1.0" encoding="utf-16"?> <Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> <TypePattern> @@ -57,5 +52,4 @@ </Entry> </TypePattern> </Patterns> - \ No newline at end of file diff --git a/git-clean.cmd b/git-clean.cmd index 5f7b39a..07b006c 100644 --- a/git-clean.cmd +++ b/git-clean.cmd @@ -1 +1,2 @@ -git reset --hard | git clean -d -fx . \ No newline at end of file +git reset --hard +git clean -d -fx . \ No newline at end of file diff --git a/src/AssemblyInfo.cs b/src/AssemblyInfo.cs index 21578b5..7b70604 100644 --- a/src/AssemblyInfo.cs +++ b/src/AssemblyInfo.cs @@ -24,5 +24,5 @@ internal static class AssemblyInfo public const string ASSEMBLY_PRODUCT = "dot"; public const string ASSEMBLY_TITLE = "功能全面的实用工具 - 程序员的瑞士军刀"; public const string ASSEMBLY_VERSION = _VERSION; - private const string _VERSION = "1.1.6"; + private const string _VERSION = "1.1.7"; } \ No newline at end of file diff --git a/src/Color/MouseHook.cs b/src/Color/MouseHook.cs deleted file mode 100644 index 0d410f5..0000000 --- a/src/Color/MouseHook.cs +++ /dev/null @@ -1,82 +0,0 @@ -// ReSharper disable ClassNeverInstantiated.Global - -#if NET7_0_WINDOWS -using System.Diagnostics; -using System.Runtime.InteropServices; - -namespace Dot.Color; - -internal sealed class MouseHook : IDisposable -{ - private const int _WH_MOUSE_LL = 14; - private const int _WM_LBUTTONDOWN = 0x0201; - private const int _WM_MOUSEMOVE = 0x0200; - private readonly nint _hookId; - private bool _disposed; - - public MouseHook() - { - _hookId = SetHook(HookCallback); - } - - ~MouseHook() - { - Dispose(false); - } - - public event MouseEventHandler MouseEvent; - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private static nint SetHook(Func proc) - { - using var curProcess = Process.GetCurrentProcess(); - using var curModule = curProcess.MainModule!; - return Win32.SetWindowsHookEx(_WH_MOUSE_LL, proc, Win32.GetModuleHandle(curModule.ModuleName), 0); - } - - private void Dispose(bool disposing) - { - if (_disposed) { - return; - } - - if (disposing) { - // - } - - if (_hookId != default) { - Win32.UnhookWindowsHookEx(_hookId); - } - - _disposed = true; - } - - private nint HookCallback(int nCode, nint wParam, nint lParam) - { - if (nCode < 0 || (wParam != _WM_MOUSEMOVE && wParam != _WM_LBUTTONDOWN)) { - return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam); - } - - var hookStruct = (Msllhookstruct)Marshal.PtrToStructure(lParam, typeof(Msllhookstruct))!; - MouseEvent?.Invoke(null, new MouseEventArgs( // - wParam == _WM_MOUSEMOVE ? MouseButtons.None : MouseButtons.Left // - , 0 // - , hookStruct.X // - , hookStruct.Y // - , 0)); - return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam); - } - - [StructLayout(LayoutKind.Explicit)] - private readonly struct Msllhookstruct - { - [FieldOffset(0)] public readonly int X; - [FieldOffset(4)] public readonly int Y; - } -} -#endif \ No newline at end of file diff --git a/src/Color/WinMain.cs b/src/Color/WinMain.cs index 78dfe70..82c5d76 100644 --- a/src/Color/WinMain.cs +++ b/src/Color/WinMain.cs @@ -1,6 +1,7 @@ #if NET7_0_WINDOWS using System.Runtime.InteropServices; using System.Runtime.Versioning; +using Dot.Native; using TextCopy; namespace Dot.Color; diff --git a/src/Native/MouseHook.cs b/src/Native/MouseHook.cs new file mode 100644 index 0000000..15a8d57 --- /dev/null +++ b/src/Native/MouseHook.cs @@ -0,0 +1,73 @@ +// ReSharper disable ClassNeverInstantiated.Global + +#if NET7_0_WINDOWS +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Dot.Native; + +internal sealed class MouseHook : IDisposable +{ + private readonly nint _hookId; + private bool _disposed; + + public MouseHook() + { + _hookId = SetHook(HookCallback); + } + + ~MouseHook() + { + Dispose(false); + } + + public event MouseEventHandler MouseMoveEvent; + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private static nint SetHook(Win32.HookProc lpfn) + { + using var process = Process.GetCurrentProcess(); + using var module = process.MainModule; + return Win32.SetWindowsHookExA(Win32.WH_MOUSE_LL, lpfn, module!.BaseAddress, 0); + } + + private void Dispose(bool disposing) + { + if (_disposed) { + return; + } + + if (disposing) { + // + } + + if (_hookId != default) { + Win32.UnhookWindowsHookExA(_hookId); + } + + _disposed = true; + } + + private nint HookCallback(int nCode, nint wParam, nint lParam) + { + if (wParam == Win32.WM_MOUSEMOVE) { + var hookStruct = (Msllhookstruct)Marshal.PtrToStructure(lParam, typeof(Msllhookstruct))!; + MouseMoveEvent?.Invoke(null, new MouseEventArgs(MouseButtons.None, 0, hookStruct.X, hookStruct.Y, 0)); + } + + return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam); + } + + [StructLayout(LayoutKind.Explicit)] + private readonly struct Msllhookstruct + { + [FieldOffset(0)] public readonly int X; + [FieldOffset(4)] public readonly int Y; + } +} +#endif \ No newline at end of file diff --git a/src/Win32.cs b/src/Native/Win32.cs similarity index 65% rename from src/Win32.cs rename to src/Native/Win32.cs index c9b6e6a..3f91e6c 100644 --- a/src/Win32.cs +++ b/src/Native/Win32.cs @@ -3,17 +3,23 @@ using System.Runtime.InteropServices; -namespace Dot; +namespace Dot.Native; internal static partial class Win32 { - public const int SW_HIDE = 0; - public const int WM_CHANGECBCHAIN = 0x030D; - public const int WM_DRAWCLIPBOARD = 0x308; + public const int CS_DROP_SHADOW = 0x20000; + public const int GCL_STYLE = -26; + public const int SW_HIDE = 0; + public const int WH_MOUSE_LL = 14; + public const int WM_CHANGECBCHAIN = 0x030D; + public const int WM_DRAWCLIPBOARD = 0x308; + public const int WM_LBUTTONDOWN = 0x0201; + public const int WM_MOUSEMOVE = 0x0200; + private const string _GDI32_DLL = "gdi32.dll"; + private const string _KERNEL32_DLL = "kernel32.dll"; + private const string _USER32_DLL = "user32.dll"; - private const string _GDI32_DLL = "gdi32.dll"; - private const string _KERNEL32_DLL = "kernel32.dll"; - private const string _USER32_DLL = "user32.dll"; + public delegate nint HookProc(int nCode, nint wParam, nint lParam); [LibraryImport(_USER32_DLL)] internal static partial nint CallNextHookEx(nint hhk, int nCode, nint wParam, nint lParam); @@ -22,6 +28,9 @@ internal static partial class Win32 [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool ChangeClipboardChain(nint hWndRemove, nint hWndNewNext); + [LibraryImport(_USER32_DLL)] + internal static partial int GetClassLongA(nint hWnd, int nIndex); + [LibraryImport(_KERNEL32_DLL)] internal static partial nint GetConsoleWindow(); @@ -29,7 +38,7 @@ internal static partial class Win32 internal static partial nint GetDesktopWindow(); [LibraryImport(_KERNEL32_DLL, StringMarshalling = StringMarshalling.Utf16)] - internal static partial nint GetModuleHandle(string lpModuleName); + internal static partial nint GetModuleHandleA(string lpModuleName); [LibraryImport(_GDI32_DLL)] internal static partial uint GetPixel(nint dc, int x, int y); @@ -43,6 +52,9 @@ internal static partial class Win32 [LibraryImport(_USER32_DLL)] internal static partial int SendMessageA(nint hwnd, uint wMsg, nint wParam, nint lParam); + [LibraryImport(_USER32_DLL)] + internal static partial int SetClassLongA(nint hWnd, int nIndex, int dwNewLong); + [LibraryImport(_USER32_DLL)] internal static partial int SetClipboardViewer(nint hWnd); @@ -50,8 +62,7 @@ internal static partial class Win32 internal static partial void SetLocalTime(Systemtime st); [LibraryImport(_USER32_DLL)] - internal static partial nint SetWindowsHookEx(int idHook, Func lpfn, nint hMod - , uint dwThreadId); + internal static partial nint SetWindowsHookExA(int idHook, HookProc lpfn, nint hMod, uint dwThreadId); [LibraryImport(_USER32_DLL)] [return: MarshalAs(UnmanagedType.Bool)] @@ -59,7 +70,7 @@ internal static partial class Win32 [LibraryImport(_USER32_DLL)] [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool UnhookWindowsHookEx(nint hhk); + internal static partial bool UnhookWindowsHookExA(nint hhk); [StructLayout(LayoutKind.Explicit)] internal ref struct Systemtime diff --git a/src/Text/Main.Output.cs b/src/Text/Main.Output.cs deleted file mode 100644 index 6c45ae4..0000000 --- a/src/Text/Main.Output.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Dot.Text; - -internal sealed partial class Main -{ - private ref struct Output - { - public ReadOnlySpan Base64; - public ReadOnlySpan Base64DeCode; - public ReadOnlySpan Base64DeCodeHex; - public ReadOnlySpan EncodingName; - public ReadOnlySpan Hex; - public ReadOnlySpan HtmlDecode; - public ReadOnlySpan HtmlEncode; - public ReadOnlySpan Md5; - public ReadOnlySpan OriginText; - public ReadOnlySpan Sha1; - public ReadOnlySpan Sha256; - public ReadOnlySpan Sha512; - public ReadOnlySpan UrlDecode; - public ReadOnlySpan UrlEncode; - } -} \ No newline at end of file diff --git a/src/Text/Main.cs b/src/Text/Main.cs index c36648b..e3eaca2 100644 --- a/src/Text/Main.cs +++ b/src/Text/Main.cs @@ -12,7 +12,7 @@ namespace Dot.Text; [Description(nameof(Str.TextTool))] [Localization(typeof(Str))] -internal sealed partial class Main : ToolBase