-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageHandlerForm.cs
69 lines (56 loc) · 1.93 KB
/
MessageHandlerForm.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
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Tulpep.NotificationWindow;
namespace ImageToText
{
public partial class MessageHandlerForm : Form, IDisposable
{
private ClipBoardUpdaterImageToText _updater;
private PopupNotifier _popup;
public MessageHandlerForm()
{
InitializeComponent();
ShowInTaskbar = false;
WindowState = FormWindowState.Minimized;
Init();
RegisterHotKey(Handle, 0, (int)KeyModifier.Control, Keys.M.GetHashCode());
FormClosing += MessageHandler_FormClosing;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0312)
{
_updater.Update();
}
base.WndProc(ref m);
}
private void Init()
{
_popup = PopupInit();
_updater = new ClipBoardUpdaterImageToText(
str =>
{
_popup.ContentText = str;
_popup.Popup();
},
new ImageToTextConverter()
);
}
private PopupNotifier PopupInit()
{
var popup = new PopupNotifier
{
TitleText = "Распознавание текста",
TitleFont = new System.Drawing.Font("Consolas", 14),
ContentFont = new System.Drawing.Font("Consolas", 12)
};
return popup;
}
private void MessageHandler_FormClosing(object sender, FormClosingEventArgs e) => UnregisterHotKey(Handle, 0);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
}
}