-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTOOLTIP_REPO.cpp
132 lines (105 loc) · 4.04 KB
/
TOOLTIP_REPO.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
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
#include "TOOLTIP_REPO.h"
TOOLTIP_REPO::TOOLTIP_REPO()
{
}
TOOLTIP_REPO::~TOOLTIP_REPO()
{
}
HINSTANCE TOOLTIP_REPO::SetHInstance(HINSTANCE hInst)
{
HINSTANCE oldHInst = this->hInstance;
this->hInstance = hInst;
return oldHInst;
}
void TOOLTIP_REPO::ActivateTooltips(BOOL activate)
{
this->active = activate;
for (auto const& tip : this->tooltips)
SendMessage(tip, TTM_ACTIVATE, activate, 0);
}
HWND TOOLTIP_REPO::CreateToolTip(HWND hWnd, WORD messageID) {
// Create the tooltip.
HWND hwndTip = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP //| TTS_BALLOON
, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hWnd, NULL, this->hInstance, NULL);
if (!hwndTip) return (HWND)NULL;
// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(TOOLINFO);
toolInfo.hwnd = NULL;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hWnd;
toolInfo.lpszText = (LPWSTR)MAKELPARAM(messageID, 0);
toolInfo.hinst = this->hInstance;
//GetClientRect(hwndTool, &toolInfo.rect);
//SendMessageW(hwndTip, TTM_ACTIVATE, TRUE, 0);
if (!SendMessageW(hwndTip, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&toolInfo)) { //Will add the Tool Tip on Control
DestroyWindow(hwndTip);
return (HWND)NULL;
}
SendMessage(hwndTip, TTM_ACTIVATE, this->active, 0);
this->AddTooltip(hwndTip);
return hwndTip;
}
HWND TOOLTIP_REPO::CreateToolTipForRect(HWND hwndParent, WORD messageID)
//INFO: Im really just creating a tooltip for the parent and assigning it a rect to work with
{
// Create a tooltip.
HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP //| TTS_BALLOON
, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwndParent, NULL, this->hInstance, NULL);
//SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
// Set up "tool" information. In this case, the "tool" is the entire parent window.
TOOLINFO ti = { 0 };
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwndParent;
ti.hinst = this->hInstance;
ti.lpszText = (LPWSTR)MAKELPARAM(messageID, 0);
GetClientRect(hwndParent, &ti.rect);
// Associate the tooltip with the "tool" window.
if (!SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti)) {
//MessageBox(hwndParent, TEXT("Failed to add tooltip"), L"Smart Veil Error", MB_OK);
DestroyWindow(hwndTT);
return (HWND)NULL;
}
SendMessage(hwndTT, TTM_ACTIVATE, this->active, 0);
this->AddTooltip(hwndTT);
return hwndTT;
}
HWND TOOLTIP_REPO::CreateToolTipForRect(HWND hwndParent, HWND hwndTool, WORD messageID)
//INFO: Im really just creating a tooltip for the parent and resizing it to the position & size of the child
{
// Create a tooltip.
HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP //| TTS_BALLOON
, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hwndParent, NULL, this->hInstance, NULL);
//SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
// Set up "tool" information. In this case, the "tool" is the entire parent window.
TOOLINFO ti = { 0 };
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwndParent;
ti.hinst = this->hInstance;
ti.lpszText = (LPWSTR)MAKELPARAM(messageID, 0);
GetClientRect(hwndTool, &ti.rect);
MapWindowPoints(hwndTool, hwndParent, (LPPOINT)&ti.rect, 2);
// ti.rect.right /= 2;
// Associate the tooltip with the "tool" window.
if (!SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti)) {
//MessageBox(hwndParent, TEXT("Failed to add tooltip"), L"Smart Veil Error", MB_OK);
DestroyWindow(hwndTT);
return (HWND)NULL;
}
SendMessage(hwndTT, TTM_ACTIVATE, this->active, 0);
this->AddTooltip(hwndTT);
return hwndTT;
}
void TOOLTIP_REPO::AddTooltip(HWND tooltip)
{
if (!tooltip) return;
tooltips.push_back(tooltip);
}