-
Notifications
You must be signed in to change notification settings - Fork 0
/
WndRzForm.cs
143 lines (124 loc) · 5.08 KB
/
WndRzForm.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WndRz.WindowResizer;
namespace WndRz
{
public partial class WndRzForm : Form
{
int _screenWidth;
int _screenHeight;
KeyboardHooker _keyboardHooker;
WindowResizer _windowResizer;
WndRzModel _model;
public const int MOD_ALT = 0x0001;
public const int MOD_CONTROL = 0x0002;
public const int MOD_NOREPEAT = 0x4000;
public const int MOD_SHIFT = 0x0004;
public const int MOD_WIN = 0x0008;
public WndRzForm()
{
InitializeComponent();
_keyboardHooker = KeyboardHooker.GetInstance();
_windowResizer = WindowResizer.GetInstance();
_screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
_screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
_model = new WndRzModel(_screenWidth, _screenHeight);
}
// Passing event to keyboard hooker to handle HotKey message
protected override void WndProc(ref Message m)
{
_keyboardHooker.WndProc(ref m);
base.WndProc(ref m);
}
private void OnFormLoad(object sender, EventArgs e)
{
Visible = false;
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN | MOD_ALT, Keys.Up, OnWindowFullTop);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN | MOD_ALT, Keys.Down, OnWindowFullBottom);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN | MOD_ALT, Keys.Left, OnWindowFullLeft);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN | MOD_ALT, Keys.Right, OnWindowFullRight);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN, Keys.Up, OnWindowTop);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN, Keys.Down, OnWindowBottom);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN, Keys.Left, OnWindowLeft);
_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN, Keys.Right, OnWindowRight);
//_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN | MOD_ALT, Keys.Down, OnWindowBottom);
//_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN, Keys.Up, OnWindowTopLeft);
//_keyboardHooker.Register(Handle, MOD_CONTROL | MOD_WIN, Keys.Down, OnWindowBottomLeft);
//_keyboardHooker.Register(Handle, MOD_WIN | MOD_ALT, Keys.Up, OnWindowTopRight);
//_keyboardHooker.Register(Handle, MOD_WIN | MOD_ALT, Keys.Down, OnWindowBottomRight);
}
private void OnWindowFullTop()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewFullTopRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Full top");
}
private void OnWindowFullBottom()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewFullBottomRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Full bottom");
}
private void OnWindowFullLeft()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewFullLeftRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Full left");
}
private void OnWindowFullRight()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewFullRightRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Full right");
}
private void OnFormClosed(object sender, FormClosedEventArgs e)
{
_keyboardHooker.Unregister(Handle);
}
private void OnWindowTop()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewTopRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Top");
}
private void OnWindowBottom()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewBottomRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Bottom");
}
private void OnWindowLeft()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewLeftRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Left");
}
private void OnWindowRight()
{
RECT rect = _windowResizer.GetCurrentWindowRect();
RECT newRect = _model.GetNewRightRect(rect);
_windowResizer.Resize(newRect);
Console.WriteLine("Right");
}
private void ClickClose(object sender, EventArgs e)
{
Close();
}
}
}