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