| LEFT | RIGHT |
| 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): parentWindow(parent) | 6 NotificationMessage::NotificationMessage(HWND parent): parentWindow(parent) |
| 7 { | 7 { |
| 8 toolTipWindow = 0; | 8 toolTipWindow = 0; |
| 9 InitializeCommonControls(); | 9 InitializeCommonControls(); |
| 10 }; | 10 }; |
| 11 | 11 |
| 12 bool NotificationMessage::commonControlsInitialized(false); | 12 bool NotificationMessage::commonControlsInitialized(false); |
| 13 | 13 |
| 14 void NotificationMessage::InitializeCommonControls() | 14 void NotificationMessage::InitializeCommonControls() |
| 15 { | 15 { |
| 16 if (!commonControlsInitialized) | 16 if (!commonControlsInitialized) |
| 17 { | 17 { |
| 18 INITCOMMONCONTROLSEX commControls; | 18 INITCOMMONCONTROLSEX commControls; |
| 19 commControls.dwSize = sizeof(INITCOMMONCONTROLSEX); | 19 commControls.dwSize = sizeof(commControls); |
| 20 commControls.dwICC = ICC_BAR_CLASSES; | 20 commControls.dwICC = ICC_BAR_CLASSES; |
| 21 InitCommonControlsEx(&commControls); | 21 InitCommonControlsEx(&commControls); |
| 22 commonControlsInitialized = true; | 22 commonControlsInitialized = true; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico
n) | 26 bool NotificationMessage::Show(std::wstring message, std::wstring title, int ico
n) |
| 27 { | 27 { |
| 28 if (toolTipWindow != 0) | 28 if (toolTipWindow != 0) |
| 29 { | 29 { |
| 30 Hide(); | 30 Hide(); |
| 31 } | 31 } |
| 32 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, | 32 toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, |
| 33 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, | 33 TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, |
| 34 0, 0, | 34 0, 0, |
| 35 0, 0, | 35 0, 0, |
| 36 parentWindow, NULL, NULL, | 36 parentWindow, NULL, NULL, |
| 37 NULL); | 37 NULL); |
| 38 | 38 |
| 39 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, | 39 SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, |
| 40 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); | 40 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
| 41 TOOLINFOW ti = {}; | 41 TOOLINFOW ti = {}; |
| 42 ti.cbSize = sizeof(TOOLINFOW); | 42 ti.cbSize = sizeof(ti); |
| 43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; | 43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; |
| 44 ti.hwnd = parentWindow; | 44 ti.hwnd = parentWindow; |
| 45 ti.hinst = NULL; | 45 ti.hinst = NULL; |
| 46 ti.uId = (UINT_PTR)parentWindow; | 46 ti.uId = (UINT_PTR)parentWindow; |
| 47 ti.lpszText = const_cast<LPWSTR>(message.c_str()); | 47 ti.lpszText = const_cast<LPWSTR>(message.c_str()); |
| 48 GetClientRect(parentWindow, &ti.rect); | 48 GetClientRect(parentWindow, &ti.rect); |
| 49 | 49 |
| 50 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); | 50 LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); |
| 51 | 51 |
| 52 RECT rect; | 52 RECT rect; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 70 | 70 |
| 71 void NotificationMessage::Move(short x, short y) | 71 void NotificationMessage::Move(short x, short y) |
| 72 { | 72 { |
| 73 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); | 73 ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title,
int icon) | 77 bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title,
int icon) |
| 78 { | 78 { |
| 79 TOOLINFOW ti = {}; | 79 TOOLINFOW ti = {}; |
| 80 ti.cbSize = sizeof(TOOLINFOW); | 80 ti.cbSize = sizeof(ti); |
| 81 ti.hwnd = parentWindow; | 81 ti.hwnd = parentWindow; |
| 82 ti.hinst = NULL; | 82 ti.hinst = NULL; |
| 83 ti.uId = (UINT_PTR)parentWindow; | 83 ti.uId = (UINT_PTR)parentWindow; |
| 84 ti.lpszText = const_cast<LPWSTR>(text.c_str()); | 84 ti.lpszText = const_cast<LPWSTR>(text.c_str()); |
| 85 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c
_str()); | 85 LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c
_str()); |
| 86 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); | 86 res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); |
| 87 return res == TRUE; | 87 return res == TRUE; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void NotificationMessage::SetParent(HWND parent) | 90 void NotificationMessage::SetParent(HWND parent) |
| 91 { | 91 { |
| 92 parentWindow = parent; | 92 parentWindow = parent; |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool NotificationMessage::IsVisible() | 95 bool NotificationMessage::IsVisible() |
| 96 { | 96 { |
| 97 if (toolTipWindow == 0) | 97 if (toolTipWindow == 0) |
| 98 return false; | 98 return false; |
| 99 return IsWindowVisible(toolTipWindow); | 99 return IsWindowVisible(toolTipWindow); |
| 100 } | 100 } |
| LEFT | RIGHT |