Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/plugin/NotificationMessage.cpp

Issue 12836004: Fixed crash caused by update tooltips, TOOLINFO.hwnd cannot be thetooltip itself (causes a recursi… (Closed)
Patch Set: Created Oct. 9, 2013, 5:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
(...skipping 16 matching lines...) Expand all
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(TOOLINFOW);
43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT; 43 ti.uFlags = TTF_IDISHWND | TTF_TRACK | TTF_TRANSPARENT;
44 ti.hwnd = toolTipWindow; 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;
53 GetWindowRect(parentWindow, &rect); 53 GetWindowRect(parentWindow, &rect);
54 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);
55 55
56 SetTextAndIcon(message, title, icon); 56 SetTextAndIcon(message, title, icon);
57 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti); 57 res = ::SendMessage(toolTipWindow, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
58 58
59 return true; 59 return true;
60 } 60 }
61 61
62 void NotificationMessage::Hide() 62 void NotificationMessage::Hide()
63 { 63 {
64 if (toolTipWindow != 0) 64 if (toolTipWindow != 0)
65 { 65 {
66 DestroyWindow(toolTipWindow); 66 DestroyWindow(toolTipWindow);
67 toolTipWindow = 0; 67 toolTipWindow = 0;
68 } 68 }
69 } 69 }
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(TOOLINFOW);
81 ti.hwnd = toolTipWindow; 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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld