Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
4.8 KiB

  1. // SAFInciTrayIcon.cpp: implementation of the CSAFInciTrayIcon class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "SAFInciTrayIcon.h"
  6. //////////////////////////////////////////////////////////////////////
  7. // Construction/Destruction
  8. //////////////////////////////////////////////////////////////////////
  9. const UINT CSAFInciTrayIcon::WM_TASKBARCREATED = ::RegisterWindowMessage(_T("TaskbarCreated"));
  10. DWORD CSAFInciTrayIcon::dwThreadId = 0;
  11. BOOL CSAFInciTrayIcon::m_bVisible = FALSE;
  12. NOTIFYICONDATA CSAFInciTrayIcon::m_tnd;
  13. #define CHANNEL_PATH TEXT("\\PCHEALTH\\HelpCtr\\Binaries\\HelpCtr.exe -FromStartHelp -Url \"hcp://CN=Microsoft Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance")
  14. #define ID_SAFINCIDENT_ICON 1
  15. const TCHAR cstrToolTip[] = _T("Remote Assistance - %d tickets");
  16. CSAFInciTrayIcon::CSAFInciTrayIcon(UINT &nRefCount):m_nRefCount(nRefCount)
  17. {
  18. m_wIconId = IDI_NORMALINCIDENT;
  19. }
  20. BOOL CSAFInciTrayIcon::RemoveTrayIcon()
  21. {
  22. m_tnd.uFlags = 0;
  23. if (m_bVisible == TRUE)
  24. {
  25. if (Shell_NotifyIcon(NIM_DELETE, &m_tnd))
  26. m_bVisible = FALSE;
  27. }
  28. return m_bVisible;
  29. }
  30. BOOL CSAFInciTrayIcon::AddTrayIcon()
  31. {
  32. ZeroMemory(&m_tnd, sizeof(m_tnd));
  33. m_tnd.cbSize = sizeof(NOTIFYICONDATA);
  34. m_tnd.hWnd = m_hWnd;
  35. m_tnd.uID = ID_SAFINCIDENT_ICON;
  36. m_tnd.hIcon = ::LoadIcon(_Module.m_hInst, (LPCWSTR)m_wIconId);
  37. m_tnd.uCallbackMessage = WM_ICON_NOTIFY;
  38. m_tnd.uFlags = NIF_MESSAGE | NIF_ICON ;
  39. if (m_nRefCount)
  40. {
  41. m_tnd.uFlags |= NIF_TIP;
  42. TCHAR strbuf[64] = _T("");
  43. wsprintf(strbuf,cstrToolTip,m_nRefCount);
  44. _tcsncpy(m_tnd.szTip, strbuf, 64);
  45. }
  46. m_bVisible = Shell_NotifyIcon(NIM_ADD, &m_tnd);
  47. m_tnd.uFlags = 0;
  48. m_tnd.uVersion = NOTIFYICON_VERSION;
  49. if (m_bVisible == TRUE)
  50. {
  51. Shell_NotifyIcon(NIM_SETVERSION, &m_tnd);
  52. }
  53. return m_bVisible;
  54. }
  55. BOOL CSAFInciTrayIcon::ChangeToolTip()
  56. {
  57. NOTIFYICONDATA IconData = {0};
  58. IconData.cbSize = sizeof(NOTIFYICONDATA);
  59. IconData.hWnd = m_hWnd;
  60. IconData.uID = ID_SAFINCIDENT_ICON;
  61. if (m_nRefCount)
  62. {
  63. IconData.uFlags = NIF_TIP;
  64. TCHAR strbuf[64] = _T("");
  65. wsprintf(strbuf,cstrToolTip,m_nRefCount);
  66. _tcsncpy(IconData.szTip, strbuf, 64);
  67. Shell_NotifyIcon(NIM_MODIFY, &IconData);
  68. }
  69. return TRUE;
  70. }
  71. BOOL CSAFInciTrayIcon::ModifyIcon()
  72. {
  73. NOTIFYICONDATA IconData = {0};
  74. IconData.cbSize = sizeof(NOTIFYICONDATA);
  75. IconData.hWnd = m_hWnd;
  76. IconData.uID = ID_SAFINCIDENT_ICON;
  77. IconData.hIcon = ::LoadIcon(_Module.m_hInst, (LPCWSTR)m_wIconId);
  78. IconData.uFlags = NIF_ICON;
  79. Shell_NotifyIcon(NIM_MODIFY, &IconData);
  80. return TRUE;
  81. }
  82. BOOL CSAFInciTrayIcon::ShowBalloon(LPCTSTR szText,
  83. LPCTSTR szTitle /*=NULL*/,
  84. DWORD dwIcon /*=NIIF_NONE*/,
  85. UINT uTimeout /*=10*/ )
  86. {
  87. m_tnd.uFlags = NIF_INFO;
  88. _tcsncpy(m_tnd.szInfo, szText, 256);
  89. if (szTitle)
  90. _tcsncpy(m_tnd.szInfoTitle, szTitle, 64);
  91. else
  92. m_tnd.szInfoTitle[0] = _T('\0');
  93. m_tnd.dwInfoFlags = dwIcon;
  94. m_tnd.uTimeout = uTimeout * 1000; // convert time to ms
  95. BOOL bSuccess = Shell_NotifyIcon (NIM_MODIFY, &m_tnd);
  96. // Zero out the balloon text string so that later operations won't redisplay
  97. // the balloon.
  98. m_tnd.szInfo[0] = _T('\0');
  99. return bSuccess;
  100. }
  101. DWORD WINAPI CSAFInciTrayIcon::SAFInciTrayIconThreadFn(LPVOID lpParameter)
  102. {
  103. CSAFInciTrayIcon *pThis = (CSAFInciTrayIcon*)lpParameter;
  104. HWND hWnd = pThis->Create(NULL,CWindow::rcDefault);
  105. if (::IsWindow(hWnd) == FALSE)
  106. return FALSE;
  107. MSG msg;
  108. while (GetMessage(&msg, 0, 0, 0))
  109. DispatchMessage(&msg);
  110. pThis->RemoveTrayIcon();
  111. return TRUE;
  112. }
  113. LRESULT CSAFInciTrayIcon::OnTrayNotification(UINT wParam, LONG lParam)
  114. {
  115. if (LOWORD(lParam) == WM_LBUTTONDBLCLK)
  116. {
  117. TCHAR szCommandLine[2048];
  118. STARTUPINFO StartupInfo;
  119. PROCESS_INFORMATION ProcInfo;
  120. ZeroMemory(&StartupInfo,sizeof(StartupInfo));
  121. StartupInfo.cb = sizeof(StartupInfo);
  122. TCHAR szWinDir[2048];
  123. GetWindowsDirectory(szWinDir, 2048);
  124. _stprintf(szCommandLine, _T("%s%s/rcBuddy.htm?CheckStatus=1"), szWinDir,CHANNEL_PATH);
  125. BOOL bRetVal = CreateProcess(NULL,szCommandLine,NULL,NULL,TRUE,CREATE_NEW_PROCESS_GROUP,NULL,NULL,&StartupInfo,&ProcInfo);
  126. if (!bRetVal)
  127. {
  128. TCHAR buff[50];
  129. DWORD dwLastError = GetLastError();
  130. wsprintf(buff,_T("%d"),dwLastError);
  131. MessageBox(buff);
  132. }
  133. CloseHandle(ProcInfo.hThread);
  134. CloseHandle(ProcInfo.hProcess);
  135. }
  136. return 1;
  137. }
  138. LRESULT CSAFInciTrayIcon::OnIconNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  139. {
  140. OnTrayNotification(wParam,lParam);
  141. return 0;
  142. }
  143. LRESULT CSAFInciTrayIcon::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  144. {
  145. AddTrayIcon();
  146. return 0;
  147. }
  148. LRESULT CSAFInciTrayIcon::OnTaskBarCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  149. {
  150. AddTrayIcon();
  151. return 0;
  152. }