-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
66 lines (63 loc) · 2.31 KB
/
Program.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
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace LinkInterceptor;
static class Program {
[STAThread]
static void Main()
{
int WM_NCLBUTTONDOWN = 0xA1;
int HTCAPTION = 0x2;
[DllImport("User32.dll")]
static extern bool ReleaseCapture();
[DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
Form f = new Form();
f.BackColor = Color.Black;
f.FormBorderStyle = FormBorderStyle.None;
var screen = Screen.PrimaryScreen;
f.StartPosition = FormStartPosition.Manual;
f.Bounds = screen.Bounds;
f.Location = screen.WorkingArea.Location;
f.TopMost = true;
// f.DoubleClick += (object? sender, System.EventArgs e) =>
// {
// };
f.MouseDown += (object? sender, MouseEventArgs e) =>
{
if (e.Button == MouseButtons.Middle) {
// exit on middle click
Application.Exit();
}
if (e.Button == MouseButtons.Right) {
var me = Process.GetCurrentProcess()?.MainModule?.FileName;
if (me == null) return;
Process.Start(me);
}
if (e.Button != MouseButtons.Left) return;
var isFull = f.FormBorderStyle == FormBorderStyle.None;
if (e.Clicks >= 2) {
// toggle fullscreen
var screen = Screen.FromRectangle(new(f.Location, f.Size));
if (isFull)
{
f.FormBorderStyle = FormBorderStyle.FixedDialog;
f.Bounds = new(screen.Bounds.X + screen.Bounds.Width / 4, screen.Bounds.Y + screen.Bounds.Height / 4, screen.Bounds.Width/2, screen.Bounds.Height/2);
}
else
{
f.FormBorderStyle = FormBorderStyle.None;
f.Bounds = screen.Bounds;
}
} else {
// click and drag support
if (isFull) return;
ReleaseCapture();
SendMessage(f.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
};
Application.EnableVisualStyles();
Application.Run(f);
}
}