add Screenshot

This commit is contained in:
NaBian committed 2020-03-06 14:36:12 +08:00
1 parent 08ae754ea3
commit 46b1297aa7
28 files changed
+923 -100

No files matched your search

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows;
@@ -18,7 +17,6 @@ namespace HandyControl.Tools
static GlobalShortcut()
{
KeyboardHook.KeyDown += KeyboardHook_KeyDown;
}
@@ -51,21 +49,6 @@ namespace HandyControl.Tools
key == Key.RightCtrl || key == Key.RightAlt || key == Key.RightShift || key == Key.RWin;
}
[Obsolete("pls use Host attach property instead of Init method")]
public static void Init(DependencyObject host)
{
CommandDic.Clear();
if (host == null) return;
KeyBindingCollection = GetKeyBindings(host);
if (KeyBindingCollection == null || KeyBindingCollection.Count == 0) return;
AddKeyBindings(KeyBindingCollection);
KeyboardHook.Start();
}
private static void AddKeyBindings(IEnumerable<KeyBinding> keyBindings)
{
foreach (var item in keyBindings)
@@ -6,7 +6,6 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Windows;
using System.Windows.Interop;
using HandyControl.Tools.Extension;
using HandyControl.Tools.Interop;
namespace HandyControl.Tools
@@ -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)
});
@@ -239,11 +239,6 @@ namespace HandyControl.Tools.Interop
IntPtr hInstance,
IntPtr lpParam);
[SecurityCritical]
[SuppressUnmanagedCodeSecurity]
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern short RegisterClass(InteropValues.WNDCLASS wc);
[SecurityCritical]
[SuppressUnmanagedCodeSecurity]
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
@@ -438,5 +433,18 @@ namespace HandyControl.Tools.Interop
internal static extern bool AlphaBlend(IntPtr hdcDest, int xoriginDest, int yoriginDest, int wDest, int hDest, IntPtr hdcSrc, int xoriginSrc, int yoriginSrc, int wSrc, int hSrc, InteropValues.BLENDFUNCTION pfn);
internal static int GET_SC_WPARAM(IntPtr wParam) => (int)wParam & 65520;
[DllImport(InteropValues.ExternDll.User32)]
internal static extern IntPtr ChildWindowFromPointEx(IntPtr hwndParent, InteropValues.POINT pt, int uFlags);
[DllImport(InteropValues.ExternDll.Gdi32)]
internal static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int width, int height);
[DllImport(InteropValues.ExternDll.Gdi32)]
internal static extern bool BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
[DllImport(InteropValues.ExternDll.User32)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool EnableWindow(IntPtr hWnd, bool enable);
}
}
@@ -80,7 +80,8 @@ namespace HandyControl.Tools.Interop
SC_MOVE = 0xF010,
SC_MINIMIZE = 0xF020,
SC_MAXIMIZE = 0xF030,
SC_RESTORE = 0xF120;
SC_RESTORE = 0xF120,
SRCCOPY = 0x00CC0020;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class NOTIFYICONDATA
@@ -212,6 +213,14 @@ namespace HandyControl.Tools.Interop
public int Right;
public int Bottom;
public RECT(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public RECT(Rect rect)
{
Left = (int)rect.Left;