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.

780 lines
24 KiB

  1. #include "tsvs.h"
  2. TCHAR szTipText[MAX_PATH];
  3. int iItemCount, count;
  4. int g_CurrentSortColumn = 0;
  5. BOOL g_bAscending = FALSE;
  6. HMENU g_hMenu;
  7. HMENU hSysMenu;
  8. TCHAR g_szSelectedSession[MAX_LEN];
  9. //////////////////////////////////////////////////////////////////////////////
  10. int APIENTRY WinMain(HINSTANCE hInstance,
  11. HINSTANCE hPrevInstance,
  12. LPSTR lpCmdLine,
  13. int nCmdShow)
  14. {
  15. MSG msg;
  16. HACCEL hAccelTable;
  17. INITCOMMONCONTROLSEX cmctl;
  18. LVCOLUMN lvc;
  19. cmctl.dwICC = ICC_TAB_CLASSES | ICC_BAR_CLASSES;
  20. cmctl.dwSize = sizeof(INITCOMMONCONTROLSEX);
  21. InitCommonControlsEx(&cmctl);
  22. g_hTrayThread = CreateThread(NULL, 0,
  23. (LPTHREAD_START_ROUTINE)TrayThreadMessageLoop,
  24. NULL, 0, &g_idTrayThread);
  25. g_hWinstaThread = CreateThread(NULL, 0,
  26. (LPTHREAD_START_ROUTINE)WinstaThreadMessageLoop,
  27. NULL, 0, &g_idWinstaThread);
  28. // Initialize global strings
  29. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  30. LoadString(hInstance, IDC_TSVS, szWindowClass, MAX_LOADSTRING);
  31. MyRegisterClass(hInstance);
  32. HWND hwndOld = FindWindow(szAppName, szTitle);
  33. if (hwndOld) {
  34. // Send the other copy of ourselves a PWM_ACTIVATE message.
  35. // If that succeeds, and it returns PWM_ACTIVATE back as the
  36. // return code, it's up and alive and we can exit this instance.
  37. DWORD dwPid = 0;
  38. GetWindowThreadProcessId(hwndOld, &dwPid);
  39. // Chris - Leave this in here. Might need it when
  40. // VS gets fixed.
  41. // AllowSetForegroundWindow(dwPid);
  42. ULONG_PTR dwResult;
  43. if (SendMessageTimeout(hwndOld,
  44. PWM_ACTIVATE,
  45. 0, 0,
  46. SMTO_ABORTIFHUNG,
  47. FIND_TIMEOUT,
  48. &dwResult)) {
  49. return 0;
  50. }
  51. }
  52. // Perform application initialization:
  53. if (!InitInstance (hInstance, nCmdShow)) {
  54. return FALSE;
  55. }
  56. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TSVS);
  57. lvc.mask = LVCF_TEXT | LVCF_WIDTH;
  58. lvc.pszText = pszColumn;
  59. lvc.cchTextMax = sizeof(pszColumn);
  60. lvc.cx = COLUMNONEWIDTH;
  61. g_ColumnOneIndex = ListView_InsertColumn(g_hListView, 1, &lvc);
  62. lvc.pszText = pszColumn2;
  63. lvc.cchTextMax = sizeof(pszColumn2);
  64. lvc.cx = COLUMNTWOWIDTH;
  65. g_ColumnTwoIndex = ListView_InsertColumn(g_hListView, 2, &lvc);
  66. lvc.pszText = pszColumn3;
  67. lvc.cchTextMax = sizeof(pszColumn3);
  68. lvc.cx = COLUMNTHREEWIDTH;
  69. g_ColumnThreeIndex = ListView_InsertColumn(g_hListView, 3, &lvc);
  70. lvc.pszText = pszColumn4;
  71. lvc.cchTextMax = sizeof(pszColumn4);
  72. lvc.cx = COLUMNFOURWIDTH;
  73. g_ColumnFourIndex = ListView_InsertColumn(g_hListView, 4, &lvc);
  74. ListView_SetExtendedListViewStyle(g_hListView,
  75. LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  76. if (g_idWinstaThread) {
  77. PostThreadMessage(g_idWinstaThread, PM_WINSTA, 0, 0);
  78. }
  79. // Main message loop:
  80. while (GetMessage(&msg, NULL, 0, 0)) {
  81. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
  82. TranslateMessage(&msg);
  83. DispatchMessage(&msg);
  84. }
  85. }
  86. return(int)msg.wParam;
  87. }
  88. //////////////////////////////////////////////////////////////////////////////
  89. ATOM MyRegisterClass(HINSTANCE hInstance)
  90. {
  91. WNDCLASSEX wcex;
  92. wcex.cbSize = sizeof(WNDCLASSEX);
  93. wcex.style = CS_HREDRAW | CS_VREDRAW;
  94. wcex.lpfnWndProc = (WNDPROC)WndProc;
  95. wcex.cbClsExtra = 0;
  96. wcex.cbWndExtra = DLGWINDOWEXTRA;
  97. wcex.hInstance = hInstance;
  98. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TSVS);
  99. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  100. wcex.hbrBackground = (HBRUSH)(COLOR_ACTIVEBORDER + 1);
  101. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_TSVS);
  102. wcex.lpszClassName = szAppName;
  103. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
  104. return RegisterClassEx(&wcex);
  105. }
  106. //////////////////////////////////////////////////////////////////////////////
  107. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  108. {
  109. hInst = hInstance; // Store instance handle in our global variable
  110. hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DLG_TSVS), 0, NULL);
  111. g_hMenu = GetMenu(hWnd);
  112. if (!hWnd)
  113. return FALSE;
  114. g_hListView = GetDlgItem(hWnd, IDC_LIST_VIEW);
  115. // variable to save handle to system menu
  116. hSysMenu = GetSystemMenu(hWnd, FALSE);
  117. AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
  118. AppendMenu(hSysMenu, MF_STRING, IDM_SYS_SHOW_ALL, TEXT("Show All"));
  119. AppendMenu(hSysMenu, MF_STRING, IDM_SYS_ABOUT, TEXT("About..."));
  120. if (CheckForRegKey(LEFT) == TRUE &&
  121. CheckForRegKey(TOP) == TRUE &&
  122. CheckForRegKey(RIGHT) == TRUE &&
  123. CheckForRegKey(BOTTOM) == TRUE) {
  124. SetWindowPos(hWnd, HWND_NOTOPMOST,
  125. GetRegKeyValue(LEFT),
  126. GetRegKeyValue(TOP),
  127. (GetRegKeyValue(RIGHT) +
  128. GetSystemMetrics (SM_CXDLGFRAME))
  129. - GetRegKeyValue(LEFT),
  130. (GetRegKeyValue(BOTTOM) +
  131. GetSystemMetrics (SM_CYDLGFRAME))
  132. - GetRegKeyValue(TOP),
  133. SWP_NOZORDER | SWP_NOACTIVATE);
  134. }
  135. ShowWindow(hWnd, nCmdShow);
  136. UpdateWindow(hWnd);
  137. ListView_DeleteAllItems(g_hListView);
  138. InitializeCriticalSection(&g_CSTrayThread);
  139. for (UINT i = 0; i < g_cTrayIcons; i++) {
  140. g_TrayIcons[i] =
  141. (HICON) LoadImage(hInst,
  142. MAKEINTRESOURCE(idTrayIcons[i]),
  143. IMAGE_ICON,
  144. 0, 0,
  145. LR_DEFAULTCOLOR);
  146. }
  147. CTrayNotification * pNot =
  148. new CTrayNotification(hWnd,
  149. PWM_TRAYICON,
  150. NIM_ADD,
  151. g_TrayIcons[GREEN],
  152. NULL);
  153. if (pNot) {
  154. if (FALSE == DeliverTrayNotification(pNot)) {
  155. delete pNot;
  156. }
  157. }
  158. return TRUE;
  159. }
  160. //////////////////////////////////////////////////////////////////////////////
  161. LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
  162. WPARAM wParam, LPARAM lParam)
  163. {
  164. int wmId, wmEvent;
  165. PAINTSTRUCT ps;
  166. HDC hdc;
  167. HMENU hPopMenu;
  168. switch (message) {
  169. case WM_SYSCOMMAND:
  170. wmId = LOWORD(wParam);
  171. wmEvent = HIWORD(wParam);
  172. switch (wmId) {
  173. case IDM_SYS_ABOUT:
  174. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  175. return 0;
  176. case IDM_SYS_SHOW_ALL:
  177. if (GetMenuState(g_hMenu, IDM_SHOW_ALL,
  178. MF_BYCOMMAND) == MF_CHECKED) {
  179. CheckMenuItem(g_hMenu, IDM_SHOW_ALL, MF_UNCHECKED);
  180. CheckMenuItem(hSysMenu, IDM_SYS_SHOW_ALL, MF_UNCHECKED);
  181. } else {
  182. CheckMenuItem(g_hMenu, IDM_SHOW_ALL, MF_CHECKED);
  183. CheckMenuItem(hSysMenu, IDM_SYS_SHOW_ALL, MF_CHECKED);
  184. }
  185. GetWinStationInfo();
  186. return 0;
  187. }// end wmId
  188. case WM_COMMAND:
  189. wmId = LOWORD(wParam);
  190. wmEvent = HIWORD(wParam);
  191. switch (wmId) {
  192. case IDM_ABOUT:
  193. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  194. break;
  195. case IDR_POP_CLOSE:
  196. case IDM_EXIT:
  197. DestroyWindow(hWnd);
  198. break;
  199. case IDM_SHOW_ALL:
  200. if (GetMenuState(g_hMenu, IDM_SHOW_ALL,
  201. MF_BYCOMMAND) == MF_CHECKED) {
  202. CheckMenuItem(g_hMenu, IDM_SHOW_ALL, MF_UNCHECKED);
  203. } else {
  204. CheckMenuItem(g_hMenu, IDM_SHOW_ALL, MF_CHECKED);
  205. }
  206. GetWinStationInfo();
  207. break;
  208. case IDD_RESTORE:
  209. ShowRunningInstance();
  210. break;
  211. case IDR_POP_MIN:
  212. case IDD_MINIMIZE:
  213. ShowWindow(hWnd, SW_MINIMIZE);
  214. break;
  215. case ID_FILE_REFRESH:
  216. if (g_idWinstaThread) {
  217. GetWinStationInfo();
  218. }
  219. break;
  220. case IDR_POP_SND_MSG:
  221. // make sure a user is selected
  222. if (g_szSelectedSession[0] != 0 &&
  223. _tcslen(g_szSelectedSession) > 7)
  224. DialogBox(hInst, (LPCTSTR)IDD_MSG_DLG,
  225. hWnd, (DLGPROC)SndMsg);
  226. break;
  227. default:
  228. return DefWindowProc(hWnd, message, wParam, lParam);
  229. }
  230. break;
  231. case WM_PAINT:
  232. hdc = BeginPaint(hWnd, &ps);
  233. RECT rt;
  234. GetClientRect(hWnd, &rt);
  235. EndPaint(hWnd, &ps);
  236. break;
  237. case WM_NOTIFY:
  238. {
  239. switch (((LPNMHDR) lParam)->code) {
  240. // display a popup menu for sending a message, closing app, etc.
  241. case NM_RCLICK :
  242. {
  243. LPNMITEMACTIVATE lpnmitem;
  244. lpnmitem = (LPNMITEMACTIVATE) lParam;
  245. hPopMenu = LoadPopupMenu(hInst, IDR_POP);
  246. ZeroMemory(g_szSelectedSession, MAX_LEN);
  247. // get the session ID that the user clicked on.
  248. ListView_GetItemText(g_hListView, lpnmitem->iItem, 1,
  249. g_szSelectedSession, MAX_LEN);
  250. if (g_szSelectedSession[0] != 0 &&
  251. _tcslen(g_szSelectedSession) > 7) {
  252. EnableMenuItem(hPopMenu,
  253. IDR_POP_SND_MSG, MF_BYCOMMAND | MF_ENABLED);
  254. } else {
  255. EnableMenuItem(hPopMenu,
  256. IDR_POP_SND_MSG, MF_BYCOMMAND | MF_GRAYED);
  257. }
  258. if (hPopMenu) {
  259. POINT pt;
  260. GetCursorPos(&pt);
  261. SetForegroundWindow(hWnd);
  262. TrackPopupMenuEx(hPopMenu, 0, pt.x, pt.y, hWnd, NULL);
  263. DestroyMenu(hPopMenu);
  264. }
  265. break;
  266. }
  267. case NM_DBLCLK :
  268. {
  269. LPNMITEMACTIVATE lpnmitem;
  270. lpnmitem = (LPNMITEMACTIVATE) lParam;
  271. // get the session ID that the user clicked on.
  272. ListView_GetItemText(g_hListView, lpnmitem->iItem, 1,
  273. g_szSelectedSession, MAX_LEN);
  274. // make sure a user is selected
  275. if (g_szSelectedSession[0] != 0 &&
  276. _tcslen(g_szSelectedSession) > 7)
  277. DialogBox(hInst, (LPCTSTR)IDD_MSG_DLG,
  278. hWnd, (DLGPROC)SndMsg);
  279. break;
  280. }
  281. case LVN_COLUMNCLICK:
  282. {
  283. if (g_CurrentSortColumn == ((LPNMLISTVIEW)lParam)->iSubItem)
  284. g_bAscending = !g_bAscending;
  285. else
  286. g_bAscending = TRUE;
  287. g_CurrentSortColumn = ((LPNMLISTVIEW)lParam)->iSubItem;
  288. if (g_idWinstaThread) GetWinStationInfo();
  289. ListView_SortItems(g_hListView, Sort,
  290. ((LPNMLISTVIEW)lParam)->iSubItem);
  291. }
  292. break;
  293. }
  294. }
  295. case WM_WINDOWPOSCHANGED:
  296. {
  297. WINDOWPOS *lpwp;
  298. RECT rc, rm;
  299. lpwp = (LPWINDOWPOS) lParam;
  300. // resize the list control.
  301. GetClientRect(hWnd, &rc);
  302. MoveWindow(
  303. g_hListView, // handle to window
  304. 0, // horizontal position
  305. 0, // vertical position
  306. rc.right - rc.left, //width
  307. rc.bottom - rc.top, // height
  308. TRUE);
  309. // save window position and size.
  310. if (! IsIconic(hWnd)) {
  311. GetWindowRect(hWnd, &rm);
  312. GetClientRect(hWnd, &rc);
  313. MapWindowPoints(hWnd, NULL, (LPPOINT)&rc, 2);
  314. SetRegKey(LEFT, &rm.left);
  315. SetRegKey(TOP, &rm.top);
  316. SetRegKey(RIGHT, &rc.right);
  317. SetRegKey(BOTTOM, &rc.bottom);
  318. } else {
  319. ShowWindow(hWnd, SW_HIDE);
  320. }
  321. break;
  322. }
  323. // notifications from tray icon
  324. case PWM_TRAYICON:
  325. {
  326. Tray_Notify(hWnd, wParam, lParam);
  327. break;
  328. }
  329. // wake up and be shown
  330. case PWM_ACTIVATE:
  331. {
  332. ShowRunningInstance();
  333. break;
  334. }
  335. case WM_DESTROY:
  336. {
  337. TerminateThread(g_hWinstaThread, 0);
  338. // Remove the tray icon
  339. CTrayNotification * pNot =
  340. new CTrayNotification(hWnd,
  341. PWM_TRAYICON,
  342. NIM_DELETE,
  343. NULL,
  344. NULL);
  345. if (pNot) {
  346. if (FALSE == DeliverTrayNotification(pNot)) {
  347. delete pNot;
  348. }
  349. }
  350. // If there's a tray thread, tell it to exit
  351. EnterCriticalSection(&g_CSTrayThread);
  352. if (g_idTrayThread) {
  353. PostThreadMessage(g_idTrayThread, PM_QUITTRAYTHREAD, 0, 0);
  354. }
  355. LeaveCriticalSection(&g_CSTrayThread);
  356. // Wait around for some period of time for the tray thread to
  357. // do its cleanup work. If the wait times out, worst case we
  358. // orphan the tray icon.
  359. if (g_hTrayThread) {
  360. #define TRAY_THREAD_WAIT 3000
  361. WaitForSingleObject(g_hTrayThread, TRAY_THREAD_WAIT);
  362. CloseHandle(g_hTrayThread);
  363. }
  364. PostQuitMessage(0);
  365. break;
  366. }
  367. default:
  368. return DefWindowProc(hWnd, message, wParam, lParam);
  369. }
  370. return 0;
  371. }
  372. // Mesage handler for about box.
  373. //////////////////////////////////////////////////////////////////////////////
  374. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  375. {
  376. switch (message) {
  377. case WM_INITDIALOG:
  378. return TRUE;
  379. case WM_COMMAND:
  380. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
  381. EndDialog(hDlg, LOWORD(wParam));
  382. return TRUE;
  383. }
  384. break;
  385. }
  386. return FALSE;
  387. }
  388. //////////////////////////////////////////////////////////////////////////////
  389. // Mesage handler for send message dialog.
  390. //////////////////////////////////////////////////////////////////////////////
  391. LRESULT CALLBACK SndMsg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  392. {
  393. int wmId, wmEvent;
  394. DWORD pResponse;
  395. TCHAR pTitle[MAX_LEN];
  396. // user name variables
  397. DWORD nSize;
  398. TCHAR szBuf[MAX_LEN];
  399. TCHAR pMessage[MAX_LEN];
  400. static HWND hwndEditTitle;
  401. static HWND hwndEditMessage;
  402. PSID pSID;
  403. DWORD dwGroupSIDCount = 0;
  404. DWORD cbSID, dwError;
  405. SID_NAME_USE snuGroup;
  406. DWORD dwDomainSize = MAX_LEN;
  407. TCHAR szDomainName[MAX_LEN];
  408. LPTSTR pszGroupName[MAX_LEN];
  409. switch (message) {
  410. case WM_INITDIALOG:
  411. {
  412. hwndEditTitle = GetDlgItem(hDlg, IDC_EDIT_TITLE);
  413. hwndEditMessage = GetDlgItem(hDlg, IDC_EDIT_MSG);
  414. // get the user name
  415. nSize = sizeof(szBuf);
  416. GetUserName(szBuf, &nSize);
  417. cbSID = GetSidLengthRequired (10);
  418. pSID = ( PSID) malloc ( cbSID);
  419. if (!pSID) {
  420. return 0;
  421. }
  422. // get the user's domain
  423. LookupAccountName ( NULL, szBuf, pSID,
  424. &cbSID, szDomainName, &dwDomainSize, &snuGroup);
  425. /*/
  426. dwError = GetLastError();
  427. if ( dwError == ERROR_INSUFFICIENT_BUFFER)
  428. {
  429. } else {
  430. }
  431. /*/
  432. free(pSID);
  433. pSID = NULL;
  434. for (UINT i = 0; i < pCount; i++) {
  435. // find the correct session ID
  436. if (! _tcscmp(ppSessionInfo[i].pWinStationName,
  437. g_szSelectedSession)) {
  438. _tcscpy(pTitle, TEXT("Message from: "));
  439. _tcscat(pTitle, szDomainName);
  440. _tcscat(pTitle, "\\");
  441. _tcscat(pTitle, szBuf);
  442. SetWindowText(hwndEditTitle, pTitle);
  443. }
  444. }
  445. return TRUE;
  446. }
  447. case WM_COMMAND:
  448. wmId = LOWORD(wParam);
  449. wmEvent = HIWORD(wParam);
  450. switch (wmId) {
  451. case IDOK:
  452. {
  453. GetWindowText(hwndEditTitle, pTitle, MAX_LEN - 1);
  454. GetWindowText(hwndEditMessage, pMessage, MAX_LEN - 1);
  455. for (UINT i = 0; i < pCount; i++) {
  456. // find the correct session ID
  457. if (! _tcscmp(ppSessionInfo[i].pWinStationName,
  458. g_szSelectedSession))
  459. WTSSendMessage(
  460. WTS_CURRENT_SERVER_HANDLE,
  461. ppSessionInfo[i].SessionId,
  462. pTitle,
  463. sizeof(pTitle),
  464. pMessage,
  465. sizeof(pMessage),
  466. MB_OK, // | MB_ICONEXCLAMATION,
  467. 30,
  468. &pResponse,
  469. FALSE); // don't wait for a response
  470. }
  471. EndDialog(hDlg, LOWORD(wParam));
  472. return TRUE;
  473. }
  474. case IDCANCEL:
  475. EndDialog(hDlg, LOWORD(wParam));
  476. return TRUE;
  477. }
  478. }
  479. return FALSE;
  480. }
  481. //////////////////////////////////////////////////////////////////////////////
  482. int FillList(int nMcIndex)
  483. {
  484. LVITEM lvi;
  485. LVFINDINFO lvfi;
  486. int iListViewIndex, i;
  487. TCHAR string[MAX_LEN];
  488. TCHAR tmp[10];
  489. // initialize tool tip variable
  490. for (i = 0; i < MAX_PATH; i++) {
  491. szTipText[i] = 0;
  492. }
  493. i = 0;
  494. iItemCount = ListView_GetItemCount(g_hListView);
  495. ListView_GetItemText(g_hListView, nMcIndex - 1, 0, string, MAX_LEN);
  496. ListView_DeleteAllItems(g_hListView);
  497. // fill the list with the stats for running machines
  498. while (i < nMcIndex) {
  499. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  500. lvi.iItem = (int) SendMessage(g_hListView, LVM_GETITEMCOUNT, 0, 0);
  501. lvi.iSubItem = 0;
  502. lvi.pszText = szMcNames[i];
  503. lvi.cchTextMax = sizeof(szMcNames[i]);
  504. _itot(i, tmp, 10);
  505. lvi.lParam = (LPARAM) i; //(TCHAR *)tmp;
  506. //lvi.lParam = (LPARAM) (TCHAR *)szMcNames[i];
  507. lvfi.flags = LVFI_STRING;
  508. lvfi.psz = szMcNames[i];
  509. lvfi.lParam = 0;
  510. lvfi.vkDirection = 0;
  511. // get the index of the item, if it's there.
  512. iListViewIndex = ListView_FindItem(g_hListView, -1, &lvfi);
  513. // the if statement makes it so you don't get any duplicate names
  514. // in the list control
  515. //if (iListViewIndex == -1) {
  516. int nPos;
  517. // insert machine name
  518. nPos = ListView_InsertItem(g_hListView, &lvi);
  519. // insert time field
  520. ListView_SetItemText(g_hListView, nPos, g_ColumnTwoIndex, szMcID[i]);
  521. // insert machine type
  522. ListView_SetItemText(g_hListView, nPos,
  523. g_ColumnThreeIndex, szMcAddress[i]);
  524. // insert machine type
  525. ListView_SetItemText(g_hListView, nPos,
  526. g_ColumnFourIndex, szBuild[i]);
  527. /*
  528. // write data to file
  529. stream1 = fopen("c:\\WinSta.log", "a");
  530. // write name to file
  531. fputs(szMcNames[i], stream1);
  532. // write ID field to file
  533. for (x = 0; x < (40 - _tcslen(szMcNames[i])); x++) {
  534. fputs(" ", stream1);
  535. }
  536. fputs(szMcID[i], stream1);
  537. // write address to file
  538. for (x = 0; x < (20 - _tcslen(szMcAddress[i])); x++) {
  539. fputs(" ", stream1);
  540. }
  541. fputs(szMcAddress[i], stream1);
  542. fputs("\n", stream1);
  543. fclose(stream1);
  544. */
  545. i++;
  546. }
  547. // count the current list elements and determine
  548. // the icon to display
  549. iItemCount = ListView_GetItemCount(g_hListView);
  550. _itot(iItemCount, string, 10);
  551. _tcscpy(szTipText, string);
  552. _tcscat(szTipText, " session(s)");
  553. if (iItemCount == 0) {
  554. count = GREEN;
  555. ShowMyIcon();
  556. return 0;
  557. }
  558. if (iItemCount > 0 && iItemCount < 5) {
  559. count = YELLOW;
  560. ShowMyIcon();
  561. return 0;
  562. }
  563. if (iItemCount > 5) {
  564. count = RED;
  565. ShowMyIcon();
  566. return 0;
  567. }
  568. return 1;
  569. }
  570. //////////////////////////////////////////////////////////////////////////////
  571. int CDECL MessageBoxPrintf(TCHAR *szCaption, TCHAR *szFormat, ...)
  572. {
  573. TCHAR szBuffer[MAX_STATIONS];
  574. va_list pArgList;
  575. va_start(pArgList, szFormat);
  576. _vsntprintf(szBuffer, sizeof(szBuffer) / sizeof(TCHAR),
  577. szFormat, pArgList);
  578. va_end(pArgList);
  579. return MessageBox(NULL, szBuffer, szCaption, 0);
  580. }
  581. //////////////////////////////////////////////////////////////////////////////
  582. void ShowMyIcon()
  583. {
  584. CTrayNotification * pNot;
  585. // change the light back to red if no servers are listed
  586. switch (count) {
  587. case GREEN:
  588. pNot = new CTrayNotification(hWnd,
  589. PWM_TRAYICON,
  590. NIM_MODIFY,
  591. g_TrayIcons[GREEN],
  592. szTipText);
  593. if (pNot) {
  594. if (FALSE == DeliverTrayNotification(pNot))
  595. delete pNot;
  596. }
  597. break;
  598. case YELLOW:
  599. pNot = new CTrayNotification(hWnd,
  600. PWM_TRAYICON,
  601. NIM_MODIFY,
  602. g_TrayIcons[GREEN],
  603. //g_TrayIcons[YELLOW],
  604. szTipText);
  605. if (pNot) {
  606. if (FALSE == DeliverTrayNotification(pNot))
  607. delete pNot;
  608. }
  609. break;
  610. case RED:
  611. pNot = new CTrayNotification(hWnd,
  612. PWM_TRAYICON,
  613. NIM_MODIFY,
  614. g_TrayIcons[GREEN],
  615. //g_TrayIcons[RED],
  616. szTipText);
  617. if (pNot) {
  618. if (FALSE == DeliverTrayNotification(pNot))
  619. delete pNot;
  620. }
  621. break;
  622. }
  623. }
  624. //////////////////////////////////////////////////////////////////////////////
  625. int CALLBACK Sort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamColumn)
  626. {
  627. TCHAR szItemString[MAX_LEN];
  628. TCHAR szItemString2[MAX_LEN];
  629. ListView_GetItemText(g_hListView, (INT)lParam1, (INT)lParamColumn,
  630. szItemString, MAX_LEN);
  631. ListView_GetItemText(g_hListView, (INT)lParam2, (INT)lParamColumn,
  632. szItemString2, MAX_LEN);
  633. if (g_bAscending == TRUE)
  634. return strcmp(szItemString, szItemString2);
  635. else
  636. return -1 * strcmp(szItemString, szItemString2);
  637. }
  638. //////////////////////////////////////////////////////////////////////////////