-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHiddenForm.cs
More file actions
74 lines (56 loc) · 2.07 KB
/
HiddenForm.cs
File metadata and controls
74 lines (56 loc) · 2.07 KB
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
// Hidden form logic
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace KidTimerLock
{
public partial class HiddenForm : Form
{
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
private const int MOD_ALT = 0x1;
private const int MOD_CONTROL = 0x2;
public HiddenForm()
{
InitializeComponent();
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
this.Load += HiddenForm_Load;
}
private void HiddenForm_Load(object sender, EventArgs e)
{
// Register global hotkey CTRL + ALT + L
RegisterHotKey(this.Handle, 1, MOD_CONTROL | MOD_ALT, (int)Keys.L);
// When triggered, show TimerForm
var timerForm = new TimerForm();
timerForm.Show();
}
protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
if (m.Msg == WM_HOTKEY)
{
int id = m.WParam.ToInt32();
if (id == 1) // Our hotkey ID
{
ShowTimerForm(); // Reshow the main dialog
}
}
base.WndProc(ref m);
}
private void ShowTimerForm()
{
if (Application.OpenForms["TimerForm"] is TimerForm timerForm)
{
timerForm.Show();
timerForm.buttonStartAccept();
timerForm.WindowState = FormWindowState.Normal;
timerForm.BringToFront();
timerForm.Activate(); // Set focus to it
timerForm.Focus(); // Just to make sure
timerForm.FocusMinutesInput(); // set focus to minutes input field to avoid a mouse click
}
}
}
}