BOOL MainDialog::ShowIcon() { if (!m_bInstalled) return false; BOOL bResult = TRUE; if (m_bHidden) { if (GetShellVersion() >= 5) //use the Shell v5 way of showing the icon { #if (_WIN32_IE >= 0x0500) m_niData.uFlags = NIF_STATE; m_niData.dwState = 0; m_niData.dwStateMask = NIS_HIDDEN; bResult = Shell_NotifyIcon(NIM_MODIFY, &m_niData) ? TRUE : false; #endif } else { m_niData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; bResult = Shell_NotifyIcon(NIM_ADD, &m_niData) ? TRUE : false; } if (bResult) { m_bHidden = false; } } return bResult; }
Tray::Tray( void ) { memset(¬ify_icon_data_, 0, sizeof(notify_icon_data_)); DWORD shell_version = GetShellVersion(); shell_major_version_ = HIWORD(shell_version); shell_minor_version_ = LOWORD(shell_version); }
BOOL CTrayNotifyIcon::SetTooltipText(LPCTSTR pszTooltipText) { if (!m_bCreated) return FALSE; if (GetShellVersion() >= 5) //Allow the larger size tooltip text if on Shell v5 or later { #ifdef _DEBUG NOTIFYICONDATA_2 dummy; DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); #endif } else { #ifdef _DEBUG NOTIFYICONDATA_1 dummy; ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); #endif } //Call the Shell_NotifyIcon function m_NotifyIconData.uFlags = NIF_TIP; #if (_MSC_VER >= 1400) _tcscpy_s(m_NotifyIconData.szTip, sizeof(m_NotifyIconData.szTip)/sizeof(TCHAR), pszTooltipText); #else _tcscpy(m_NotifyIconData.szTip, pszTooltipText); #endif return Shell_NotifyIcon(NIM_MODIFY, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); }
BOOL CTrayNotifyIcon::SetFocus() { ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or greater //Call the Shell_NotifyIcon function return Shell_NotifyIcon(NIM_SETFOCUS, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); }
BOOL MainDialog::HideIcon(void) { if (!m_bInstalled) return false; BOOL bResult = TRUE; if (!m_bHidden) { if (GetShellVersion() >= 5) //use the Shell v5 way of hiding the icon { #if (_WIN32_IE >= 0x0500) m_niData.uFlags = NIF_STATE; m_niData.dwState = NIS_HIDDEN; m_niData.dwStateMask = NIS_HIDDEN; #endif bResult = Shell_NotifyIcon(NIM_MODIFY, &m_niData) ? TRUE : false; } else { m_niData.uFlags = 0; bResult = Shell_NotifyIcon(NIM_DELETE, &m_niData) ? TRUE : false; } if (bResult) { m_bHidden = TRUE; } } return bResult; }
BOOL CTrayNotifyIcon::SetVersion(UINT uVersion) { //Validate our parameters ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later //Call the Shell_NotifyIcon function m_NotifyIconData.uVersion = uVersion; return Shell_NotifyIcon(NIM_SETVERSION, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); }
DWORD CTrayNotifyIcon::GetNOTIFYICONDATASizeForOS() { DWORD dwVersion = GetShellVersion(); if (dwVersion >= 6) return sizeof(NOTIFYICONDATA_3); else if (dwVersion >= 5) return sizeof(NOTIFYICONDATA_2); else return sizeof(NOTIFYICONDATA_1); }
UINT CTrayNotifyIcon::GetBalloonTimeout() const { //Validate our parameters ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later UINT nTimeout = 0; if (m_bCreated) nTimeout = m_NotifyIconData.uTimeout; return nTimeout; }
BOOL MainDialog::SetVersion(UINT uVersion) { ATLASSERT(GetShellVersion() >= 5); m_niData.uVersion = uVersion; #if (_WIN32_IE >= 0x0500) return Shell_NotifyIcon(NIM_SETVERSION, &m_niData) ? TRUE : false; #else return FALSE; #endif }
CTrayNotifyIconString CTrayNotifyIcon::GetBalloonCaption() const { //Validate our parameters ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later CTrayNotifyIconString sText; if (m_bCreated) sText = m_NotifyIconData.szInfoTitle; return sText; }
BOOL MainDialog::SetBalloonDetails(LPCTSTR pszBalloonText, LPCTSTR pszBalloonCaption, BalloonStyle style /*= BALLOON_INFO*/, UINT nTimeout /*= 1000*/, HICON hUserIcon /*= NULL*/, BOOL bNoSound /*= FALSE*/) { if (!m_bInstalled) return false; ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later #if (_WIN32_IE >= 0x0500) m_niData.uFlags = NIF_INFO; #endif #if (_MSC_VER >= 1400) _tcscpy_s(m_niData.szInfo, sizeof(m_niData.szInfo) / sizeof(TCHAR), pszBalloonText); _tcscpy_s(m_niData.szInfoTitle, sizeof(m_niData.szInfoTitle) / sizeof(TCHAR), pszBalloonCaption); #else _tcscpy(m_niData.szInfo, pszBalloonText); _tcscpy(m_niData.szInfoTitle, pszBalloonCaption); #endif m_niData.uTimeout = nTimeout; #if (_WIN32_IE >= 0x0500) switch (style) { case BALLOON_WARNING: m_niData.dwInfoFlags = NIIF_WARNING; break; case BALLOON_ERROR: m_niData.dwInfoFlags = NIIF_ERROR; break; case BALLOON_INFO: m_niData.dwInfoFlags = NIIF_INFO; break; case BALLOON_NONE: m_niData.dwInfoFlags = NIIF_NONE; break; #if (_WIN32_IE >= 0x0600) case BALLOON_USER: ATLASSERT(hUserIcon != NULL); m_niData.dwInfoFlags = NIIF_USER; m_niData.hIcon = hUserIcon; break; #endif default: ATLASSERT(FALSE); break; } #endif #if (_WIN32_IE >= 0x0501) if (bNoSound) m_niData.dwInfoFlags |= NIIF_NOSOUND; #endif return Shell_NotifyIcon(NIM_MODIFY, &m_niData) ? TRUE : false; }
BOOL CTrayNotifyIcon::Hide() { //Validate our parameters ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later ATLASSERT(!m_bHidden); //Only makes sense to hide the icon if it is not already hidden m_NotifyIconData.uFlags = NIF_STATE; m_NotifyIconData.dwState = NIS_HIDDEN; m_NotifyIconData.dwStateMask = NIS_HIDDEN; BOOL bSuccess = Shell_NotifyIcon(NIM_MODIFY, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); if (bSuccess) m_bHidden = TRUE; return bSuccess; }
BOOL CTrayNotifyIcon::Show() { //Validate our parameters ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later ATLASSERT(m_bHidden); //Only makes sense to show the icon if it has been previously hidden ATLASSERT(m_bCreated); m_NotifyIconData.uFlags = NIF_STATE; m_NotifyIconData.dwState = 0; m_NotifyIconData.dwStateMask = NIS_HIDDEN; BOOL bSuccess = Shell_NotifyIcon(NIM_MODIFY, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); if (bSuccess) m_bHidden = FALSE; return bSuccess; }
void CMainFrame::pShowWelcome() { // // We use different message based on the version of the shell, // as NIN_BALLOONUSERCLICK is only available in shell 6.0 (Windows XP) or later // UINT nMsgId = (GetShellVersion() >= PackVersion(6,0)) ? IDS_NDASMGMT_WELCOME_TOOLTIP : IDS_NDASMGMT_WELCOME_TOOLTIP_SHELL50; m_taskbarIcon.ShowBalloonToolTip( nMsgId, IDS_NDASMGMT_WELCOME_TITLE, NIIF_INFO, 30 * 1000); m_curBalloonType = FirstRunBalloon; }
LONG GetShellVersion( void ) { DWORD dwMajor = 0, dwMinor = 0; GetShellVersion(&dwMajor, &dwMinor); return MAKELONG(dwMajor, dwMinor); }
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*cmdShow*/) { SetDllDirectory(L""); CAutoGeneralHandle hReloadProtection = ::CreateMutex(NULL, FALSE, GetCacheMutexName()); if ((!hReloadProtection) || (GetLastError() == ERROR_ALREADY_EXISTS)) { // An instance of TGitCache is already running ATLTRACE("TGitCache ignoring restart\n"); return 0; } CGitStatusCache::Create(); CGitStatusCache::Instance().Init(); SecureZeroMemory(szCurrentCrawledPath, sizeof(szCurrentCrawledPath)); DWORD dwThreadId; MSG msg; TCHAR szWindowClass[] = {TGIT_CACHE_WINDOW_NAME}; // create a hidden window to receive window messages. WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = 0; wcex.hbrBackground = 0; wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = 0; RegisterClassEx(&wcex); hWnd = CreateWindow(TGIT_CACHE_WINDOW_NAME, TGIT_CACHE_WINDOW_NAME, WS_CAPTION, 0, 0, 800, 300, NULL, 0, hInstance, 0); hTrayWnd = hWnd; if (hWnd == NULL) { return 0; } if (CRegStdDWORD(_T("Software\\TortoiseGit\\CacheTrayIcon"), FALSE)==TRUE) { SecureZeroMemory(&niData,sizeof(NOTIFYICONDATA)); DWORD dwMajor = 0; DWORD dwMinor = 0; GetShellVersion(&dwMajor, &dwMinor); DWORD dwVersion = PACKVERSION(dwMajor, dwMinor); if (dwVersion >= PACKVERSION(6,0)) niData.cbSize = sizeof(NOTIFYICONDATA); else if (dwVersion >= PACKVERSION(5,0)) niData.cbSize = NOTIFYICONDATA_V2_SIZE; else niData.cbSize = NOTIFYICONDATA_V1_SIZE; niData.uID = TRAY_ID; // own tray icon ID niData.hWnd = hWnd; niData.uFlags = NIF_ICON|NIF_MESSAGE; // load the icon niData.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_TGITCACHE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); // set the message to send // note: the message value should be in the // range of WM_APP through 0xBFFF niData.uCallbackMessage = TRAY_CALLBACK; Shell_NotifyIcon(NIM_ADD,&niData); // free icon handle if(niData.hIcon && DestroyIcon(niData.hIcon)) niData.hIcon = NULL; } // Create a thread which waits for incoming pipe connections CAutoGeneralHandle hPipeThread = CreateThread( NULL, // no security attribute 0, // default stack size PipeThread, (LPVOID) &bRun, // thread parameter 0, // not suspended &dwThreadId); // returns thread ID if (!hPipeThread) { //OutputDebugStringA("TSVNCache: Could not create pipe thread\n"); //DebugOutputLastError(); return 0; } else hPipeThread.CloseHandle(); // Create a thread which waits for incoming pipe connections CAutoGeneralHandle hCommandWaitThread = CreateThread( NULL, // no security attribute 0, // default stack size CommandWaitThread, (LPVOID) &bRun, // thread parameter 0, // not suspended &dwThreadId); // returns thread ID if (!hCommandWaitThread) { //OutputDebugStringA("TSVNCache: Could not create command wait thread\n"); //DebugOutputLastError(); return 0; } // loop to handle window messages. BOOL bLoopRet; while (bRun) { bLoopRet = GetMessage(&msg, NULL, 0, 0); if ((bLoopRet != -1)&&(bLoopRet != 0)) { DispatchMessage(&msg); } } bRun = false; Shell_NotifyIcon(NIM_DELETE,&niData); CGitStatusCache::Destroy(); return 0; }
LRESULT CMainFrame::OnCreate(LPCREATESTRUCT lParam) { NdasUiDbgCall( 2, _T("m_hWnd = %p\n"), m_hWnd ); m_AutoPnpMutex = CreateSemaphore( NULL, 1, 1, NULL ); if (m_AutoPnpMutex == NULL) { ATLASSERT(m_AutoPnpMutex); } else { for (UINT i=0; i<NDAS_MAX_AUTO_PNP; i++) { m_NdasStringId[i] = (PTCHAR)::HeapAlloc( ::GetProcessHeap(), HEAP_ZERO_MEMORY, (NDAS_DEVICE_STRING_ID_LEN + 1) * sizeof(TCHAR) ); if (m_NdasStringId[i] == NULL) { ATLASSERT(FALSE); } } m_NdasStringIdLen = 0; } xTaskDialogInitialize(); #ifdef NDASMGMT_USE_QUERYCANCELAUTOPLAY WM_QUERYCANCELAUTOPLAY = ::RegisterWindowMessage(_T("QueryCancelAutoplay")); ATLASSERT(WM_QUERYCANCELAUTOPLAY); #endif int cxSmall = ::GetSystemMetrics(SM_CXSMICON); int cySmall = ::GetSystemMetrics(SM_CYSMICON); int cxLarge = ::GetSystemMetrics(SM_CXICON); int cyLarge = ::GetSystemMetrics(SM_CYICON); HICON hAppIcon = AtlLoadIconImage( IDR_MAINFRAME, LR_DEFAULTCOLOR | LR_DEFAULTSIZE, cxLarge, cyLarge); HICON hAppIconSmall = AtlLoadIconImage( IDR_MAINFRAME, LR_DEFAULTCOLOR | LR_DEFAULTSIZE, cxSmall, cySmall); ATLASSERT(hAppIcon && hAppIconSmall); SetIcon(hAppIcon, TRUE); SetIcon(hAppIconSmall, FALSE); m_hTaskbarDefaultMenu.LoadMenu(IDR_TASKBAR); m_taskbarIcon.Install(m_hWnd, 1, IDR_TASKBAR); // Create Task Bar Icon Image List // Only shell 6.0 or later can handle ILC_COLOR32 DWORD imageListFlags = ILC_MASK; imageListFlags |= (GetShellVersion() >= PackVersion(6,0)) ? ILC_COLOR32 : ILC_COLOR8; ATLVERIFY(m_taskbarImageList.Create(cxSmall, cySmall, imageListFlags , 2, 1)); ATLVERIFY(m_hTaskbarIconBase = AtlLoadIconImage(IDR_TASKBAR, LR_DEFAULTCOLOR, cxSmall, cySmall)); ATLVERIFY(m_hTaskbarFailOverlay = AtlLoadIconImage(IDR_TASKBAR_FAIL, LR_DEFAULTCOLOR, cxSmall, cySmall)); m_nTaskbarNormal = m_taskbarImageList.AddIcon(m_hTaskbarIconBase); m_nTaskbarFailureOverlay = m_taskbarImageList.AddIcon(m_hTaskbarFailOverlay); ATLVERIFY(m_taskbarImageList.SetOverlayImage(m_nTaskbarFailureOverlay, 1)); pUpdateDeviceList(); pUpdateMenuItems(); if (pGetAppConfigBOOL(_T("UseHotKey"), FALSE)) { NDASMGMT_POPUP_HOTKEY = ::GlobalAddAtom(ndasmgmt::NDASMGMT_ATOM_HOTKEY); ATLASSERT(NDASMGMT_POPUP_HOTKEY >= 0xC000 && NDASMGMT_POPUP_HOTKEY <= 0xFFFF); BOOL fSuccess = ::RegisterHotKey( m_hWnd, NDASMGMT_POPUP_HOTKEY, MOD_WIN, 'N' /* VK_N */); if (fSuccess) { m_fHotKeyRegistered = TRUE; } else { ATLVERIFY(0 == ::GlobalDeleteAtom(static_cast<ATOM>(NDASMGMT_POPUP_HOTKEY))); NDASMGMT_POPUP_HOTKEY = 0xFFFF; } } if (pGetAppConfigBOOL(_T("FirstRun"), TRUE)) { pShowWelcome(); ATLVERIFY(pSetAppConfigValueBOOL(_T("FirstRun"), FALSE)); } m_taskbarMenu.Init(m_hWnd); ATLVERIFY(m_bitmapHandler.Initialize()); // Subscribe NDAS Event ATLVERIFY(NdasEventSubscribe(m_hWnd)); NdasUiDbgCall( 2, "out\n" ); return 0; }
LRESULT CMainFrame::OnCreate(LPCREATESTRUCT lParam) { #ifdef NDASMGMT_USE_QUERYCANCELAUTOPLAY WM_QUERYCANCELAUTOPLAY = ::RegisterWindowMessage(_T("QueryCancelAutoplay")); ATLASSERT(WM_QUERYCANCELAUTOPLAY); #endif int cxSmall = ::GetSystemMetrics(SM_CXSMICON); int cySmall = ::GetSystemMetrics(SM_CYSMICON); int cxLarge = ::GetSystemMetrics(SM_CXICON); int cyLarge = ::GetSystemMetrics(SM_CYICON); HICON hAppIcon = AtlLoadIconImage( IDR_MAINFRAME, LR_DEFAULTCOLOR | LR_DEFAULTSIZE, cxLarge, cyLarge); HICON hAppIconSmall = AtlLoadIconImage( IDR_MAINFRAME, LR_DEFAULTCOLOR | LR_DEFAULTSIZE, cxSmall, cySmall); ATLASSERT(hAppIcon && hAppIconSmall); SetIcon(hAppIcon, TRUE); SetIcon(hAppIconSmall, FALSE); m_hTaskbarDefaultMenu.LoadMenu(IDR_TASKBAR); m_taskbarIcon.Install(m_hWnd, 1, IDR_TASKBAR); // Create Task Bar Icon Image List // Only shell 6.0 or later can handle ILC_COLOR32 DWORD imageListFlags = ILC_MASK; imageListFlags |= (GetShellVersion() >= PackVersion(6,0)) ? ILC_COLOR32 : ILC_COLOR8; ATLVERIFY(m_taskbarImageList.Create(cxSmall, cySmall, imageListFlags , 2, 1)); ATLVERIFY(m_hTaskbarIconBase = AtlLoadIconImage(IDR_TASKBAR, LR_DEFAULTCOLOR, cxSmall, cySmall)); ATLVERIFY(m_hTaskbarFailOverlay = AtlLoadIconImage(IDR_TASKBAR_FAIL, LR_DEFAULTCOLOR, cxSmall, cySmall)); m_nTaskbarNormal = m_taskbarImageList.AddIcon(m_hTaskbarIconBase); m_nTaskbarFailureOverlay = m_taskbarImageList.AddIcon(m_hTaskbarFailOverlay); ATLVERIFY(m_taskbarImageList.SetOverlayImage(m_nTaskbarFailureOverlay, 1)); _UpdateDeviceList(); _UpdateMenuItems(); if (pGetAppConfigBOOL(_T("UseHotKey"), FALSE)) { NDASMGMT_POPUP_HOTKEY = ::GlobalAddAtom(ndasmgmt::NDASMGMT_ATOM_HOTKEY); ATLASSERT(NDASMGMT_POPUP_HOTKEY >= 0xC000 && NDASMGMT_POPUP_HOTKEY <= 0xFFFF); BOOL fSuccess = ::RegisterHotKey( m_hWnd, NDASMGMT_POPUP_HOTKEY, MOD_WIN, 'N' /* VK_N */); if (fSuccess) { m_fHotKeyRegistered = TRUE; } else { ATLVERIFY(0 == ::GlobalDeleteAtom(static_cast<ATOM>(NDASMGMT_POPUP_HOTKEY))); NDASMGMT_POPUP_HOTKEY = 0xFFFF; } } if (pGetAppConfigBOOL(_T("FirstRun"), TRUE)) { _ShowWelcome(); ATLVERIFY(pSetAppConfigValueBOOL(_T("FirstRun"), FALSE)); } ATLVERIFY(m_bitmapHandler.Initialize()); // Subscribe NDAS Event ATLVERIFY(NdasEventSubscribe(m_hWnd)); return 0; }
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*cmdShow*/) { SetDllDirectory(L""); CAutoGeneralHandle hReloadProtection = ::CreateMutex(NULL, FALSE, GetCacheMutexName()); if ((!hReloadProtection) || (GetLastError() == ERROR_ALREADY_EXISTS)) { // An instance of TSVNCache is already running CTraceToOutputDebugString::Instance()(__FUNCTION__ ": TSVNCache ignoring restart\n"); return 0; } // set the current directory to the users temp dir TCHAR pathbuf[MAX_PATH] = { 0 }; GetTempPath(_countof(pathbuf), pathbuf); SetCurrentDirectory(pathbuf); apr_initialize(); svn_dso_initialize2(); svn_error_set_malfunction_handler(svn_error_handle_malfunction); g_SVNAdminDir.Init(); CSVNStatusCache::Create(); CSVNStatusCache::Instance().Init(); SecureZeroMemory(szCurrentCrawledPath, sizeof(szCurrentCrawledPath)); // create a hidden window to receive window messages. hWndHidden = CreateHiddenWindow(hInstance); hTrayWnd = hWndHidden; if (hWndHidden == NULL) { return 0; } if (CRegStdDWORD(L"Software\\TortoiseSVN\\CacheTrayIcon", FALSE)==TRUE) { SecureZeroMemory(&niData,sizeof(NOTIFYICONDATA)); DWORD dwMajor = 0; DWORD dwMinor = 0; GetShellVersion(&dwMajor, &dwMinor); DWORD dwVersion = PACKVERSION(dwMajor, dwMinor); if (dwVersion >= PACKVERSION(6,0)) niData.cbSize = sizeof(NOTIFYICONDATA); else if (dwVersion >= PACKVERSION(5,0)) niData.cbSize = NOTIFYICONDATA_V2_SIZE; else niData.cbSize = NOTIFYICONDATA_V1_SIZE; niData.uID = TRAY_ID; // own tray icon ID niData.hWnd = hWndHidden; niData.uFlags = NIF_ICON|NIF_MESSAGE; // load the icon niData.hIcon = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_TSVNCACHE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); // set the message to send // note: the message value should be in the // range of WM_APP through 0xBFFF niData.uCallbackMessage = TRAY_CALLBACK; Shell_NotifyIcon(NIM_ADD,&niData); // free icon handle if(niData.hIcon && DestroyIcon(niData.hIcon)) niData.hIcon = NULL; } // Create a thread which waits for incoming pipe connections unsigned int threadId = 0; CAutoGeneralHandle hPipeThread = (HANDLE)_beginthreadex(NULL, 0, PipeThread, &bRun, 0, &threadId); if (!hPipeThread) return 0; // Create a thread which waits for incoming pipe connections CAutoGeneralHandle hCommandWaitThread = (HANDLE)_beginthreadex(NULL, 0, CommandWaitThread, &bRun, 0, &threadId); if (hCommandWaitThread) { // loop to handle window messages. MSG msg; while (bRun) { const BOOL bLoopRet = GetMessage(&msg, NULL, 0, 0); if ((bLoopRet != -1)&&(bLoopRet != 0)) { DispatchMessage(&msg); } } } bRun = false; Shell_NotifyIcon(NIM_DELETE,&niData); CSVNStatusCache::Destroy(); g_SVNAdminDir.Close(); apr_terminate(); return 0; }
BOOL CTrayNotifyIcon::Create(CWindow* pNotifyWnd, UINT uID, LPCTSTR pszTooltipText, HICON hIcon, UINT nNotifyMessage, UINT uMenuID) #endif { //Validate our parameters ATLASSERT(pNotifyWnd && ::IsWindow(pNotifyWnd->operator HWND())); #ifdef _DEBUG if (GetShellVersion() >= 5) //If on Shell v5 or higher, then use the larger size tooltip { NOTIFYICONDATA_2 dummy; ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); } else { NOTIFYICONDATA_1 dummy; ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); } #endif ATLASSERT(hIcon); ATLASSERT(nNotifyMessage >= WM_USER); //Make sure we avoid conflict with other messages //Load up the menu resource which is to be used as the context menu if (!m_Menu.LoadMenu(uMenuID == 0 ? uID : uMenuID)) { ATLASSERT(FALSE); return FALSE; } #ifdef _AFX CMenu* pSubMenu = m_Menu.GetSubMenu(0); if (!pSubMenu) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } //Make the specified menu item the default (bold font) pSubMenu->SetDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #else CMenuHandle subMenu = m_Menu.GetSubMenu(0); if (!subMenu.IsMenu()) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } subMenu.SetMenuDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #endif //Install the hook if (!m_HookWnd.Init(this, pNotifyWnd)) return FALSE; //Call the Shell_NotifyIcon function m_pNotificationWnd = pNotifyWnd; m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; m_NotifyIconData.hWnd = pNotifyWnd->operator HWND(); m_NotifyIconData.uID = uID; m_NotifyIconData.uCallbackMessage = nNotifyMessage; m_NotifyIconData.hIcon = hIcon; #if (_MSC_VER >= 1400) _tcscpy_s(m_NotifyIconData.szTip, sizeof(m_NotifyIconData.szTip)/sizeof(TCHAR), pszTooltipText); #else _tcscpy(m_NotifyIconData.szTip, pszTooltipText); #endif m_bCreated = Shell_NotifyIcon(NIM_ADD, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); //Turn on Shell v5 style behaviour if supported if (GetShellVersion() >= 5) SetVersion(NOTIFYICON_VERSION); return m_bCreated; }
BOOL CTrayNotifyIcon::Create(CWindow* pNotifyWnd, UINT uID, LPCTSTR pszTooltipText, LPCTSTR pszBalloonText, LPCTSTR pszBalloonCaption, UINT nTimeout, BalloonStyle style, HICON hIcon, UINT nNotifyMessage, UINT uMenuID, BOOL bNoSound) #endif { //Validate our parameters ATLASSERT(pNotifyWnd && ::IsWindow(pNotifyWnd->operator HWND())); ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later #ifdef _DEBUG NOTIFYICONDATA_2 dummy; DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); ATLASSERT(_tcslen(pszTooltipText) < sizeof(dummy.szTip)/sizeof(TCHAR)); ATLASSERT(_tcslen(pszBalloonText) < sizeof(dummy.szInfo)/sizeof(TCHAR)); ATLASSERT(_tcslen(pszBalloonCaption) < sizeof(dummy.szInfoTitle)/sizeof(TCHAR)); ATLASSERT(hIcon); ATLASSERT(nNotifyMessage >= WM_USER); //Make sure we avoid conflict with other messages #endif //Load up the menu resource which is to be used as the context menu if (!m_Menu.LoadMenu(uMenuID == 0 ? uID : uMenuID)) { ATLASSERT(FALSE); return FALSE; } #ifdef _AFX CMenu* pSubMenu = m_Menu.GetSubMenu(0); if (!pSubMenu) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } //Make the specified menu item the default (bold font) pSubMenu->SetDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #else CMenuHandle subMenu = m_Menu.GetSubMenu(0); if (!subMenu.IsMenu()) { ATLASSERT(FALSE); //Your menu resource has been designed incorrectly return FALSE; } //Make the specified menu item the default (bold font) subMenu.SetMenuDefaultItem(m_nDefaultMenuItem, m_bDefaultMenuItemByPos); #endif //Install the hook if (!m_HookWnd.Init(this, pNotifyWnd)) return FALSE; //Call the Shell_NotifyIcon function m_pNotificationWnd = pNotifyWnd; m_NotifyIconData.hWnd = pNotifyWnd->operator HWND(); m_NotifyIconData.uID = uID; m_NotifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO; m_NotifyIconData.uCallbackMessage = nNotifyMessage; m_NotifyIconData.hIcon = hIcon; #if (_MSC_VER >= 1400) _tcscpy_s(m_NotifyIconData.szTip, sizeof(m_NotifyIconData.szTip)/sizeof(TCHAR), pszTooltipText); _tcscpy_s(m_NotifyIconData.szInfo, sizeof(m_NotifyIconData.szInfo)/sizeof(TCHAR), pszBalloonText); _tcscpy_s(m_NotifyIconData.szInfoTitle, sizeof(m_NotifyIconData.szInfoTitle)/sizeof(TCHAR), pszBalloonCaption); #else _tcscpy(m_NotifyIconData.szTip, pszTooltipText); _tcscpy(m_NotifyIconData.szInfo, pszBalloonText); _tcscpy(m_NotifyIconData.szInfoTitle, pszBalloonCaption); #endif m_NotifyIconData.uTimeout = nTimeout; switch (style) { case Warning: { m_NotifyIconData.dwInfoFlags = NIIF_WARNING; break; } case Error: { m_NotifyIconData.dwInfoFlags = NIIF_ERROR; break; } case Info: { m_NotifyIconData.dwInfoFlags = NIIF_INFO; break; } case None: { m_NotifyIconData.dwInfoFlags = NIIF_NONE; break; } case User: { ATLASSERT(hIcon != NULL); //You forget to provide a user icon m_NotifyIconData.dwInfoFlags = NIIF_USER; break; } default: { ATLASSERT(FALSE); break; } } if (bNoSound) m_NotifyIconData.dwInfoFlags |= NIIF_NOSOUND; m_bCreated = Shell_NotifyIcon(NIM_ADD, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); //Turn on Shell v5 tray icon behaviour SetVersion(NOTIFYICON_VERSION); return m_bCreated; }
BOOL CTrayNotifyIcon::SetBalloonDetails(LPCTSTR pszBalloonText, LPCTSTR pszBalloonCaption, BalloonStyle style, UINT nTimeout, HICON hUserIcon, BOOL bNoSound) { if (!m_bCreated) return FALSE; //Validate our parameters ATLASSERT(GetShellVersion() >= 5); //Only supported on Shell v5 or later #ifdef _DEBUG NOTIFYICONDATA_2 dummy; DBG_UNREFERENCED_LOCAL_VARIABLE(dummy); ATLASSERT(_tcslen(pszBalloonText) < sizeof(dummy.szInfo)/sizeof(TCHAR)); ATLASSERT(_tcslen(pszBalloonCaption) < sizeof(dummy.szInfoTitle)/sizeof(TCHAR)); #endif //Call the Shell_NotifyIcon function m_NotifyIconData.uFlags = NIF_INFO; #if (_MSC_VER >= 1400) _tcscpy_s(m_NotifyIconData.szInfo, sizeof(m_NotifyIconData.szInfo)/sizeof(TCHAR), pszBalloonText); _tcscpy_s(m_NotifyIconData.szInfoTitle, sizeof(m_NotifyIconData.szInfoTitle)/sizeof(TCHAR), pszBalloonCaption); #else _tcscpy(m_NotifyIconData.szInfo, pszBalloonText); _tcscpy(m_NotifyIconData.szInfoTitle, pszBalloonCaption); #endif m_NotifyIconData.uTimeout = nTimeout; switch (style) { case Warning: { m_NotifyIconData.dwInfoFlags = NIIF_WARNING; break; } case Error: { m_NotifyIconData.dwInfoFlags = NIIF_ERROR; break; } case Info: { m_NotifyIconData.dwInfoFlags = NIIF_INFO; break; } case None: { m_NotifyIconData.dwInfoFlags = NIIF_NONE; break; } case User: { ATLASSERT(hUserIcon != NULL); //You forget to provide a user icon m_NotifyIconData.dwInfoFlags = NIIF_USER; m_NotifyIconData.hIcon = hUserIcon; break; } default: { ATLASSERT(FALSE); break; } } if (bNoSound) m_NotifyIconData.dwInfoFlags |= NIIF_NOSOUND; return Shell_NotifyIcon(NIM_MODIFY, reinterpret_cast<PNOTIFYICONDATA>(&m_NotifyIconData)); }