-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMask.cs
104 lines (90 loc) · 3.14 KB
/
Mask.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Drawing;
using System.Windows.Forms;
using WindowsAPI;
namespace Gotchya
{
/// <summary>
/// This is a transparent layer that can be placed on top of a window to create an effect.
/// </summary>
public partial class Mask : Form
{
bool mouseDown = false;
Point clickPoint = new Point(0, 0);
bool movementEnabled = true;
public Mask() {
InitializeComponent();
}
/// <summary>
/// Create a form to overlay the desktop with an image.
/// </summary>
/// <param name="bmp">The overlay image.</param>
public Mask(Bitmap bmp) {
InitializeComponent();
OverlayWindow(bmp);
}
/// <summary>
/// Create a form to overlay a window with an image.
/// </summary>
/// <param name="hWnd">The handle to the window.</param>
/// <param name="bmp">The overlay image.</param>
public Mask(IntPtr hWnd, Bitmap bmp) {
InitializeComponent();
OverlayWindow(hWnd, bmp);
}
/// <summary>
/// Overlays the desktop with a specified image.
/// </summary>
/// <param name="bmp">The overlay image.</param>
public void OverlayWindow(Bitmap bmp) {
Show();
Location = new Point(0, 0);
Size = Screen.PrimaryScreen.Bounds.Size;
TopMost = true;
Picture.Image = bmp;
Refresh();
}
/// <summary>
/// Overlays a window with a specified image.
/// </summary>
/// <param name="hWnd">The handle to the window.</param>
/// <param name="bmp">The overlay image.</param>
public void OverlayWindow(IntPtr hWnd, Bitmap bmp) {
Show();
Location = Window.GetLocation(hWnd);
Size = Window.GetSize(hWnd);
TopMost = true;
Picture.Image = bmp;
Refresh();
}
/// <summary>
/// Allows the user to drag the layer to new locations.
/// </summary>
public void EnableMovement() {
movementEnabled = true;
}
/// <summary>
/// Prevents the user from dragging the layer to new locations.
/// </summary>
public void DisableMovement() {
movementEnabled = false;
}
private void Picture_MouseMove(object sender, MouseEventArgs e) {
if (mouseDown && movementEnabled) {
Location = new Point(Cursor.Position.X + clickPoint.X, Cursor.Position.Y + clickPoint.Y);
}
}
private void Picture_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
mouseDown = true;
clickPoint = new Point(Location.X - Cursor.Position.X, Location.Y - Cursor.Position.Y);
}
}
private void Picture_MouseUp(object sender, MouseEventArgs e) {
mouseDown = false;
}
private void Picture_MouseClick(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Right) Application.Exit();
}
}
}