add Screenshot
This commit is contained in:
1 parent
08ae754ea3
commit
46b1297aa7
28 files changed
+923
-100
No files matched your search
@@ -6,32 +6,43 @@ namespace HandyControl.Tools
|
||||
{
|
||||
public class ClipboardHook
|
||||
{
|
||||
public static event Action ContentChanged;
|
||||
|
||||
private static HwndSource HWndSource;
|
||||
|
||||
private static IntPtr HookId = IntPtr.Zero;
|
||||
|
||||
public static event Action ContentChanged;
|
||||
private static int Count;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (HookId != IntPtr.Zero)
|
||||
if (HookId == IntPtr.Zero)
|
||||
{
|
||||
Stop();
|
||||
HookId = WindowHelper.CreateHandle();
|
||||
HWndSource = HwndSource.FromHwnd(HookId);
|
||||
if (HWndSource != null)
|
||||
{
|
||||
HWndSource.AddHook(WinProc);
|
||||
InteropMethods.AddClipboardFormatListener(HookId);
|
||||
}
|
||||
}
|
||||
|
||||
HookId = WindowHelper.CreateHandle();
|
||||
HWndSource = HwndSource.FromHwnd(HookId);
|
||||
if (HWndSource != null)
|
||||
if (HookId != IntPtr.Zero)
|
||||
{
|
||||
HWndSource.AddHook(WinProc);
|
||||
InteropMethods.AddClipboardFormatListener(HookId);
|
||||
Count++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
HWndSource.RemoveHook(WinProc);
|
||||
InteropMethods.RemoveClipboardFormatListener(HookId);
|
||||
Count--;
|
||||
if (Count < 1)
|
||||
{
|
||||
HWndSource.RemoveHook(WinProc);
|
||||
InteropMethods.RemoveClipboardFormatListener(HookId);
|
||||
|
||||
HookId = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr WinProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
|
||||
|
||||
@@ -26,29 +26,42 @@ namespace HandyControl.Tools
|
||||
|
||||
private static readonly IntPtr SyskeyUpIntPtr = (IntPtr)InteropValues.WM_SYSKEYUP;
|
||||
|
||||
private static int Count;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (HookId == IntPtr.Zero)
|
||||
{
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
if (HookId != IntPtr.Zero)
|
||||
{
|
||||
Stop();
|
||||
Count++;
|
||||
}
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
public static void Stop() => InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
public static void Stop()
|
||||
{
|
||||
Count--;
|
||||
if (Count < 1)
|
||||
{
|
||||
InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
HookId = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr SetHook(InteropValues.HookProc proc)
|
||||
{
|
||||
using (var curProcess = Process.GetCurrentProcess())
|
||||
using (var curModule = curProcess.MainModule)
|
||||
using var curProcess = Process.GetCurrentProcess();
|
||||
using var curModule = curProcess.MainModule;
|
||||
|
||||
if (curModule != null)
|
||||
{
|
||||
if (curModule != null)
|
||||
{
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_KEYBOARD_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_KEYBOARD_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
|
||||
@@ -14,29 +14,42 @@ namespace HandyControl.Tools
|
||||
|
||||
private static readonly InteropValues.HookProc Proc = HookCallback;
|
||||
|
||||
private static int Count;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (HookId == IntPtr.Zero)
|
||||
{
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
if (HookId != IntPtr.Zero)
|
||||
{
|
||||
Stop();
|
||||
Count++;
|
||||
}
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
public static void Stop() => InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
public static void Stop()
|
||||
{
|
||||
Count--;
|
||||
if (Count < 1)
|
||||
{
|
||||
InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
HookId = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr SetHook(InteropValues.HookProc proc)
|
||||
{
|
||||
using (var curProcess = Process.GetCurrentProcess())
|
||||
using (var curModule = curProcess.MainModule)
|
||||
using var curProcess = Process.GetCurrentProcess();
|
||||
using var curModule = curProcess.MainModule;
|
||||
|
||||
if (curModule != null)
|
||||
{
|
||||
if (curModule != null)
|
||||
{
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_MOUSE_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_MOUSE_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
@@ -45,7 +58,7 @@ namespace HandyControl.Tools
|
||||
var hookStruct = (InteropValues.MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(InteropValues.MOUSEHOOKSTRUCT));
|
||||
StatusChanged?.Invoke(null, new MouseHookEventArgs
|
||||
{
|
||||
Message = (MouseHookMessageType)wParam,
|
||||
MessageType = (MouseHookMessageType)wParam,
|
||||
Point = new InteropValues.POINT(hookStruct.pt.X, hookStruct.pt.Y)
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user