-
Notifications
You must be signed in to change notification settings - Fork 0
/
WindowPainter.xaml.cs
84 lines (74 loc) · 2.45 KB
/
WindowPainter.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace BiuBiuClick
{
/// <summary>
/// WindowPainter.xaml 的交互逻辑
/// </summary>
public partial class WindowPainter : Window
{
public delegate void StopCapture();
public StopCapture stopCapture;
private MouseHook mouseHook;
public MouseHook.MouseMoveHandler MouseMoveEventHandler;
public MouseHook.MouseDownHandler MouseDownEventHandler;
public MouseHook.MouseUpHandler MouseUpEventHandler;
public MouseHook.MouseDoubleClickHandler MouseDoubleClickHandler;
public WindowPainter()
{
InitializeComponent();
mouseHook = new MouseHook();
}
public void DrawWindowBorder(WindowInfo windowInfo)
{
setMouseHook();
Rectangle rect = new Rectangle()
{
Margin = new Thickness(windowInfo.Bounds.Left, windowInfo.Bounds.Top, 0, 0),
Width = windowInfo.Bounds.Width,
Height = windowInfo.Bounds.Height,
Fill = Brushes.Transparent,
Stroke = Brushes.Red,
StrokeThickness = 1,
};
this.canvas.Children.Add(rect);
}
public void CleanWindowBorder()
{
this.canvas.Children.Clear();
unsetMouseHook();
}
private void setMouseHook()
{
mouseHook.SetHook();
mouseHook.MouseDownEvent += MouseDownEventHandler;
mouseHook.MouseUpEvent += MouseUpEventHandler;
mouseHook.MouseMoveEvent += MouseMoveEventHandler;
mouseHook.MouseDoubleClickEvent += MouseDoubleClickHandler;
}
private void unsetMouseHook()
{
mouseHook.UnHook();
}
private void CommandBinding_ExitCaptureMode_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void CommandBinding_ExitCaptureMode_Executed(object sender, ExecutedRoutedEventArgs e)
{
CleanWindowBorder();
stopCapture();
}
}
}