OLD | NEW |
1 #include <Windows.h> | 1 #include <Windows.h> |
2 #include <CommCtrl.h> | 2 #include <CommCtrl.h> |
3 | 3 |
4 #include "NotificationMessage.h" | 4 #include "NotificationMessage.h" |
5 | 5 |
6 NotificationMessage::NotificationMessage(HWND parent) | 6 NotificationMessage::NotificationMessage(HWND parent): parentWindow(parent) |
7 { | 7 { |
8 parentWindow = parent; | |
9 toolTipWindow = 0; | 8 toolTipWindow = 0; |
10 InitializeCommonControls(); | 9 InitializeCommonControls(); |
11 }; | 10 }; |
12 | 11 |
13 bool NotificationMessage::commonControlsInitialized(false); | 12 bool NotificationMessage::commonControlsInitialized(false); |
14 | 13 |
15 void NotificationMessage::InitializeCommonControls() | 14 void NotificationMessage::InitializeCommonControls() |
16 { | 15 { |
17 if (!commonControlsInitialized) | 16 if (!commonControlsInitialized) |
18 { | 17 { |
(...skipping 13 matching lines...) Expand all Loading... |
32 } | 31 } |
33 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, | 32 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, |
34 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, | 33 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, |
35 0, 0, | 34 0, 0, |
36 0, 0, | 35 0, 0, |
37 parentWindow, NULL, NULL, | 36 parentWindow, NULL, NULL, |
38 NULL); | 37 NULL); |
39 | 38 |
40 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, | 39 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, |
41 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | 40 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
42 TOOLINFOW ti; | 41 TOOLINFOW ti = {}; |
43 ti.cbSize = sizeof(TOOLINFOW); | 42 ti.cbSize = sizeof(TOOLINFOW); |
44 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; | 43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; |
45 ti.hwnd = toolTipWindow; | 44 ti.hwnd = toolTipWindow; |
46 ti.hinst = NULL; | 45 ti.hinst = NULL; |
47 ti.uId = (UINT_PTR)parentWindow; | 46 ti.uId = (UINT_PTR)parentWindow; |
48 ti.lpszText = const_cast<LPWSTR>(message.c_str()); | 47 ti.lpszText = const_cast<LPWSTR>(message.c_str()); |
49 GetClientRect(parentWindow, &ti.rect); | 48 GetClientRect(parentWindow, &ti.rect); |
50 | 49 |
51 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); | 50 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); |
52 | 51 |
53 RECT rect; | 52 RECT rect; |
54 GetWindowRect(parentWindow, &rect); | 53 GetWindowRect(parentWindow, &rect); |
55 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.
top) / 2); | 54 Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.
top) / 2); |
56 | 55 |
57 SetTextAndIcon(message, title, icon); | 56 SetTextAndIcon(message, title, icon); |
58 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti); | 57 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti); |
(...skipping 11 matching lines...) Expand all Loading... |
70 } | 69 } |
71 | 70 |
72 void NotificationMessage::Move(short x, short y) | 71 void NotificationMessage::Move(short x, short y) |
73 { | 72 { |
74 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); | 73 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); |
75 return; | 74 return; |
76 } | 75 } |
77 | 76 |
78 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title,
int icon) | 77 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title,
int icon) |
79 { | 78 { |
80 TOOLINFOW ti; | 79 TOOLINFOW ti = {}; |
81 memset(&ti, 0, sizeof(TOOLINFOW)); | |
82 ti.cbSize = sizeof(TOOLINFOW); | 80 ti.cbSize = sizeof(TOOLINFOW); |
83 ti.hwnd = toolTipWindow; | 81 ti.hwnd = toolTipWindow; |
84 ti.hinst = NULL; | 82 ti.hinst = NULL; |
85 ti.uId = (UINT_PTR)parentWindow; | 83 ti.uId = (UINT_PTR)parentWindow; |
86 ti.lpszText = const_cast<LPWSTR>(text.c_str()); | 84 ti.lpszText = const_cast<LPWSTR>(text.c_str()); |
87 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c
_str()); | 85 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c
_str()); |
88 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); | 86 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); |
89 return res == TRUE; | 87 return res == TRUE; |
90 } | 88 } |
91 | 89 |
92 void NotificationMessage::SetParent(HWND parent) | 90 void NotificationMessage::SetParent(HWND parent) |
93 { | 91 { |
94 parentWindow = parent; | 92 parentWindow = parent; |
95 } | 93 } |
96 | 94 |
97 bool NotificationMessage::IsVisible() | 95 bool NotificationMessage::IsVisible() |
98 { | 96 { |
99 if (toolTipWindow == 0) | 97 if (toolTipWindow == 0) |
100 return false; | 98 return false; |
101 return IsWindowVisible(toolTipWindow); | 99 return IsWindowVisible(toolTipWindow); |
102 } | 100 } |
OLD | NEW |