-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window.cpp
67 lines (59 loc) · 1.32 KB
/
Window.cpp
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
#include "Window.h"
std::function<void()> HandleHotkey;
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_HOTKEY:
if (wParam == Constants::HotkeyDownload && HandleHotkey)
HandleHotkey();
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
break;
}
}
Window::Window(HINSTANCE hInstance)
{
WNDCLASS wc = { 0 };
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpszClassName = Constants::ProgramName;
wc.lpszMenuName = NULL;
wc.lpfnWndProc = WndProc;
if (!RegisterClass(&wc))
MessageBox(NULL, _T("Failed registering window class"), _T("Error"), MB_ICONERROR | MB_OK);
hwnd = CreateWindow(
Constants::ProgramName,
Constants::ProgramName,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
// Ctrl-Shift-Alt-D
RegisterHotKey(hwnd, Constants::HotkeyDownload, MOD_NOREPEAT | MOD_SHIFT | MOD_CONTROL | MOD_ALT, 0x44);
}
Window::~Window()
{
UnregisterHotKey(hwnd, Constants::HotkeyDownload);
DestroyWindow(hwnd);
}
void Window::SetHotkeyHandler(const std::function<void()>& func)
{
HandleHotkey = func;
}