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.

1142 lines
31 KiB

  1. /*******************************************************************************
  2. *
  3. * apppgs.cpp
  4. *
  5. * implementations for the Application info pages
  6. *
  7. * copyright notice: Copyright 1997, Citrix Systems Inc.
  8. * Copyright (c) 1998 - 1999 Microsoft Corporation
  9. *
  10. * $Author: donm $ Don Messerli
  11. *
  12. * $Log: N:\nt\private\utils\citrix\winutils\tsadmin\VCS\apppgs.cpp $
  13. *
  14. * Rev 1.4 16 Feb 1998 16:00:00 donm
  15. * modifications to support pICAsso extension
  16. *
  17. * Rev 1.3 03 Nov 1997 15:20:24 donm
  18. * added descending sort
  19. *
  20. * Rev 1.2 22 Oct 1997 21:06:14 donm
  21. * update
  22. *
  23. * Rev 1.1 18 Oct 1997 18:49:48 donm
  24. * update
  25. *
  26. *******************************************************************************/
  27. #include "stdafx.h"
  28. #include "afxpriv.h"
  29. #include "winadmin.h"
  30. #include "admindoc.h"
  31. #include "apppgs.h"
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. ////////////////////////////////
  38. // MESSAGE MAP: CApplicationServersPage
  39. //
  40. IMPLEMENT_DYNCREATE(CApplicationServersPage, CFormView)
  41. BEGIN_MESSAGE_MAP(CApplicationServersPage, CFormView)
  42. //{{AFX_MSG_MAP(CApplicationServersPage)
  43. ON_WM_SIZE()
  44. ON_NOTIFY(LVN_COLUMNCLICK, IDC_APPLICATION_SERVER_LIST, OnColumnClick)
  45. ON_NOTIFY(NM_SETFOCUS, IDC_APPLICATION_SERVER_LIST, OnSetfocusServerList)
  46. ON_COMMAND(ID_HELP, CWnd::OnHelp)
  47. ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
  48. ON_MESSAGE(WM_HELP, OnCommandHelp)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////
  52. // F'N: CApplicationServersPage ctor
  53. //
  54. CApplicationServersPage::CApplicationServersPage()
  55. : CAdminPage(CApplicationServersPage::IDD)
  56. {
  57. //{{AFX_DATA_INIT(CApplicationServersPage)
  58. //}}AFX_DATA_INIT
  59. m_pApplication = NULL;
  60. m_bSortAscending = TRUE;
  61. } // end CApplicationServersPage ctor
  62. /////////////////////////////
  63. // F'N: CApplicationServersPage dtor
  64. //
  65. CApplicationServersPage::~CApplicationServersPage()
  66. {
  67. } // end CApplicationServersPage dtor
  68. ////////////////////////////////////////
  69. // F'N: CApplicationServersPage::DoDataExchange
  70. //
  71. void CApplicationServersPage::DoDataExchange(CDataExchange* pDX)
  72. {
  73. CFormView::DoDataExchange(pDX);
  74. //{{AFX_DATA_MAP(CApplicationServersPage)
  75. DDX_Control(pDX, IDC_APPLICATION_SERVER_LIST, m_ServerList);
  76. //}}AFX_DATA_MAP
  77. } // end CApplicationServersPage::DoDataExchange
  78. #ifdef _DEBUG
  79. /////////////////////////////////////
  80. // F'N: CApplicationServersPage::AssertValid
  81. //
  82. void CApplicationServersPage::AssertValid() const
  83. {
  84. CFormView::AssertValid();
  85. } // end CApplicationServersPage::AssertValid
  86. //////////////////////////////
  87. // F'N: CApplicationServersPage::Dump
  88. //
  89. void CApplicationServersPage::Dump(CDumpContext& dc) const
  90. {
  91. CFormView::Dump(dc);
  92. } // end CApplicationServersPage::Dump
  93. #endif //_DEBUG
  94. //////////////////////////////
  95. // F'N: CApplicationServersPage::OnCommandHelp
  96. //
  97. void CApplicationServersPage::OnCommandHelp(void)
  98. {
  99. AfxGetApp()->WinHelp(CApplicationServersPage::IDD + HID_BASE_RESOURCE);
  100. } // end CApplicationServersPage::OnCommandHelp
  101. static ColumnDef ServerColumns[] = {
  102. CD_SERVER,
  103. { IDS_COL_COMMAND_LINE, LVCFMT_LEFT, 200 },
  104. { IDS_COL_WORKING_DIR, LVCFMT_LEFT, 200 },
  105. { IDS_COL_TCP_LOAD, LVCFMT_RIGHT, 100 },
  106. { IDS_COL_IPX_LOAD, LVCFMT_RIGHT, 100 },
  107. { IDS_COL_NETBIOS_LOAD, LVCFMT_RIGHT, 100 }
  108. };
  109. #define NUM_SERVER_COLUMNS sizeof(ServerColumns)/sizeof(ColumnDef)
  110. //////////////////////////////
  111. // F'N: CApplicationServersPage::OnInitialUpdate
  112. //
  113. void CApplicationServersPage::OnInitialUpdate()
  114. {
  115. CFormView::OnInitialUpdate();
  116. BuildImageList(); // builds the image list for the list control
  117. CString columnString;
  118. for(int col = 0; col < NUM_SERVER_COLUMNS; col++) {
  119. columnString.LoadString(ServerColumns[col].stringID);
  120. m_ServerList.InsertColumn(col, columnString, ServerColumns[col].format, ServerColumns[col].width, col);
  121. }
  122. m_CurrentSortColumn = APP_SERVER_COL_SERVER;
  123. } // end CApplicationServersPage::OnInitialUpdate
  124. //////////////////////////////
  125. // F'N: CApplicationServersPage::OnColumnClick
  126. //
  127. void CApplicationServersPage::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
  128. {
  129. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  130. // TODO: Add your control notification handler code here
  131. // If the sort column hasn't changed, flip the ascending mode.
  132. if(m_CurrentSortColumn == pNMListView->iSubItem)
  133. m_bSortAscending = !m_bSortAscending;
  134. else // New sort column, start in ascending mode
  135. m_bSortAscending = TRUE;
  136. m_CurrentSortColumn = pNMListView->iSubItem;
  137. SortByColumn(VIEW_APPLICATION, PAGE_APP_SERVERS, &m_ServerList, m_CurrentSortColumn, m_bSortAscending);
  138. *pResult = 0;
  139. } // end CApplicationUsersPage::OnColumnClick
  140. //////////////////////////////
  141. // F'N: CApplicationServersPage::OnSize
  142. //
  143. void CApplicationServersPage::OnSize(UINT nType, int cx, int cy)
  144. {
  145. RECT rect;
  146. GetClientRect(&rect);
  147. rect.top += LIST_TOP_OFFSET;
  148. if(m_ServerList.GetSafeHwnd())
  149. m_ServerList.MoveWindow(&rect, TRUE);
  150. CFormView::OnSize(nType, cx, cy);
  151. } // end CApplicationServersPage::OnSize
  152. //////////////////////////////
  153. // F'N: CApplicationServersPage::Reset
  154. //
  155. void CApplicationServersPage::Reset(void *pApplication)
  156. {
  157. m_pApplication = (CPublishedApp*)pApplication;
  158. DisplayServers();
  159. } // end CApplicationServersPage::Reset
  160. //////////////////////////////
  161. // F'N: CApplicationServersPage::AddServer
  162. //
  163. void CApplicationServersPage::AddServer(CAppServer *pAppServer)
  164. {
  165. ASSERT(pAppServer);
  166. // We have to make sure the server isn't already in the list
  167. // Add the server to the list
  168. if(AddServerToList(pAppServer)) {
  169. // Tell the list to sort itself
  170. LockListControl();
  171. SortByColumn(VIEW_APPLICATION, PAGE_APP_SERVERS, &m_ServerList, m_CurrentSortColumn, m_bSortAscending);
  172. UnlockListControl();
  173. }
  174. } // end CApplicationServersPage::AddServer
  175. //////////////////////////////
  176. // F'N: CApplicationServersPage::RemoveServer
  177. //
  178. void CApplicationServersPage::RemoveServer(CAppServer *pAppServer)
  179. {
  180. ASSERT(pAppServer);
  181. LockListControl();
  182. // Find out how many items in the list
  183. int ItemCount = m_ServerList.GetItemCount();
  184. // Go through the items are remove this server
  185. for(int item = 0; item < ItemCount; item++) {
  186. CAppServer *pListAppServer = (CAppServer*)m_ServerList.GetItemData(item);
  187. if(pListAppServer == pAppServer) {
  188. m_ServerList.DeleteItem(item);
  189. break;
  190. }
  191. }
  192. UnlockListControl();
  193. } // end CApplicationServersPage::RemoveServer
  194. //////////////////////////////
  195. // F'N: CApplicationServersPage::AddServerToList
  196. //
  197. int CApplicationServersPage::AddServerToList(CAppServer *pAppServer)
  198. {
  199. ASSERT(pAppServer);
  200. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  201. // Server - put at the end of the list
  202. int item = m_ServerList.InsertItem(m_ServerList.GetItemCount(), pAppServer->GetName(),
  203. pAppServer->IsCurrentServer() ? m_idxCurrentServer : m_idxServer);
  204. // Command Line
  205. m_ServerList.SetItemText(item, APP_SERVER_COL_CMDLINE, pAppServer->GetInitialProgram());
  206. // Working Directory
  207. m_ServerList.SetItemText(item, APP_SERVER_COL_WORKDIR, pAppServer->GetWorkDirectory());
  208. CServer *pServer = pDoc->FindServerByName(pAppServer->GetName());
  209. if(pServer) {
  210. ExtServerInfo *pExtServerInfo = pServer->GetExtendedInfo();
  211. CString LoadLevelString;
  212. if(pExtServerInfo && ((pExtServerInfo->Flags & ESF_LOAD_BALANCING) > 0)) {
  213. if(pExtServerInfo->TcpLoadLevel == 0xFFFFFFFF) {
  214. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  215. }
  216. else LoadLevelString.Format(TEXT("%lu"), pExtServerInfo->TcpLoadLevel);
  217. m_ServerList.SetItemText(item, APP_SERVER_COL_TCP_LOAD, LoadLevelString);
  218. if(pExtServerInfo->IpxLoadLevel == 0xFFFFFFFF) {
  219. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  220. }
  221. else LoadLevelString.Format(TEXT("%lu"), pExtServerInfo->IpxLoadLevel);
  222. m_ServerList.SetItemText(item, APP_SERVER_COL_IPX_LOAD, LoadLevelString);
  223. if(pExtServerInfo->NetbiosLoadLevel == 0xFFFFFFFF) {
  224. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  225. }
  226. else LoadLevelString.Format(TEXT("%lu"), pExtServerInfo->NetbiosLoadLevel);
  227. m_ServerList.SetItemText(item, APP_SERVER_COL_NETBIOS_LOAD, LoadLevelString);
  228. } else {
  229. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  230. m_ServerList.SetItemText(item, APP_SERVER_COL_TCP_LOAD, LoadLevelString);
  231. m_ServerList.SetItemText(item, APP_SERVER_COL_IPX_LOAD, LoadLevelString);
  232. m_ServerList.SetItemText(item, APP_SERVER_COL_NETBIOS_LOAD, LoadLevelString);
  233. }
  234. }
  235. m_ServerList.SetItemData(item, (DWORD)pAppServer);
  236. return item;
  237. } // end CApplicationServersPage::AddServerToList
  238. /////////////////////////////////////
  239. // F'N: CApplicationServersPage::DisplayServers
  240. //
  241. void CApplicationServersPage::DisplayServers()
  242. {
  243. // Clear out the list control
  244. m_ServerList.DeleteAllItems();
  245. m_pApplication->LockServerList();
  246. // Get a pointer to this App's list of Servers
  247. CObList *pServerList = m_pApplication->GetServerList();
  248. // Iterate through the Server list
  249. POSITION pos = pServerList->GetHeadPosition();
  250. while(pos) {
  251. CAppServer *pAppServer = (CAppServer*)pServerList->GetNext(pos);
  252. AddServerToList(pAppServer);
  253. } // end while(pos)
  254. m_pApplication->UnlockServerList();
  255. SortByColumn(VIEW_APPLICATION, PAGE_APP_SERVERS, &m_ServerList, m_CurrentSortColumn, m_bSortAscending);
  256. } // end CApplicationServersPage::DisplayServers
  257. /////////////////////////////////////
  258. // F'N: CApplicationServersPage::UpdateServer
  259. //
  260. void CApplicationServersPage::UpdateServer(CServer *pServer)
  261. {
  262. ASSERT(pServer);
  263. CAppServer *pAppServer = m_pApplication->FindServerByName(pServer->GetName());
  264. if(!pAppServer) return;
  265. LV_FINDINFO FindInfo;
  266. FindInfo.flags = LVFI_PARAM;
  267. FindInfo.lParam = (LPARAM)pAppServer;
  268. // Find the AppServer in our list
  269. int item = m_ServerList.FindItem(&FindInfo, -1);
  270. if(item != -1) {
  271. ExtServerInfo *pExtServerInfo = pServer->GetExtendedInfo();
  272. CString LoadLevelString;
  273. if(pExtServerInfo && ((pExtServerInfo->Flags & ESF_LOAD_BALANCING) > 0)) {
  274. if(pExtServerInfo->TcpLoadLevel == 0xFFFFFFFF) {
  275. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  276. }
  277. else LoadLevelString.Format(TEXT("%lu"), pExtServerInfo->TcpLoadLevel);
  278. m_ServerList.SetItemText(item, APP_SERVER_COL_TCP_LOAD, LoadLevelString);
  279. if(pExtServerInfo->IpxLoadLevel == 0xFFFFFFFF) {
  280. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  281. }
  282. else LoadLevelString.Format(TEXT("%lu"), pExtServerInfo->IpxLoadLevel);
  283. m_ServerList.SetItemText(item, APP_SERVER_COL_IPX_LOAD, LoadLevelString);
  284. if(pExtServerInfo->NetbiosLoadLevel == 0xFFFFFFFF) {
  285. LoadLevelString.LoadString(IDS_NOT_APPLICABLE);
  286. }
  287. else LoadLevelString.Format(TEXT("%lu"), pExtServerInfo->NetbiosLoadLevel);
  288. m_ServerList.SetItemText(item, APP_SERVER_COL_NETBIOS_LOAD, LoadLevelString);
  289. }
  290. }
  291. } // end CApplicationServersPage::UpdateServer
  292. /////////////////////////////////////
  293. // F'N: CApplicationServersPage::BuildImageList
  294. //
  295. // - calls m_imageList.Create(..) to create the image list
  296. // - calls AddIconToImageList(..) to add the icons themselves and save
  297. // off their indices
  298. // - attaches the image list to the list ctrl
  299. //
  300. void CApplicationServersPage::BuildImageList()
  301. {
  302. m_imageList.Create(16, 16, TRUE, 2, 0);
  303. m_idxServer = AddIconToImageList(IDI_SERVER);
  304. m_idxCurrentServer = AddIconToImageList(IDI_CURRENT_SERVER);
  305. m_ServerList.SetImageList(&m_imageList, LVSIL_SMALL);
  306. } // end CApplicationServersPage::BuildImageList
  307. /////////////////////////////////////////
  308. // F'N: CApplicationServersPage::AddIconToImageList
  309. //
  310. // - loads the appropriate icon, adds it to m_imageList, and returns
  311. // the newly-added icon's index in the image list
  312. //
  313. int CApplicationServersPage::AddIconToImageList(int iconID)
  314. {
  315. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  316. return m_imageList.Add(hIcon);
  317. } // end CApplicationServersPage::AddIconToImageList
  318. /////////////////////////////////////////
  319. // F'N: CApplicationServersPage::OnSetfocusServerList
  320. //
  321. void CApplicationServersPage::OnSetfocusServerList(NMHDR* pNMHDR, LRESULT* pResult)
  322. {
  323. // TODO: Add your control notification handler code here
  324. if(m_ServerList) m_ServerList.Invalidate();
  325. *pResult = 0;
  326. } // end CApplicationServersPage::OnSetfocusServerList
  327. ////////////////////////////////
  328. // MESSAGE MAP: CApplicationUsersPage
  329. //
  330. IMPLEMENT_DYNCREATE(CApplicationUsersPage, CFormView)
  331. BEGIN_MESSAGE_MAP(CApplicationUsersPage, CFormView)
  332. //{{AFX_MSG_MAP(CApplicationUsersPage)
  333. ON_WM_SIZE()
  334. ON_NOTIFY(LVN_COLUMNCLICK, IDC_APPLICATION_USER_LIST, OnColumnClick)
  335. ON_NOTIFY(NM_SETFOCUS, IDC_APPLICATION_USER_LIST, OnSetfocusUserList)
  336. ON_COMMAND(ID_HELP, CWnd::OnHelp)
  337. ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
  338. ON_MESSAGE(WM_HELP, OnCommandHelp)
  339. //}}AFX_MSG_MAP
  340. END_MESSAGE_MAP()
  341. /////////////////////////////
  342. // F'N: CApplicationUsersPage ctor
  343. //
  344. CApplicationUsersPage::CApplicationUsersPage()
  345. : CAdminPage(CApplicationUsersPage::IDD)
  346. {
  347. //{{AFX_DATA_INIT(CApplicationUsersPage)
  348. //}}AFX_DATA_INIT
  349. m_pApplication = NULL;
  350. m_bSortAscending = TRUE;
  351. } // end CApplicationUsersPage ctor
  352. /////////////////////////////
  353. // F'N: CApplicationUsersPage dtor
  354. //
  355. CApplicationUsersPage::~CApplicationUsersPage()
  356. {
  357. } // end CApplicationUsersPage dtor
  358. ////////////////////////////////////////
  359. // F'N: CApplicationUsersPage::DoDataExchange
  360. //
  361. void CApplicationUsersPage::DoDataExchange(CDataExchange* pDX)
  362. {
  363. CFormView::DoDataExchange(pDX);
  364. //{{AFX_DATA_MAP(CApplicationUsersPage)
  365. DDX_Control(pDX, IDC_APPLICATION_USER_LIST, m_UserList);
  366. //}}AFX_DATA_MAP
  367. } // end CApplicationUsersPage::DoDataExchange
  368. #ifdef _DEBUG
  369. /////////////////////////////////////
  370. // F'N: CApplicationUsersPage::AssertValid
  371. //
  372. void CApplicationUsersPage::AssertValid() const
  373. {
  374. CFormView::AssertValid();
  375. } // end CApplicationUsersPage::AssertValid
  376. //////////////////////////////
  377. // F'N: CApplicationUsersPage::Dump
  378. //
  379. void CApplicationUsersPage::Dump(CDumpContext& dc) const
  380. {
  381. CFormView::Dump(dc);
  382. } // end CApplicationUsersPage::Dump
  383. #endif //_DEBUG
  384. //////////////////////////////
  385. // F'N: CApplicationUsersPage::OnCommandHelp
  386. //
  387. void CApplicationUsersPage::OnCommandHelp(void)
  388. {
  389. AfxGetApp()->WinHelp(CApplicationUsersPage::IDD + HID_BASE_RESOURCE);
  390. } // end CApplicationUsersPage::OnCommandHelp
  391. static ColumnDef UserColumns[] = {
  392. CD_SERVER,
  393. CD_USER3,
  394. CD_SESSION,
  395. CD_ID,
  396. CD_STATE,
  397. CD_IDLETIME,
  398. CD_LOGONTIME
  399. };
  400. #define NUM_USER_COLUMNS sizeof(UserColumns)/sizeof(ColumnDef)
  401. //////////////////////////////
  402. // F'N: CApplicationUsersPage::OnInitialUpdate
  403. //
  404. void CApplicationUsersPage::OnInitialUpdate()
  405. {
  406. CFormView::OnInitialUpdate();
  407. BuildImageList(); // builds the image list for the list control
  408. CString columnString;
  409. for(int col = 0; col < NUM_USER_COLUMNS; col++) {
  410. columnString.LoadString(UserColumns[col].stringID);
  411. m_UserList.InsertColumn(col, columnString, UserColumns[col].format, UserColumns[col].width, col);
  412. }
  413. m_CurrentSortColumn = APP_USERS_COL_SERVER;
  414. } // end CApplicationUsersPage::OnInitialUpdate
  415. //////////////////////////////
  416. // F'N: CApplicationUsersPage::OnColumnClick
  417. //
  418. void CApplicationUsersPage::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
  419. {
  420. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  421. // TODO: Add your control notification handler code here
  422. // If the sort column hasn't changed, flip the ascending mode.
  423. if(m_CurrentSortColumn == pNMListView->iSubItem)
  424. m_bSortAscending = !m_bSortAscending;
  425. else // New sort column, start in ascending mode
  426. m_bSortAscending = TRUE;
  427. m_CurrentSortColumn = pNMListView->iSubItem;
  428. SortByColumn(VIEW_APPLICATION, PAGE_APP_USERS, &m_UserList, m_CurrentSortColumn, m_bSortAscending);
  429. *pResult = 0;
  430. } // end CApplicationUsersPage::OnColumnClick
  431. //////////////////////////////
  432. // F'N: CApplicationUsersPage::OnSize
  433. //
  434. void CApplicationUsersPage::OnSize(UINT nType, int cx, int cy)
  435. {
  436. RECT rect;
  437. GetClientRect(&rect);
  438. rect.top += LIST_TOP_OFFSET;
  439. if(m_UserList.GetSafeHwnd())
  440. m_UserList.MoveWindow(&rect, TRUE);
  441. CFormView::OnSize(nType, cx, cy);
  442. } // end CApplicationUsersPage::OnSize
  443. //////////////////////////////
  444. // F'N: CApplicationUsersPage::Reset
  445. //
  446. void CApplicationUsersPage::Reset(void *pApplication)
  447. {
  448. m_pApplication = (CPublishedApp*)pApplication;
  449. DisplayUsers();
  450. } // end CApplicationUsersPage::Reset
  451. /////////////////////////////////////
  452. // F'N: CApplicationUsersPage::DisplayUsers
  453. //
  454. //
  455. void CApplicationUsersPage::DisplayUsers()
  456. {
  457. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  458. // Clear out the list control
  459. m_UserList.DeleteAllItems();
  460. pDoc->LockServerList();
  461. // Get a pointer to this document's list of Servers
  462. CObList *pServerList = pDoc->GetServerList();
  463. // Iterate through the Server list
  464. POSITION pos = pServerList->GetHeadPosition();
  465. while(pos) {
  466. CServer *pServer = (CServer*)pServerList->GetNext(pos);
  467. if(!pServer->IsState(SS_GOOD)) continue;
  468. // Loop through the WinStations on this server and
  469. // see if any are running this published app
  470. CObList *pWinStationList = pServer->GetWinStationList();
  471. pServer->LockWinStationList();
  472. POSITION pos2 = pWinStationList->GetHeadPosition();
  473. while(pos2) {
  474. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos2);
  475. if(pWinStation->IsActive()
  476. && pWinStation->HasUser()
  477. && pWinStation->IsRunningPublishedApp()
  478. && pWinStation->IsRunningPublishedApp(m_pApplication->GetName())) {
  479. AddUserToList(pWinStation);
  480. }
  481. } // end while(pos2)
  482. pServer->UnlockWinStationList();
  483. } // end while(pos)
  484. pDoc->UnlockServerList();
  485. SortByColumn(VIEW_APPLICATION, PAGE_APP_USERS, &m_UserList, m_CurrentSortColumn, m_bSortAscending);
  486. } // end CApplicationUsersPage::DisplayUsers
  487. //////////////////////////////
  488. // F'N: CApplicationUsersPage::UpdateWinStations
  489. //
  490. void CApplicationUsersPage::UpdateWinStations(CServer *pServer)
  491. {
  492. ASSERT(pServer);
  493. // If the server isn't in the list of servers for this application, there's
  494. // nothing to do
  495. if(!m_pApplication->FindServerByName(pServer->GetName())) return;
  496. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  497. BOOL bAnyChanges = FALSE;
  498. // Loop through the WinStations
  499. pServer->LockWinStationList();
  500. CObList *pWinStationList = pServer->GetWinStationList();
  501. POSITION pos = pWinStationList->GetHeadPosition();
  502. while(pos) {
  503. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos);
  504. LV_FINDINFO FindInfo;
  505. FindInfo.flags = LVFI_PARAM;
  506. FindInfo.lParam = (LPARAM)pWinStation;
  507. // Find the WinStation in our list
  508. int item = m_UserList.FindItem(&FindInfo, -1);
  509. // If user is not in the list
  510. if(item == -1) {
  511. // If the WinStation is not in the list but now has a user that is running
  512. // this published application, add it to the list
  513. if((pWinStation->IsCurrent() || pWinStation->IsNew())
  514. && pWinStation->HasUser()
  515. && pWinStation->IsRunningPublishedApp()
  516. && pWinStation->IsRunningPublishedApp(m_pApplication->GetName())) {
  517. AddUserToList(pWinStation);
  518. bAnyChanges = TRUE;
  519. continue;
  520. }
  521. // user is already in the list
  522. } else {
  523. // If the WinStation is no longer current,
  524. // remove it from the list
  525. if(!pWinStation->IsCurrent() || !pWinStation->HasUser()) {
  526. // Remove the WinStation from the list
  527. m_UserList.DeleteItem(item);
  528. pWinStation->ClearSelected();
  529. continue;
  530. }
  531. // If the WinStation info has changed, change
  532. // it's info in our tree
  533. if(pWinStation->IsChanged()) {
  534. PopulateUserColumns(item, pWinStation, FALSE);
  535. if(m_CurrentSortColumn != APP_USERS_COL_ID)
  536. bAnyChanges = TRUE;
  537. continue;
  538. }
  539. }
  540. }
  541. pServer->UnlockWinStationList();
  542. if(bAnyChanges) SortByColumn(VIEW_APPLICATION, PAGE_APP_USERS, &m_UserList, m_CurrentSortColumn, m_bSortAscending);
  543. } // end CApplicationUsersPage::UpdateWinStations
  544. //////////////////////////////
  545. // F'N: CApplicationUsersPage::AddUserToList
  546. //
  547. int CApplicationUsersPage::AddUserToList(CWinStation *pWinStation)
  548. {
  549. ASSERT(pWinStation);
  550. CServer *pServer = pWinStation->GetServer();
  551. LockListControl();
  552. //////////////////////
  553. // Fill in the columns
  554. //////////////////////
  555. // Server - put at the end of the list
  556. int item = m_UserList.InsertItem(m_UserList.GetItemCount(), pServer->GetName(),
  557. pWinStation->IsCurrentUser() ? m_idxCurrentUser : m_idxUser);
  558. PopulateUserColumns(item, pWinStation, TRUE);
  559. // Attach a pointer to the CWinStation structure to the list item
  560. m_UserList.SetItemData(item, (DWORD)pWinStation);
  561. UnlockListControl();
  562. return item;
  563. } // end CApplicationUsersPage::AddUserToList
  564. //////////////////////////////
  565. // F'N: CApplicationUsersPage::PopulateUserColumns
  566. //
  567. void CApplicationUsersPage::PopulateUserColumns(int item, CWinStation *pWinStation, BOOL newitem)
  568. {
  569. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  570. if(!newitem) {
  571. // User
  572. m_UserList.SetItemText(item, APP_USERS_COL_USER, pWinStation->GetUserName());
  573. }
  574. // WinStation Name
  575. if(pWinStation->GetName()[0])
  576. m_UserList.SetItemText(item, APP_USERS_COL_WINSTATION, pWinStation->GetName());
  577. else {
  578. CString NameString(" ");
  579. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  580. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  581. m_UserList.SetItemText(item, APP_USERS_COL_WINSTATION, NameString);
  582. }
  583. // Logon ID
  584. CString ColumnString;
  585. ColumnString.Format(TEXT("%lu"), pWinStation->GetLogonId());
  586. m_UserList.SetItemText(item, APP_USERS_COL_ID, ColumnString);
  587. // Connect State
  588. m_UserList.SetItemText(item, APP_USERS_COL_STATE, StrConnectState(pWinStation->GetState(), FALSE));
  589. // Idle Time
  590. TCHAR IdleTimeString[MAX_ELAPSED_TIME_LENGTH];
  591. ELAPSEDTIME IdleTime = pWinStation->GetIdleTime();
  592. if(IdleTime.days || IdleTime.hours || IdleTime.minutes || IdleTime.seconds)
  593. {
  594. ElapsedTimeString( &IdleTime, FALSE, IdleTimeString);
  595. }
  596. else wcscpy(IdleTimeString, TEXT("."));
  597. m_UserList.SetItemText(item, APP_USERS_COL_IDLETIME, IdleTimeString);
  598. // Logon Time
  599. TCHAR LogonTimeString[MAX_DATE_TIME_LENGTH];
  600. // We don't want to pass a 0 logon time to DateTimeString()
  601. // It will blow up if the timezone is GMT
  602. if(pWinStation->GetState() == State_Active && pWinStation->GetLogonTime().QuadPart) {
  603. DateTimeString(&(pWinStation->GetLogonTime()), LogonTimeString);
  604. pDoc->FixUnknownString(LogonTimeString);
  605. }
  606. else LogonTimeString[0] = '\0';
  607. m_UserList.SetItemText(item, APP_USERS_COL_LOGONTIME, LogonTimeString);
  608. } // end CApplicationUsersPage::PopulateUserColumns
  609. /////////////////////////////////////
  610. // F'N: CApplicationUsersPage::BuildImageList
  611. //
  612. // - calls m_imageList.Create(..) to create the image list
  613. // - calls AddIconToImageList(..) to add the icons themselves and save
  614. // off their indices
  615. // - attaches the image list to the list ctrl
  616. //
  617. void CApplicationUsersPage::BuildImageList()
  618. {
  619. m_imageList.Create(16, 16, TRUE, 2, 0);
  620. m_idxUser = AddIconToImageList(IDI_USER);
  621. m_idxCurrentUser = AddIconToImageList(IDI_CURRENT_USER);
  622. m_UserList.SetImageList(&m_imageList, LVSIL_SMALL);
  623. } // end CApplicationUsersPage::BuildImageList
  624. /////////////////////////////////////////
  625. // F'N: CApplicationUsersPage::AddIconToImageList
  626. //
  627. // - loads the appropriate icon, adds it to m_imageList, and returns
  628. // the newly-added icon's index in the image list
  629. //
  630. int CApplicationUsersPage::AddIconToImageList(int iconID)
  631. {
  632. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  633. return m_imageList.Add(hIcon);
  634. } // end CApplicationUsersPage::AddIconToImageList
  635. /////////////////////////////////////////
  636. // F'N: CApplicationUsersPage::OnSetfocusUserList
  637. //
  638. void CApplicationUsersPage::OnSetfocusUserList(NMHDR* pNMHDR, LRESULT* pResult)
  639. {
  640. // TODO: Add your control notification handler code here
  641. m_UserList.Invalidate();
  642. *pResult = 0;
  643. } // end CApplicationUsersPage::OnSetfocusUserList
  644. ////////////////////////////////
  645. // MESSAGE MAP: CApplicationInfoPage
  646. //
  647. IMPLEMENT_DYNCREATE(CApplicationInfoPage, CFormView)
  648. BEGIN_MESSAGE_MAP(CApplicationInfoPage, CFormView)
  649. //{{AFX_MSG_MAP(CApplicationInfoPage)
  650. ON_WM_SIZE()
  651. ON_NOTIFY(LVN_COLUMNCLICK, IDC_APPLICATION_SECURITY_LIST, OnColumnClick)
  652. ON_NOTIFY(NM_SETFOCUS, IDC_APPLICATION_SECURITY_LIST, OnSetfocusSecurityList)
  653. ON_COMMAND(ID_HELP, CWnd::OnHelp)
  654. ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
  655. ON_MESSAGE(WM_HELP, OnCommandHelp)
  656. //}}AFX_MSG_MAP
  657. END_MESSAGE_MAP()
  658. /////////////////////////////
  659. // F'N: CApplicationInfoPage ctor
  660. //
  661. CApplicationInfoPage::CApplicationInfoPage()
  662. : CAdminPage(CApplicationInfoPage::IDD)
  663. {
  664. //{{AFX_DATA_INIT(CApplicationInfoPage)
  665. //}}AFX_DATA_INIT
  666. m_pApplication = NULL;
  667. m_bSortAscending = TRUE;
  668. } // end CApplicationInfoPage ctor
  669. /////////////////////////////
  670. // F'N: CApplicationInfoPage dtor
  671. //
  672. CApplicationInfoPage::~CApplicationInfoPage()
  673. {
  674. } // end CApplicationInfoPage dtor
  675. ////////////////////////////////////////
  676. // F'N: CApplicationInfoPage::DoDataExchange
  677. //
  678. void CApplicationInfoPage::DoDataExchange(CDataExchange* pDX)
  679. {
  680. CFormView::DoDataExchange(pDX);
  681. //{{AFX_DATA_MAP(CApplicationInfoPage)
  682. DDX_Control(pDX, IDC_APPLICATION_SECURITY_LIST, m_SecurityList);
  683. //}}AFX_DATA_MAP
  684. } // end CApplicationInfoPage::DoDataExchange
  685. #ifdef _DEBUG
  686. /////////////////////////////////////
  687. // F'N: CApplicationInfoPage::AssertValid
  688. //
  689. void CApplicationInfoPage::AssertValid() const
  690. {
  691. CFormView::AssertValid();
  692. } // end CApplicationInfoPage::AssertValid
  693. //////////////////////////////
  694. // F'N: CApplicationInfoPage::Dump
  695. //
  696. void CApplicationInfoPage::Dump(CDumpContext& dc) const
  697. {
  698. CFormView::Dump(dc);
  699. } // end CApplicationInfoPage::Dump
  700. #endif //_DEBUG
  701. //////////////////////////////
  702. // F'N: CApplicationInfoPage::OnCommandHelp
  703. //
  704. void CApplicationInfoPage::OnCommandHelp(void)
  705. {
  706. AfxGetApp()->WinHelp(CApplicationInfoPage::IDD + HID_BASE_RESOURCE);
  707. } // end CApplicationInfoPage::OnCommandHelp
  708. static ColumnDef SecurityColumns[] = {
  709. { IDS_COL_USER_GROUP, LVCFMT_LEFT, 200 },
  710. { IDS_COL_USER_TYPE, LVCFMT_LEFT, 80 }
  711. };
  712. #define NUM_SECURITY_COLUMNS sizeof(SecurityColumns)/sizeof(ColumnDef)
  713. //////////////////////////////
  714. // F'N: CApplicationInfoPage::OnInitialUpdate
  715. //
  716. void CApplicationInfoPage::OnInitialUpdate()
  717. {
  718. CFormView::OnInitialUpdate();
  719. BuildImageList(); // builds the image list for the list control
  720. CString columnString;
  721. for(int col = 0; col < NUM_SECURITY_COLUMNS; col++) {
  722. columnString.LoadString(SecurityColumns[col].stringID);
  723. m_SecurityList.InsertColumn(col, columnString, SecurityColumns[col].format, SecurityColumns[col].width, col);
  724. }
  725. m_CurrentSortColumn = APP_SEC_COL_USERGROUP;
  726. } // end CApplicationInfoPage::OnInitialUpdate
  727. //////////////////////////////
  728. // F'N: CApplicationInfoPage::OnColumnClick
  729. //
  730. void CApplicationInfoPage::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
  731. {
  732. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  733. // TODO: Add your control notification handler code here
  734. // If the sort column hasn't changed, flip the ascending mode.
  735. if(m_CurrentSortColumn == pNMListView->iSubItem)
  736. m_bSortAscending = !m_bSortAscending;
  737. else // New sort column, start in ascending mode
  738. m_bSortAscending = TRUE;
  739. m_CurrentSortColumn = pNMListView->iSubItem;
  740. SortByColumn(VIEW_APPLICATION, PAGE_APP_INFO, &m_SecurityList, m_CurrentSortColumn, m_bSortAscending);
  741. *pResult = 0;
  742. } // end CApplicationInfoPage::OnColumnClick
  743. //////////////////////////////
  744. // F'N: CApplicationInfoPage::OnSize
  745. //
  746. void CApplicationInfoPage::OnSize(UINT nType, int cx, int cy)
  747. {
  748. RECT rect;
  749. GetWindowRect(&rect);
  750. CWnd *pWnd = GetDlgItem(IDC_APPUSERS_LABEL);
  751. if(pWnd) {
  752. RECT rect2;
  753. pWnd->GetWindowRect(&rect2);
  754. rect.top = rect2.bottom + 5;
  755. }
  756. ScreenToClient(&rect);
  757. if(m_SecurityList.GetSafeHwnd())
  758. m_SecurityList.MoveWindow(&rect, TRUE);
  759. CFormView::OnSize(nType, cx, cy);
  760. } // end CApplicationInfoPage::OnSize
  761. //////////////////////////////
  762. // F'N: CApplicationInfoPage::Reset
  763. //
  764. void CApplicationInfoPage::Reset(void *pApplication)
  765. {
  766. m_pApplication = (CPublishedApp*)pApplication;
  767. Display();
  768. } // end CApplicationInfoPage::Reset
  769. /////////////////////////////////////
  770. // F'N: CApplicationInfoPage::Display
  771. //
  772. //
  773. void CApplicationInfoPage::Display()
  774. {
  775. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  776. // Clear out the list control
  777. m_SecurityList.DeleteAllItems();
  778. // Application Type
  779. CString appString;
  780. appString.LoadString(m_pApplication->IsAnonymous() ? IDS_ANONYMOUS : IDS_EXPLICIT);
  781. SetDlgItemText(IDC_APP_TYPE, appString);
  782. // Hide Title Bar
  783. appString.LoadString(m_pApplication->IsTitleBarHidden() ? IDS_YES : IDS_NO);
  784. SetDlgItemText(IDC_HIDE_TITLE_BAR, appString);
  785. // Maximize Window
  786. appString.LoadString(m_pApplication->IsMaximize() ? IDS_YES : IDS_NO);
  787. SetDlgItemText(IDC_MAXIMIZE_WINDOW, appString);
  788. ////////////////////////////////////
  789. // Add users to list control
  790. ////////////////////////////////////
  791. m_pApplication->LockAllowedUserList();
  792. CObList *pList = m_pApplication->GetAllowedUserList();
  793. POSITION pos = pList->GetHeadPosition();
  794. while(pos) {
  795. CAppAllowed *pAppAllowed = (CAppAllowed*)pList->GetNext(pos);
  796. UINT stringID = IDS_USER;
  797. int image = USER_IMAGE;
  798. switch(pAppAllowed->GetType()) {
  799. case AAT_USER:
  800. stringID = IDS_USER;
  801. image = USER_IMAGE;
  802. break;
  803. case AAT_LOCAL_GROUP:
  804. stringID = IDS_LOCAL_GROUP;
  805. image = LOCAL_GROUP_IMAGE;
  806. break;
  807. case AAT_GLOBAL_GROUP:
  808. stringID = IDS_GLOBAL_GROUP;
  809. image = GLOBAL_GROUP_IMAGE;
  810. break;
  811. }
  812. int item = m_SecurityList.InsertItem(m_SecurityList.GetItemCount(), pAppAllowed->m_Name, image);
  813. CString userString;
  814. userString.LoadString(stringID);
  815. m_SecurityList.SetItemText(item, APP_SEC_COL_USERTYPE, userString);
  816. m_SecurityList.SetItemData(item, (DWORD)pAppAllowed);
  817. }
  818. m_pApplication->UnlockAllowedUserList();
  819. } // end CApplicationInfoPage::Display
  820. /////////////////////////////////////
  821. // F'N: CApplicationInfoPage::BuildImageList
  822. //
  823. // - calls m_imageList.Create(..) to create the image list
  824. // - calls AddIconToImageList(..) to add the icons themselves and save
  825. // off their indices
  826. // - attaches the image list to the list ctrl
  827. //
  828. void CApplicationInfoPage::BuildImageList()
  829. {
  830. m_imageList.Create(IDB_APP_USERS, 19, 0, RGB(255,255,255));
  831. m_SecurityList.SetImageList(&m_imageList, LVSIL_SMALL);
  832. } // end CApplicationInfoPage::BuildImageList
  833. /////////////////////////////////////////
  834. // F'N: CApplicationInfoPage::AddIconToImageList
  835. //
  836. // - loads the appropriate icon, adds it to m_imageList, and returns
  837. // the newly-added icon's index in the image list
  838. //
  839. int CApplicationInfoPage::AddIconToImageList(int iconID)
  840. {
  841. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  842. return m_imageList.Add(hIcon);
  843. } // end CApplicationaInfoPage::AddIconToImageList
  844. /////////////////////////////////////////
  845. // F'N: CApplicationInfoPage::OnSetfocusSecurityList
  846. //
  847. void CApplicationInfoPage::OnSetfocusSecurityList(NMHDR* pNMHDR, LRESULT* pResult)
  848. {
  849. // TODO: Add your control notification handler code here
  850. m_SecurityList.Invalidate();
  851. *pResult = 0;
  852. } // end CApplicationInfoPage::OnSetfocusSecurityList