-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_btn.cpp
103 lines (84 loc) · 2.1 KB
/
generate_btn.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
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
#include "generate_btn.h"
#include <Windows.h>
#include <CommCtrl.h> // DefSubclassProc
::LRESULT __stdcall ::generate_btn_proc(
::HWND gen_btn,
::UINT msg,
::WPARAM wparam,
::LPARAM lparam,
::UINT_PTR sub_class,
::DWORD_PTR ref_data)
{
UNREFERENCED_PARAMETER(sub_class);
UNREFERENCED_PARAMETER(ref_data);
static bool is_mouse_on_btn{ false };
switch (msg)
{
case WM_PAINT:
{
const ::HFONT text_font{ ::CreateFontW(
22,
0,
0,
0,
FW_NORMAL,
FW_DONTCARE,
0,
0,
DEFAULT_CHARSET,
OUT_TT_ONLY_PRECIS,
CLIP_CHARACTER_PRECIS,
PROOF_QUALITY,
FF_MODERN,
L"Segoe UI") };
::PAINTSTRUCT ps{};
::HDC hdc{ BeginPaint(gen_btn, &ps) };
::SelectObject(hdc, text_font);
::SetTextColor(hdc, RGB(255u, 255u, 255u));
::COLORREF background_color{ (is_mouse_on_btn) ? RGB(45, 45, 45) : RGB(35, 35, 35) };
::SetBkColor(hdc, background_color);
::HBRUSH backgroundBrush{ ::CreateSolidBrush(background_color) };
::RECT crect{};
::GetClientRect(gen_btn, &crect);
::FillRect(hdc, &crect, backgroundBrush);
::DrawTextW(
hdc,
L"Сгенерировать пароли",
::lstrlenW(L"Сгенерировать пароли"),
&crect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
::DeleteObject(text_font);
::DeleteObject(backgroundBrush);
::EndPaint(gen_btn, &ps);
break;
}
case WM_MOUSEMOVE:
{
::TRACKMOUSEEVENT tme{};
tme.cbSize = sizeof(::TRACKMOUSEEVENT);
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.dwHoverTime = 1;
tme.hwndTrack = gen_btn;
::TrackMouseEvent(&tme);
break;
}
case WM_MOUSELEAVE:
is_mouse_on_btn = false;
InvalidateRect(gen_btn, NULL, FALSE); // перерисовка окна
break;
case WM_MOUSEHOVER:
is_mouse_on_btn = true;
InvalidateRect(gen_btn, NULL, FALSE);
SendMessage(gen_btn, WM_SETCURSOR, NULL, NULL);
break;
case WM_SETCURSOR:
{
static ::HCURSOR hCursor{ LoadCursorW(NULL, IDC_HAND) };
SetCursor(hCursor);
break;
}
default:
return DefSubclassProc(gen_btn, msg, wparam, lparam);
}
return 0;
}