1 | //////////////////////////////////////////////////////////// |
---|
2 | // Copyright (C) Roman Ryltsov, 2008-2011 |
---|
3 | // Created by Roman Ryltsov roman@alax.info |
---|
4 | // |
---|
5 | // $Id: NotifyIconWindow.h 99 2012-08-22 22:44:15Z roman $ |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #include <vfwmsgs.h> |
---|
10 | #include <asferr.h> // FACILITY_NS |
---|
11 | #include <mferror.h> // FACILITY_MF |
---|
12 | #include <wmcodecdsp.h> // FACILITY_WMAAECMA |
---|
13 | #include <ddraw.h> // _FACD3D |
---|
14 | //#include <d3d9helper.h> // _FACD3D |
---|
15 | #include <d3d9.h> // _FACD3D |
---|
16 | #include <d2derr.h> // FACILITY_D2D |
---|
17 | #include <wincodec.h> // FACILITY_WINCODEC_ERR |
---|
18 | #include "rowinhttp.h" |
---|
19 | #include "AboutDialog.h" |
---|
20 | |
---|
21 | //////////////////////////////////////////////////////////// |
---|
22 | // CNotifyIconWindow |
---|
23 | |
---|
24 | class CNotifyIconWindow : |
---|
25 | public CMessageOnlyWindowImpl<CNotifyIconWindow> |
---|
26 | { |
---|
27 | public: |
---|
28 | |
---|
29 | DECLARE_WND_CLASS(_T("CNotifyIconWindow")) |
---|
30 | |
---|
31 | BEGIN_MSG_MAP_EX(CNotifyIconWindow) |
---|
32 | _Z4(atlTraceUI, 4, _T("uMsg 0x%04X, wParam 0x%08X, lParam 0x%08X\n"), uMsg, wParam, lParam); |
---|
33 | //CHAIN_MSG_MAP(CMessageOnlyWindowImpl<CNotifyIconWindow>) |
---|
34 | MSG_WM_CREATE(OnCreate) |
---|
35 | MSG_WM_DESTROY(OnDestroy) |
---|
36 | MSG_WM_CHANGECBCHAIN(OnChangeCbChain) |
---|
37 | MSG_WM_DRAWCLIPBOARD(OnDrawClipboard) |
---|
38 | MSG_WM_MOUSEMOVE(OnMouseMove) |
---|
39 | MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk) |
---|
40 | MSG_WM_RBUTTONUP(OnRButtonUp) |
---|
41 | MESSAGE_HANDLER_EX(NIN_BALLOONUSERCLICK, OnNotifyIconBalloonUserClick) |
---|
42 | MESSAGE_HANDLER_EX(WM_NOTIFYICON, OnNotifyIcon) |
---|
43 | COMMAND_ID_HANDLER_EX(ID_APP_ABOUT, OnApplicationAbout) |
---|
44 | COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnApplicationExit) |
---|
45 | REFLECT_NOTIFICATIONS() |
---|
46 | END_MSG_MAP() |
---|
47 | |
---|
48 | public: |
---|
49 | |
---|
50 | ////////////////////////////////////////////////////////// |
---|
51 | // Window Message Identifiers |
---|
52 | |
---|
53 | enum |
---|
54 | { |
---|
55 | WM_FIRST = WM_APP, |
---|
56 | WM_NOTIFYICON, |
---|
57 | }; |
---|
58 | |
---|
59 | private: |
---|
60 | ULONGLONG m_nCommonControlsVersion; |
---|
61 | ULONGLONG m_nShellVersion; |
---|
62 | NOTIFYICONDATA m_NotifyIconData; |
---|
63 | CWindow m_NextClipboardViewerWindow; |
---|
64 | CString m_sQuery; |
---|
65 | |
---|
66 | static BOOL IsQuartzResult(HRESULT nResult, CString* psMessage = NULL) |
---|
67 | { |
---|
68 | if(HRESULT_FACILITY(nResult) != FACILITY_ITF) |
---|
69 | return FALSE; |
---|
70 | const SCODE nCode = HRESULT_CODE(nResult); |
---|
71 | if(nCode < 0x0200)// && nCode <= 0xFFFF) |
---|
72 | return FALSE; |
---|
73 | const CString sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("quartz.dll")), nResult); |
---|
74 | if(sMessage.IsEmpty()) |
---|
75 | return FALSE; |
---|
76 | if(psMessage) |
---|
77 | *psMessage = sMessage; |
---|
78 | return TRUE; |
---|
79 | } |
---|
80 | static CString LookupQuartzIdentifier(HRESULT nValue) |
---|
81 | { |
---|
82 | static const struct { HRESULT nValue; LPCSTR pszName; } g_pMap[] = |
---|
83 | { |
---|
84 | #define A(x) { x, #x }, |
---|
85 | #include "DsIdentifier.inc" |
---|
86 | #undef A |
---|
87 | }; |
---|
88 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
89 | if(g_pMap[nIndex].nValue == nValue) |
---|
90 | return CString(g_pMap[nIndex].pszName); |
---|
91 | return _T(""); |
---|
92 | } |
---|
93 | static BOOL IsWmResult(HRESULT nResult, CString* psMessage = NULL) |
---|
94 | { |
---|
95 | if(HRESULT_FACILITY(nResult) != FACILITY_NS) |
---|
96 | return FALSE; |
---|
97 | // SUGG: Cache loaded libraries |
---|
98 | HMODULE hModule = NULL; |
---|
99 | const SCODE nCode = HRESULT_CODE(nResult); |
---|
100 | CString sMessage; |
---|
101 | if(nCode >= 2000 && nCode < 3000) // 2000 - 2999 = ASF (defined in ASFERR.MC) |
---|
102 | sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("asferror.dll")), nResult); |
---|
103 | else |
---|
104 | sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("wmerror.dll")), nResult); |
---|
105 | if(sMessage.IsEmpty()) |
---|
106 | return FALSE; |
---|
107 | if(psMessage) |
---|
108 | *psMessage = sMessage; |
---|
109 | return TRUE; |
---|
110 | } |
---|
111 | static BOOL IsMfResult(HRESULT nResult, CString* psMessage = NULL) |
---|
112 | { |
---|
113 | if(HRESULT_FACILITY(nResult) != FACILITY_MF) |
---|
114 | return FALSE; |
---|
115 | const CString sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("mferror.dll")), nResult); |
---|
116 | if(sMessage.IsEmpty()) |
---|
117 | return FALSE; |
---|
118 | if(psMessage) |
---|
119 | *psMessage = sMessage; |
---|
120 | return TRUE; |
---|
121 | } |
---|
122 | static CString LookupMfIdentifier(HRESULT nValue) |
---|
123 | { |
---|
124 | static const struct { HRESULT nValue; LPCSTR pszName; } g_pMap[] = |
---|
125 | { |
---|
126 | #define A(x) { x, #x }, |
---|
127 | #include "MfIdentifier.inc" |
---|
128 | #undef A |
---|
129 | }; |
---|
130 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
131 | if(g_pMap[nIndex].nValue == nValue) |
---|
132 | return CString(g_pMap[nIndex].pszName); |
---|
133 | return _T(""); |
---|
134 | } |
---|
135 | static BOOL IsWs2Result(HRESULT nResult, CString* psMessage = NULL) |
---|
136 | { |
---|
137 | if(HRESULT_FACILITY(nResult) != FACILITY_WIN32) |
---|
138 | return FALSE; |
---|
139 | const SCODE nCode = HRESULT_CODE(nResult); |
---|
140 | if(nCode < 10000 || nCode >= 11150) // WSABASEERR, ... |
---|
141 | return FALSE; |
---|
142 | const CString sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("ws2_32.dll")), nResult); |
---|
143 | if(sMessage.IsEmpty()) |
---|
144 | return FALSE; |
---|
145 | if(psMessage) |
---|
146 | *psMessage = sMessage; |
---|
147 | return TRUE; |
---|
148 | } |
---|
149 | static BOOL IsWinHttpResult(HRESULT nResult, CString* psMessage = NULL) |
---|
150 | { |
---|
151 | if(HRESULT_FACILITY(nResult) != FACILITY_WIN32) |
---|
152 | return FALSE; |
---|
153 | const LONG nCode = HRESULT_CODE(nResult); |
---|
154 | if(nCode < 12000 || nCode >= 12200) // WINHTTP_ERROR_BASE, WINHTTP_ERROR_LAST |
---|
155 | return FALSE; |
---|
156 | const CString sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("winhttp.dll")), nResult); |
---|
157 | if(sMessage.IsEmpty()) |
---|
158 | return FALSE; |
---|
159 | if(psMessage) |
---|
160 | *psMessage = sMessage; |
---|
161 | return TRUE; |
---|
162 | } |
---|
163 | static BOOL IsWinInetResult(HRESULT nResult, CString* psMessage = NULL) |
---|
164 | { |
---|
165 | if(HRESULT_FACILITY(nResult) != FACILITY_WIN32) |
---|
166 | return FALSE; |
---|
167 | const LONG nCode = HRESULT_CODE(nResult); |
---|
168 | if(nCode < 12000 || nCode >= 12200) // INTERNET_ERROR_BASE, INTERNET_ERROR_LAST |
---|
169 | return FALSE; |
---|
170 | const CString sMessage = AtlFormatSystemMessage(CDataLibraryMap::LoadLibrary(_T("wininet.dll")), nResult); |
---|
171 | if(sMessage.IsEmpty()) |
---|
172 | return FALSE; |
---|
173 | if(psMessage) |
---|
174 | *psMessage = sMessage; |
---|
175 | return TRUE; |
---|
176 | } |
---|
177 | static CString LookupSystemIdentifier(HRESULT nValue) |
---|
178 | { |
---|
179 | if(HRESULT_SEVERITY(nValue) == SEVERITY_ERROR && HRESULT_FACILITY(nValue) == FACILITY_WIN32) |
---|
180 | nValue = HRESULT_CODE(nValue); |
---|
181 | if(nValue < 0 || nValue >= 16384) |
---|
182 | return _T(""); |
---|
183 | static const struct { HRESULT nValue; LPCSTR pszName; } g_pMap[] = |
---|
184 | { |
---|
185 | #define A(x) { x, #x }, |
---|
186 | #include "SystemIdentifier.inc" |
---|
187 | #undef A |
---|
188 | }; |
---|
189 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
190 | if(g_pMap[nIndex].nValue == nValue) |
---|
191 | return CString(g_pMap[nIndex].pszName); |
---|
192 | return _T(""); |
---|
193 | } |
---|
194 | static BOOL IsD3dResult(HRESULT nResult, CString* psMessage = NULL) |
---|
195 | { |
---|
196 | if(HRESULT_FACILITY(nResult) != _FACD3D) |
---|
197 | return FALSE; |
---|
198 | psMessage; |
---|
199 | return !LookupD3dIdentifier(nResult).IsEmpty(); |
---|
200 | } |
---|
201 | static CString LookupD3dIdentifier(HRESULT nValue) |
---|
202 | { |
---|
203 | static const struct { HRESULT nValue; LPCSTR pszName; } g_pMap[] = |
---|
204 | { |
---|
205 | #define A(x) { x, #x }, |
---|
206 | #include "D3dIdentifier.inc" |
---|
207 | #undef A |
---|
208 | }; |
---|
209 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
210 | if(g_pMap[nIndex].nValue == nValue) |
---|
211 | return CString(g_pMap[nIndex].pszName); |
---|
212 | return _T(""); |
---|
213 | } |
---|
214 | static BOOL IsD2dResult(HRESULT nResult, CString* psMessage = NULL) |
---|
215 | { |
---|
216 | if(HRESULT_FACILITY(nResult) != FACILITY_D2D) |
---|
217 | return FALSE; |
---|
218 | psMessage; |
---|
219 | return !LookupD2dIdentifier(nResult).IsEmpty(); |
---|
220 | } |
---|
221 | static CString LookupD2dIdentifier(HRESULT nValue) |
---|
222 | { |
---|
223 | static const struct { HRESULT nValue; LPCSTR pszName; } g_pMap[] = |
---|
224 | { |
---|
225 | #define A(x) { x, #x }, |
---|
226 | #include "D2dIdentifier.inc" |
---|
227 | #undef A |
---|
228 | }; |
---|
229 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
230 | if(g_pMap[nIndex].nValue == nValue) |
---|
231 | return CString(g_pMap[nIndex].pszName); |
---|
232 | return _T(""); |
---|
233 | } |
---|
234 | static BOOL IsWicResult(HRESULT nResult, CString* psMessage = NULL) |
---|
235 | { |
---|
236 | if(HRESULT_FACILITY(nResult) != FACILITY_WINCODEC_ERR) |
---|
237 | return FALSE; |
---|
238 | psMessage; |
---|
239 | return !LookupWicIdentifier(nResult).IsEmpty(); |
---|
240 | } |
---|
241 | static CString LookupWicIdentifier(HRESULT nValue) |
---|
242 | { |
---|
243 | static const struct { HRESULT nValue; LPCSTR pszName; } g_pMap[] = |
---|
244 | { |
---|
245 | #define A(x) { x, #x }, |
---|
246 | #include "WicIdentifier.inc" |
---|
247 | #undef A |
---|
248 | }; |
---|
249 | for(SIZE_T nIndex = 0; nIndex < DIM(g_pMap); nIndex++) |
---|
250 | if(g_pMap[nIndex].nValue == nValue) |
---|
251 | return CString(g_pMap[nIndex].pszName); |
---|
252 | return _T(""); |
---|
253 | } |
---|
254 | |
---|
255 | public: |
---|
256 | // CNotifyIconWindow |
---|
257 | static ULONGLONG GetCommonControlsVersion() throw() |
---|
258 | { |
---|
259 | DWORD nMajorVersion, nMinorVersion; |
---|
260 | _W(SUCCEEDED(AtlGetCommCtrlVersion(&nMajorVersion, &nMinorVersion))); |
---|
261 | return (ULONGLONG) ((nMajorVersion << 16) + nMinorVersion) << 32; |
---|
262 | } |
---|
263 | static ULONGLONG GetShellVersion() throw() |
---|
264 | { |
---|
265 | DWORD nMajorVersion, nMinorVersion; |
---|
266 | _W(SUCCEEDED(AtlGetShellVersion(&nMajorVersion, &nMinorVersion))); |
---|
267 | return (ULONGLONG) ((nMajorVersion << 16) + nMinorVersion) << 32; |
---|
268 | } |
---|
269 | CNotifyIconWindow() |
---|
270 | { |
---|
271 | } |
---|
272 | HWND Create() |
---|
273 | { |
---|
274 | return __super::Create(NULL, rcDefault, _T("AlaxInfo.ShowHresult.NotifyIconWindow")); |
---|
275 | } |
---|
276 | static CString GetDefaultInfoTitle() |
---|
277 | { |
---|
278 | return AtlLoadString(IDS_NOTIFYICON_DEFAULTTIPTITLE); |
---|
279 | } |
---|
280 | static DWORD GetDefaultInfoFlags() throw() |
---|
281 | { |
---|
282 | return NIIF_NONE; |
---|
283 | } |
---|
284 | VOID SetBalloonToolTip(DWORD nFlags, LPCTSTR pszTitle, LPCTSTR pszText, UINT nTimeout = 30 * 1000) |
---|
285 | { |
---|
286 | if(IsWindow() && m_NotifyIconData.uFlags & NIF_INFO) |
---|
287 | { |
---|
288 | m_NotifyIconData.uTimeout = nTimeout; |
---|
289 | m_NotifyIconData.dwInfoFlags = nFlags; |
---|
290 | _tcsncpy_s(m_NotifyIconData.szInfoTitle, pszTitle, _TRUNCATE); |
---|
291 | _tcsncpy_s(m_NotifyIconData.szInfo, pszText, _TRUNCATE); |
---|
292 | _W(Shell_NotifyIcon(NIM_MODIFY, &m_NotifyIconData)); |
---|
293 | } |
---|
294 | } |
---|
295 | BOOL Process(LPCTSTR pszText) |
---|
296 | { |
---|
297 | #pragma region Parse |
---|
298 | if(_tcslen(pszText) > 24) |
---|
299 | return FALSE; |
---|
300 | CString sText = pszText; |
---|
301 | sText.Trim(); |
---|
302 | if(!sText.IsEmpty() && _tcschr(_T("Ll"), sText[sText.GetLength() - 1])) |
---|
303 | sText.Delete(sText.GetLength() - 1); |
---|
304 | if(sText.IsEmpty()) |
---|
305 | return FALSE; |
---|
306 | LONGLONG nLongLongResult; |
---|
307 | if(_tcsnicmp(sText, _T("0x"), 2) == 0) |
---|
308 | { |
---|
309 | SIZE_T nIndex = 2; |
---|
310 | for(; nIndex < (SIZE_T) sText.GetLength(); nIndex++) |
---|
311 | if(!_tcschr(_T("0123456789ABCDEFabcdef"), sText[nIndex])) |
---|
312 | return FALSE; |
---|
313 | if(!StrToInt64Ex(sText, STIF_SUPPORT_HEX, &nLongLongResult)) |
---|
314 | return FALSE; |
---|
315 | } else |
---|
316 | { |
---|
317 | SIZE_T nIndex = 0; |
---|
318 | if(sText[0] == _T('-')) |
---|
319 | nIndex++; |
---|
320 | for(; nIndex < (SIZE_T) sText.GetLength(); nIndex++) |
---|
321 | if(!_tcschr(_T("0123456789"), sText[nIndex])) |
---|
322 | return FALSE; |
---|
323 | nLongLongResult = _ttoi64(sText); |
---|
324 | } |
---|
325 | const LONG nHighLongLongResult = (LONG) (nLongLongResult >> 32); |
---|
326 | if(!nLongLongResult || nHighLongLongResult > 0 || nHighLongLongResult < -1) |
---|
327 | return FALSE; |
---|
328 | HRESULT nResult = (LONG) nLongLongResult; |
---|
329 | #pragma endregion |
---|
330 | #pragma region Lookup |
---|
331 | // NOTE: Include file regular expression replacement: ^.+?\#define +([^ ]+?) +MAKE_D3D.+\r?$ -> A($1) |
---|
332 | CString sTitle, sMessage, sIdentifier; |
---|
333 | if(IsQuartzResult(nResult, &sMessage)) |
---|
334 | { |
---|
335 | sTitle = _T("DirectShow"); |
---|
336 | sIdentifier = LookupQuartzIdentifier(nResult); |
---|
337 | } else if(IsWmResult(nResult, &sMessage)) |
---|
338 | sTitle = _T("Windows Media"); |
---|
339 | else if(IsMfResult(nResult, &sMessage)) |
---|
340 | { |
---|
341 | sTitle = _T("Media Foundation"); |
---|
342 | sIdentifier = LookupMfIdentifier(nResult); |
---|
343 | } else if(IsWs2Result(nResult, &sMessage)) |
---|
344 | sTitle = _T("Sockets"); |
---|
345 | else if(IsWinHttpResult(nResult, &sMessage)) |
---|
346 | sTitle = _T("WinHTTP"); |
---|
347 | else if(IsWinInetResult(nResult, &sMessage)) |
---|
348 | sTitle = _T("WinInet"); |
---|
349 | else if(IsD3dResult(nResult, &sMessage)) |
---|
350 | { |
---|
351 | sTitle = _T("DirectDraw/Direct3D"); |
---|
352 | sIdentifier = LookupD3dIdentifier(nResult); |
---|
353 | } else if(IsD2dResult(nResult, &sMessage)) |
---|
354 | { |
---|
355 | sTitle = _T("Direct2D"); |
---|
356 | sIdentifier = LookupD2dIdentifier(nResult); |
---|
357 | } else if(IsWicResult(nResult, &sMessage)) |
---|
358 | { |
---|
359 | sTitle = _T("WinCodec"); |
---|
360 | sIdentifier = LookupWicIdentifier(nResult); |
---|
361 | } else |
---|
362 | { |
---|
363 | sMessage = AtlFormatSystemMessage(nResult); |
---|
364 | sIdentifier = LookupSystemIdentifier(nResult); |
---|
365 | if(sIdentifier.IsEmpty()) |
---|
366 | sIdentifier = LookupHresultSystemIdentifier(nResult); |
---|
367 | if(!sMessage.IsEmpty() || !sIdentifier.IsEmpty()) |
---|
368 | sTitle = _T("System"); |
---|
369 | } |
---|
370 | if(sMessage.IsEmpty() && sTitle.IsEmpty()) |
---|
371 | return FALSE; |
---|
372 | #pragma endregion |
---|
373 | #pragma region Present |
---|
374 | _A(!sTitle.IsEmpty()); |
---|
375 | m_sQuery = AtlFormatString(_T("0x%08X"), nResult) + _T(" ") + sIdentifier + _T(" ") + sMessage; |
---|
376 | CRoArrayT<CString> TitleArray; |
---|
377 | _W(TitleArray.Add(AtlFormatString(_T("0x%08X"), nResult)) >= 0); |
---|
378 | if(!sIdentifier.IsEmpty()) |
---|
379 | _W(TitleArray.Add(sIdentifier) >= 0); |
---|
380 | if(!sTitle.IsEmpty()) |
---|
381 | _W(TitleArray.Add(sTitle) >= 0); |
---|
382 | if(sMessage.IsEmpty()) |
---|
383 | sMessage = _T("(no message found)"); |
---|
384 | SetBalloonToolTip(NIIF_INFO, _StringHelper::Join(TitleArray, _T(" - ")), sMessage); |
---|
385 | #pragma endregion |
---|
386 | return TRUE; |
---|
387 | } |
---|
388 | |
---|
389 | // Window message handelrs |
---|
390 | LRESULT OnCreate(CREATESTRUCT*) |
---|
391 | { |
---|
392 | m_nCommonControlsVersion = GetCommonControlsVersion(); |
---|
393 | m_nShellVersion = GetShellVersion(); |
---|
394 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE); |
---|
395 | SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE); |
---|
396 | CIcon Icon = AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); |
---|
397 | CString sTip = AtlLoadString(IDS_PROJNAME); |
---|
398 | ZeroMemory(&m_NotifyIconData, sizeof m_NotifyIconData); |
---|
399 | m_NotifyIconData.hWnd = m_hWnd; |
---|
400 | m_NotifyIconData.uID = 1; |
---|
401 | m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_STATE; |
---|
402 | m_NotifyIconData.uCallbackMessage = WM_NOTIFYICON; |
---|
403 | m_NotifyIconData.hIcon = Icon; |
---|
404 | _tcsncpy_s(m_NotifyIconData.szTip, sTip, _TRUNCATE); |
---|
405 | if(m_nShellVersion >= 0x0005000000000000) // 5.0 |
---|
406 | { |
---|
407 | m_NotifyIconData.cbSize = sizeof m_NotifyIconData; |
---|
408 | m_NotifyIconData.uFlags |= NIF_INFO; |
---|
409 | _tcsncpy_s(m_NotifyIconData.szInfoTitle, GetDefaultInfoTitle(), _TRUNCATE); |
---|
410 | m_NotifyIconData.dwInfoFlags = GetDefaultInfoFlags(); |
---|
411 | } else |
---|
412 | m_NotifyIconData.cbSize = NOTIFYICONDATA_V1_SIZE; |
---|
413 | _W(Shell_NotifyIcon(NIM_ADD, &m_NotifyIconData)); |
---|
414 | m_NotifyIconData.uFlags &= ~(NIF_ICON | NIF_STATE); |
---|
415 | m_NextClipboardViewerWindow = SetClipboardViewer(); |
---|
416 | _pAtlModule->Lock(); |
---|
417 | #if defined(_DEBUG) |
---|
418 | //Process(AtlFormatString(_T("%d"), 0x80040227)); // VFW_E_WRONG_STATE |
---|
419 | Process(_T("0xC00D36B9")); // MF_E_NO_MORE_TYPES) |
---|
420 | //Process(AtlFormatString(_T("0x%x"), HRESULT_FROM_WIN32(WSAEADDRINUSE))); // WSAEADDRINUSE |
---|
421 | //Process(AtlFormatString(_T("0x%x"), HRESULT_FROM_WIN32(ERROR_WINHTTP_AUTODETECTION_FAILED))); // ERROR_WINHTTP_AUTODETECTION_FAILED |
---|
422 | Process(_T("0x80290208L")); |
---|
423 | #endif // defined(_DEBUG) |
---|
424 | return TRUE; |
---|
425 | } |
---|
426 | LRESULT OnDestroy() throw() |
---|
427 | { |
---|
428 | _pAtlModule->Unlock(); |
---|
429 | _W(ChangeClipboardChain(m_NextClipboardViewerWindow)); |
---|
430 | _W(Shell_NotifyIcon(NIM_DELETE, &m_NotifyIconData)); |
---|
431 | m_NotifyIconData.hWnd = NULL; |
---|
432 | return 0; |
---|
433 | } |
---|
434 | LRESULT OnChangeCbChain(CWindow RemovedWindow, CWindow NextWindow) |
---|
435 | { |
---|
436 | if(m_NextClipboardViewerWindow == RemovedWindow) |
---|
437 | m_NextClipboardViewerWindow = NextWindow; |
---|
438 | else if(m_NextClipboardViewerWindow) |
---|
439 | m_NextClipboardViewerWindow.SendMessage(WM_CHANGECBCHAIN, (WPARAM) (HWND) RemovedWindow, (LPARAM) (HWND) NextWindow); |
---|
440 | return 0; |
---|
441 | } |
---|
442 | LRESULT OnDrawClipboard() |
---|
443 | { |
---|
444 | if(OpenClipboard()) |
---|
445 | { |
---|
446 | _ATLTRY |
---|
447 | { |
---|
448 | if(IsClipboardFormatAvailable(CF_UNICODETEXT)) |
---|
449 | { |
---|
450 | CGlobalMemoryWeakHandle DataHandle = (HGLOBAL) GetClipboardData(CF_UNICODETEXT); |
---|
451 | __E(DataHandle); |
---|
452 | CGlobalMemoryHandle::CLockT<WCHAR> pszData(DataHandle); |
---|
453 | Process(CW2CT(pszData)); |
---|
454 | } |
---|
455 | } |
---|
456 | _ATLCATCHALL() |
---|
457 | { |
---|
458 | _W(CloseClipboard()); |
---|
459 | _ATLRETHROW; |
---|
460 | } |
---|
461 | _W(CloseClipboard()); |
---|
462 | } |
---|
463 | return 0; |
---|
464 | } |
---|
465 | LRESULT OnMouseMove(UINT, CPoint) |
---|
466 | { |
---|
467 | return 0; |
---|
468 | } |
---|
469 | LRESULT OnLButtonDblClk(UINT, CPoint) |
---|
470 | { |
---|
471 | if(!IsWindowEnabled()) |
---|
472 | return 0; |
---|
473 | INT nDefaultCommandIdentifier = ID_APP_ABOUT; |
---|
474 | //CWaitCursor WaitCursor; |
---|
475 | if(nDefaultCommandIdentifier) |
---|
476 | _W(PostMessage(WM_COMMAND, nDefaultCommandIdentifier)); |
---|
477 | return 0; |
---|
478 | } |
---|
479 | LRESULT OnRButtonUp(UINT, CPoint) |
---|
480 | { |
---|
481 | CMenu ContainerMenu; |
---|
482 | _W(ContainerMenu.LoadMenu(IDR_NOTIFYICON)); |
---|
483 | CMenuHandle Menu; |
---|
484 | INT nDefaultCommandIdentifier = ID_APP_ABOUT; |
---|
485 | Menu = ContainerMenu.GetSubMenu(0); |
---|
486 | //CWaitCursor WaitCursor; |
---|
487 | _A(Menu); |
---|
488 | if(nDefaultCommandIdentifier) |
---|
489 | _W(Menu.SetMenuDefaultItem(nDefaultCommandIdentifier)); |
---|
490 | CPoint Position; |
---|
491 | GetCursorPos(&Position); |
---|
492 | _W(SetForegroundWindow(m_hWnd)); |
---|
493 | _W(Menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_VERTICAL, Position.x, Position.y, m_hWnd)); |
---|
494 | return 0; |
---|
495 | } |
---|
496 | LRESULT OnNotifyIconBalloonUserClick(UINT, WPARAM, LPARAM) |
---|
497 | { |
---|
498 | if(m_sQuery.IsEmpty()) |
---|
499 | return 0; |
---|
500 | CWinHttpRequestIdentifier Identifier(_T("http://google.com/search")); |
---|
501 | Identifier.AddSearchValue(_T("q"), m_sQuery); |
---|
502 | CWaitCursor WaitCursor; |
---|
503 | ShellExecute(m_hWnd, NULL, CW2CT(Identifier.GetValue()), NULL, NULL, SW_SHOWDEFAULT); |
---|
504 | return 0; |
---|
505 | } |
---|
506 | LRESULT OnNotifyIcon(UINT uMsg, WPARAM wParam, LPARAM lParam) throw() |
---|
507 | { |
---|
508 | _A(wParam == m_NotifyIconData.uID); |
---|
509 | return SendMessage((UINT) lParam); |
---|
510 | } |
---|
511 | LRESULT OnApplicationAbout(UINT, INT, HWND) throw() |
---|
512 | { |
---|
513 | CAboutDialog Dialog; |
---|
514 | EnableWindow(FALSE); |
---|
515 | Dialog.DoModal(); |
---|
516 | EnableWindow(TRUE); |
---|
517 | return 0; |
---|
518 | } |
---|
519 | LRESULT OnApplicationExit(UINT = 0, INT = ID_APP_EXIT, HWND = NULL) throw() |
---|
520 | { |
---|
521 | PostQuitMessage(0); |
---|
522 | return 0; |
---|
523 | } |
---|
524 | }; |
---|