source: trunk/Utilities/ShowHresult/NotifyIconWindow.h @ 146

Last change on this file since 146 was 146, checked in by roman, 11 years ago

Added FACILITY_AUDCLNT

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