Index: src/plugin/NotificationMessage.cpp |
=================================================================== |
--- a/src/plugin/NotificationMessage.cpp |
+++ b/src/plugin/NotificationMessage.cpp |
@@ -1,28 +1,30 @@ |
-#include <Windows.h> |
-#include <CommCtrl.h> |
+#include <Windows.h> |
+#include <CommCtrl.h> |
#include "NotificationMessage.h" |
NotificationMessage::NotificationMessage() |
{ |
- CommonControlsInitialize(); |
+ toolTipWindow = 0; |
+ InitializeCommonControls(); |
} |
-NotificationMessage::NotificationMessage(HWND parent) |
-{ |
- parentWindow = parent; |
- CommonControlsInitialize(); |
-}; |
- |
-bool NotificationMessage::commonControlsInitialized(false); |
+NotificationMessage::NotificationMessage(HWND parent) |
Wladimir Palant
2013/09/25 14:00:44
You can merge the two constuctors by specifying 0
|
+{ |
+ parentWindow = parent; |
+ toolTipWindow = 0; |
+ InitializeCommonControls(); |
+}; |
-void NotificationMessage::CommonControlsInitialize() |
-{ |
- if (!commonControlsInitialized) |
- { |
- INITCOMMONCONTROLSEX commControls; |
- commControls.dwSize = sizeof(INITCOMMONCONTROLSEX); |
- commControls.dwICC = ICC_BAR_CLASSES; |
+bool NotificationMessage::commonControlsInitialized(false); |
+ |
+void NotificationMessage::InitializeCommonControls() |
+{ |
+ if (!commonControlsInitialized) |
+ { |
+ INITCOMMONCONTROLSEX commControls; |
+ commControls.dwSize = sizeof(INITCOMMONCONTROLSEX); |
+ commControls.dwICC = ICC_BAR_CLASSES; |
InitCommonControlsEx(&commControls); |
commonControlsInitialized = true; |
} |
@@ -30,6 +32,10 @@ |
bool NotificationMessage::Show(std::wstring message, std::wstring title, int icon) |
{ |
+ if (toolTipWindow != 0) |
+ { |
+ Hide(); |
+ } |
toolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, |
TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE, |
0, 0, |
@@ -39,52 +45,59 @@ |
SetWindowPos(toolTipWindow, HWND_TOPMOST,0, 0, 0, 0, |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
- TOOLINFO ti; |
- ti.cbSize = sizeof(TOOLINFO); |
+ TOOLINFOW ti; |
+ ti.cbSize = sizeof(TOOLINFOW); |
ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; |
- ti.hwnd = toolTipWindow; |
- ti.hinst = NULL; |
- ti.uId = (UINT_PTR)parentWindow; |
- ti.lpszText = (LPWSTR)message.c_str(); |
+ ti.hwnd = toolTipWindow; |
+ ti.hinst = NULL; |
+ ti.uId = (UINT_PTR)parentWindow; |
+ ti.lpszText = const_cast<LPWSTR>(message.c_str()); |
GetClientRect(parentWindow, &ti.rect); |
- LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); |
- |
- RECT rect; |
- GetWindowRect(parentWindow, &rect); |
- Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); |
+ LRESULT res = ::SendMessage(toolTipWindow, TTM_ADDTOOL, 0, (LPARAM)&ti); |
- res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str()); |
- res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)(LPTOOLINFO) &ti); |
+ RECT rect; |
+ GetWindowRect(parentWindow, &rect); |
+ Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); |
+ |
+ res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str()); |
Wladimir Palant
2013/09/25 14:00:44
Not sure where my comment on the previous changese
|
+ res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti); |
return true; |
} |
bool NotificationMessage::Hide() |
{ |
- DestroyWindow(toolTipWindow); |
- toolTipWindow = 0; |
- return true; |
+ if (IsVisible()) |
Wladimir Palant
2013/09/25 14:00:44
This seems to be the wrong check to me - we want t
|
+ { |
+ DestroyWindow(toolTipWindow); |
+ toolTipWindow = 0; |
+ return true; |
+ } |
+ else |
+ { |
+ return false; |
+ } |
} |
void NotificationMessage::Move(short x, short y) |
{ |
- ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, (LPARAM)(LPTOOLINFO)MAKELONG(x, y)); |
+ ::SendMessage(toolTipWindow, TTM_TRACKPOSITION, 0, MAKELONG(x, y)); |
return; |
} |
bool NotificationMessage::SetTextAndIcon(std::wstring text, std::wstring title, int icon) |
{ |
- TOOLINFO ti; |
- ti.cbSize = sizeof(TOOLINFO); |
+ TOOLINFOW ti; |
+ ti.cbSize = sizeof(TOOLINFOW); |
ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; |
- ti.hwnd = toolTipWindow; |
- ti.hinst = NULL; |
- ti.uId = (UINT_PTR)parentWindow; |
- ti.lpszText = (LPWSTR)text.c_str(); |
+ ti.hwnd = toolTipWindow; |
+ ti.hinst = NULL; |
+ ti.uId = (UINT_PTR)parentWindow; |
+ ti.lpszText = const_cast<LPWSTR>(text.c_str()); |
GetClientRect(parentWindow, &ti.rect); |
- LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str()); |
- res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); |
+ LRESULT res = ::SendMessage(toolTipWindow, TTM_SETTITLE, icon, (LPARAM)title.c_str()); |
+ res = ::SendMessage(toolTipWindow, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); |
return res == TRUE; |
} |
@@ -92,6 +105,7 @@ |
{ |
parentWindow = parent; |
} |
+ |
bool NotificationMessage::IsVisible() |
{ |
if (toolTipWindow == 0) |