Leaked source code of windows server 2003
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.

3166 lines
101 KiB

  1. /*******************************************************************************
  2. *
  3. * allsrvpg.cpp
  4. *
  5. * implementations of the All Servers 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\allsrvpg.cpp $
  13. *
  14. * Rev 1.8 19 Feb 1998 20:01:44 donm
  15. * removed latest extension DLL support
  16. *
  17. * Rev 1.7 19 Feb 1998 17:39:48 donm
  18. * removed latest extension DLL support
  19. *
  20. * Rev 1.6 15 Feb 1998 09:14:56 donm
  21. * update
  22. *
  23. * Rev 1.2 19 Jan 1998 17:36:06 donm
  24. * new ui behavior for domains and servers
  25. *
  26. * Rev 1.5 19 Jan 1998 16:45:34 donm
  27. * new ui behavior for domains and servers
  28. *
  29. * Rev 1.4 03 Nov 1997 15:18:28 donm
  30. * Added descending sort
  31. *
  32. * Rev 1.3 18 Oct 1997 18:49:38 donm
  33. * update
  34. *
  35. * Rev 1.2 13 Oct 1997 18:41:08 donm
  36. * update
  37. *
  38. * Rev 1.1 26 Aug 1997 19:13:56 donm
  39. * bug fixes/changes from WinFrame 1.7
  40. *
  41. * Rev 1.0 30 Jul 1997 17:10:18 butchd
  42. * Initial revision.
  43. *
  44. *******************************************************************************/
  45. #include "stdafx.h"
  46. #include "winadmin.h"
  47. #include "admindoc.h"
  48. #include "allsrvpg.h"
  49. #include <malloc.h> // for alloca used by Unicode conversion macros
  50. #include <mfc42\afxconv.h> // for Unicode conversion macros
  51. //USES_CONVERSION
  52. static int _convert;
  53. #ifdef _DEBUG
  54. #define new DEBUG_NEW
  55. #undef THIS_FILE
  56. static char THIS_FILE[] = __FILE__;
  57. #endif
  58. ////////////////////////////////
  59. // MESSAGE MAP: CAllServerServersPage
  60. //
  61. IMPLEMENT_DYNCREATE(CAllServerServersPage, CFormView)
  62. BEGIN_MESSAGE_MAP(CAllServerServersPage, CFormView)
  63. //{{AFX_MSG_MAP(CAllServerServersPage)
  64. ON_WM_SIZE()
  65. ON_NOTIFY(LVN_COLUMNCLICK, IDC_SERVER_LIST, OnColumnclick)
  66. ON_WM_CONTEXTMENU()
  67. ON_NOTIFY(LVN_ITEMCHANGED, IDC_SERVER_LIST, OnServerItemChanged)
  68. ON_NOTIFY(NM_SETFOCUS, IDC_SERVER_LIST, OnSetfocusServerList)
  69. //ON_NOTIFY( NM_KILLFOCUS , IDC_SERVER_LIST , OnKillfocusServerList )
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. /////////////////////////////
  73. // F'N: CAllServerServersPage ctor
  74. //
  75. CAllServerServersPage::CAllServerServersPage()
  76. : CAdminPage(CAllServerServersPage::IDD)
  77. {
  78. //{{AFX_DATA_INIT(CAllServerServersPage)
  79. // NOTE: the ClassWizard will add member initialization here
  80. //}}AFX_DATA_INIT
  81. m_bSortAscending = TRUE;
  82. } // end CAllServerServersPage ctor
  83. /////////////////////////////
  84. // F'N: CAllServerServersPage dtor
  85. //
  86. CAllServerServersPage::~CAllServerServersPage()
  87. {
  88. } // end CAllServerServersPage dtor
  89. ////////////////////////////////////////
  90. // F'N: CAllServerServersPage::DoDataExchange
  91. //
  92. void CAllServerServersPage::DoDataExchange(CDataExchange* pDX)
  93. {
  94. CFormView::DoDataExchange(pDX);
  95. //{{AFX_DATA_MAP(CAllServerServersPage)
  96. DDX_Control(pDX, IDC_SERVER_LIST, m_ServerList);
  97. //}}AFX_DATA_MAP
  98. } // end CAllServerServersPage::DoDataExchange
  99. #ifdef _DEBUG
  100. /////////////////////////////////////
  101. // F'N: CAllServerServersPage::AssertValid
  102. //
  103. void CAllServerServersPage::AssertValid() const
  104. {
  105. CFormView::AssertValid();
  106. } // end CAllServerServersPage::AssertValid
  107. //////////////////////////////
  108. // F'N: CAllServerServersPage::Dump
  109. //
  110. void CAllServerServersPage::Dump(CDumpContext& dc) const
  111. {
  112. CFormView::Dump(dc);
  113. } // end CAllServerServersPage::Dump
  114. #endif //_DEBUG
  115. //////////////////////////////
  116. // F'N: CAllServerServersPage::OnSize
  117. //
  118. void CAllServerServersPage::OnSize(UINT nType, int cx, int cy)
  119. {
  120. RECT rect;
  121. GetClientRect(&rect);
  122. rect.top += LIST_TOP_OFFSET;
  123. if(m_ServerList.GetSafeHwnd())
  124. m_ServerList.MoveWindow(&rect, TRUE);
  125. // CFormView::OnSize(nType, cx, cy);
  126. } // end CAllServerServersPage::OnSize
  127. static ColumnDef ServerColumns[] = {
  128. CD_SERVER,
  129. CD_TCPADDRESS,
  130. CD_IPXADDRESS,
  131. CD_NUM_SESSIONS
  132. };
  133. #define NUM_AS_SERVER_COLUMNS sizeof(ServerColumns)/sizeof(ColumnDef)
  134. //////////////////////////////
  135. // F'N: CAllServerServersPage::OnInitialUpdate
  136. //
  137. void CAllServerServersPage::OnInitialUpdate()
  138. {
  139. CFormView::OnInitialUpdate();
  140. BuildImageList(); // builds the image list for the list control
  141. CString columnString;
  142. for(int col = 0; col < NUM_AS_SERVER_COLUMNS; col++) {
  143. columnString.LoadString(ServerColumns[col].stringID);
  144. m_ServerList.InsertColumn(col, columnString, ServerColumns[col].format, ServerColumns[col].width, col);
  145. }
  146. m_CurrentSortColumn = SERVERS_COL_SERVER;
  147. } // end CAllServerServersPage::OnInitialUpdate
  148. /////////////////////////////////////
  149. // F'N: CAllServerServersPage::BuildImageList
  150. //
  151. // - calls m_ImageList.Create(..) to create the image list
  152. // - calls AddIconToImageList(..) to add the icons themselves and save
  153. // off their indices
  154. // - attaches the image list to the list ctrl
  155. //
  156. void CAllServerServersPage::BuildImageList()
  157. {
  158. m_ImageList.Create(16, 16, TRUE, 4, 0);
  159. m_idxServer = AddIconToImageList(IDI_SERVER);
  160. m_idxCurrentServer = AddIconToImageList(IDI_CURRENT_SERVER);
  161. m_idxNotSign = AddIconToImageList(IDI_NOTSIGN);
  162. m_idxQuestion = AddIconToImageList(IDI_QUESTIONMARK);
  163. m_ImageList.SetOverlayImage(m_idxNotSign, 1);
  164. m_ImageList.SetOverlayImage(m_idxQuestion, 2);
  165. m_ServerList.SetImageList(&m_ImageList, LVSIL_SMALL);
  166. } // end CAllServerServersPage::BuildImageList
  167. /////////////////////////////////////////
  168. // F'N: CAllServerServersPage::AddIconToImageList
  169. //
  170. // - loads the appropriate icon, adds it to m_ImageList, and returns
  171. // the newly-added icon's index in the image list
  172. //
  173. int CAllServerServersPage::AddIconToImageList(int iconID)
  174. {
  175. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  176. return m_ImageList.Add(hIcon);
  177. } // end CAllServerServersPage::AddIconToImageList
  178. //////////////////////////////
  179. // F'N: CAllServerServersPage::Reset
  180. //
  181. void CAllServerServersPage::Reset(void *p)
  182. {
  183. CTreeNode *pT = ( CTreeNode * )p;
  184. if( pT != NULL )
  185. {
  186. DisplayServers( pT->GetNodeType( ) );
  187. }
  188. else
  189. {
  190. DisplayServers( NODE_NONE );
  191. }
  192. } // end CAllServerServersPage::Reset
  193. //////////////////////////////
  194. // F'N: CAllServerServersPage::AddServer
  195. //
  196. void CAllServerServersPage::AddServer(CServer *pServer)
  197. {
  198. ASSERT(pServer);
  199. // We have to make sure the server isn't already in the list
  200. // Add the server to the list
  201. if(AddServerToList(pServer)) {
  202. // Tell the list to sort itself
  203. LockListControl();
  204. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_SERVERS, &m_ServerList, m_CurrentSortColumn, m_bSortAscending);
  205. UnlockListControl();
  206. }
  207. } // end CAllServerServersPage::AddServer
  208. //////////////////////////////
  209. // F'N: CAllServerServersPage::RemoveServer
  210. //
  211. void CAllServerServersPage::RemoveServer(CServer *pServer)
  212. {
  213. ASSERT(pServer);
  214. LockListControl();
  215. // Find out how many items in the list
  216. int ItemCount = m_ServerList.GetItemCount();
  217. // Go through the items are remove this server
  218. for(int item = 0; item < ItemCount; item++) {
  219. CServer *pListServer = (CServer*)m_ServerList.GetItemData(item);
  220. if(pListServer == pServer) {
  221. m_ServerList.DeleteItem(item);
  222. pServer->ClearAllSelected();
  223. break;
  224. }
  225. }
  226. UnlockListControl();
  227. } // end CAllServerServersPage::RemoveServer
  228. //////////////////////////////
  229. // F'N: CAllServerServersPage::UpdateServer
  230. //
  231. void CAllServerServersPage::UpdateServer(CServer *pServer)
  232. {
  233. ASSERT(pServer);
  234. // If we aren't connected to the server anymore, remove it from the list control
  235. if(pServer->IsState(SS_NOT_CONNECTED)) {
  236. RemoveServer(pServer);
  237. return;
  238. }
  239. // If we just connected to this server, add it to the list control
  240. if(pServer->IsState(SS_GOOD)) {
  241. AddServer(pServer);
  242. return;
  243. }
  244. LockListControl();
  245. // Find the Server in the list
  246. LV_FINDINFO FindInfo;
  247. FindInfo.flags = LVFI_PARAM;
  248. FindInfo.lParam = (LPARAM)pServer;
  249. // Find the Server in our list
  250. int item = m_ServerList.FindItem(&FindInfo, -1);
  251. if(item != -1) {
  252. // Change the icon overlay
  253. USHORT NewState;
  254. // Change the icon/overlay for the server
  255. // If the server isn't sane, put a not sign over the icon
  256. if(!pServer->IsServerSane()) NewState = STATE_NOT;
  257. // If we aren't done getting all the information about this server,
  258. // put a question mark over the icon
  259. else if(!pServer->IsState(SS_GOOD)) NewState = STATE_QUESTION;
  260. // If it is fine, we want to remove any overlays from the icon
  261. else NewState = STATE_NORMAL;
  262. // Set the tree item to the new state
  263. m_ServerList.SetItemState(item, NewState, 0x0F00);
  264. ExtServerInfo *pExtServerInfo = pServer->GetExtendedInfo();
  265. // TCP Address
  266. m_ServerList.SetItemText(item, SERVERS_COL_TCPADDRESS, pExtServerInfo->TcpAddress);
  267. // IPX Address
  268. m_ServerList.SetItemText(item, SERVERS_COL_IPXADDRESS, pExtServerInfo->IpxAddress);
  269. CString NumString;
  270. if(pExtServerInfo && (pExtServerInfo->Flags & ESF_WINFRAME)) {
  271. NumString.Format(TEXT("%lu"), pExtServerInfo->ServerTotalInUse);
  272. } else {
  273. NumString.LoadString(IDS_NOT_APPLICABLE);
  274. }
  275. m_ServerList.SetItemText(item, SERVERS_COL_NUMWINSTATIONS, NumString);
  276. }
  277. // Tell the list to sort itself
  278. if(m_CurrentSortColumn == SERVERS_COL_NUMWINSTATIONS
  279. || m_CurrentSortColumn == SERVERS_COL_TCPADDRESS
  280. || m_CurrentSortColumn == SERVERS_COL_IPXADDRESS)
  281. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_SERVERS, &m_ServerList, m_CurrentSortColumn, m_bSortAscending);
  282. UnlockListControl();
  283. } // end CAllServerServersPage::UpdateServer
  284. //////////////////////////////
  285. // F'N: CAllServerServersPage::AddServerToList
  286. //
  287. BOOL CAllServerServersPage::AddServerToList(CServer *pServer)
  288. {
  289. ASSERT(pServer);
  290. // If we aren't currently connected to the server, don't display it
  291. if(!pServer->IsState(SS_GOOD)) return FALSE;
  292. LockListControl();
  293. // Find the Server in the list
  294. LV_FINDINFO FindInfo;
  295. FindInfo.flags = LVFI_PARAM;
  296. FindInfo.lParam = (LPARAM)pServer;
  297. // Find the Server in our list
  298. int item = m_ServerList.FindItem(&FindInfo, -1);
  299. if(item != -1) return FALSE;
  300. //////////////////////
  301. // Fill in the columns
  302. //////////////////////
  303. // Name - put at the end of the list
  304. item = m_ServerList.InsertItem(m_ServerList.GetItemCount(), pServer->GetName(),
  305. pServer->IsCurrentServer() ? m_idxCurrentServer : m_idxServer);
  306. // If the server isn't sane, put a not sign over the icon
  307. if(!pServer->IsServerSane()) m_ServerList.SetItemState(item, STATE_NOT, 0x0F00);
  308. // If we aren't done getting all the information about this server,
  309. // put a question mark over the icon
  310. else if(!pServer->IsState(SS_GOOD)) m_ServerList.SetItemState(item, STATE_QUESTION, 0x0F00);
  311. ExtServerInfo *pExtServerInfo = pServer->GetExtendedInfo();
  312. // TCP Address
  313. m_ServerList.SetItemText(item, SERVERS_COL_TCPADDRESS, pExtServerInfo->TcpAddress);
  314. // IPX Address
  315. m_ServerList.SetItemText(item, SERVERS_COL_IPXADDRESS, pExtServerInfo->IpxAddress);
  316. // Connected
  317. CString NumString;
  318. if(pExtServerInfo && (pExtServerInfo->Flags & ESF_WINFRAME)) {
  319. NumString.Format(TEXT("%lu"), pExtServerInfo->ServerTotalInUse);
  320. } else {
  321. NumString.LoadString(IDS_NOT_APPLICABLE);
  322. }
  323. m_ServerList.SetItemText(item, SERVERS_COL_NUMWINSTATIONS, NumString);
  324. m_ServerList.SetItemData(item, (DWORD_PTR)pServer);
  325. UnlockListControl();
  326. return TRUE;
  327. } // end CAllServerServersPage::AddServerToList
  328. /////////////////////////////////////
  329. // F'N: CAllServerServersPage::DisplayServers
  330. //
  331. void CAllServerServersPage::DisplayServers( NODETYPE ntType )
  332. {
  333. LockListControl();
  334. // Clear out the list control
  335. m_ServerList.DeleteAllItems();
  336. // Get a pointer to our document
  337. CWinAdminDoc *doc = (CWinAdminDoc*)GetDocument();
  338. // Get a pointer to the list of servers
  339. doc->LockServerList();
  340. CObList *pServerList = doc->GetServerList();
  341. // Iterate through the Server list
  342. POSITION pos = pServerList->GetHeadPosition();
  343. while(pos)
  344. {
  345. CServer *pServer = (CServer*)pServerList->GetNext(pos);
  346. // check to see if its just for favorites
  347. if( ntType == NODE_FAV_LIST )
  348. {
  349. if( pServer->GetTreeItemFromFav() != NULL )
  350. {
  351. AddServerToList(pServer);
  352. }
  353. }
  354. else if( ntType == NODE_THIS_COMP )
  355. {
  356. if( pServer->GetTreeItemFromThisComputer( ) != NULL )
  357. {
  358. AddServerToList( pServer );
  359. }
  360. }
  361. else
  362. {
  363. AddServerToList(pServer);
  364. }
  365. } // end while(pos)
  366. doc->UnlockServerList();
  367. UnlockListControl();
  368. } // end CAllServerServersPage::DisplayServers
  369. //////////////////////////////
  370. // F'N: CAllServerServersPage::OnServerItemChanged
  371. //
  372. void CAllServerServersPage::OnServerItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
  373. {
  374. NM_LISTVIEW *pLV = (NM_LISTVIEW*)pNMHDR;
  375. // TODO: Add your control notification handler code here
  376. CServer *pServer = (CServer*)m_ServerList.GetItemData(pLV->iItem);
  377. if(pLV->uNewState & LVIS_SELECTED) {
  378. pServer->SetSelected();
  379. }
  380. if(pLV->uOldState & LVIS_SELECTED && !(pLV->uNewState & LVIS_SELECTED)) {
  381. pServer->ClearSelected();
  382. }
  383. *pResult = 0;
  384. } // end CAllServerServersPage::OnServerItemChanged
  385. //////////////////////////////
  386. // F'N: CAllServerServersPage::OnColumnclick
  387. //
  388. void CAllServerServersPage::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
  389. {
  390. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  391. // TODO: Add your control notification handler code here
  392. // If the sort column hasn't changed, flip the ascending mode.
  393. if(m_CurrentSortColumn == pNMListView->iSubItem)
  394. m_bSortAscending = !m_bSortAscending;
  395. else // New sort column, start in ascending mode
  396. m_bSortAscending = TRUE;
  397. m_CurrentSortColumn = pNMListView->iSubItem;
  398. LockListControl();
  399. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_SERVERS, &m_ServerList, m_CurrentSortColumn, m_bSortAscending);
  400. UnlockListControl();
  401. *pResult = 0;
  402. } // end CAllServerServersPage::OnColumnclick
  403. //////////////////////////////
  404. // F'N: CAllServerServersPage::OnContextMenu
  405. //
  406. void CAllServerServersPage::OnContextMenu(CWnd* pWnd, CPoint ptScreen)
  407. {
  408. // TODO: Add your message handler code here
  409. UINT flags;
  410. UINT Item;
  411. CPoint ptClient = ptScreen;
  412. ScreenToClient(&ptClient);
  413. // If we got here from the keyboard,
  414. if(ptScreen.x == -1 && ptScreen.y == -1) {
  415. UINT iCount = m_ServerList.GetItemCount( );
  416. RECT rc;
  417. for( Item = 0 ; Item < iCount ; Item++ )
  418. {
  419. if( m_ServerList.GetItemState( Item , LVIS_SELECTED ) == LVIS_SELECTED )
  420. {
  421. m_ServerList.GetItemRect( Item , &rc , LVIR_ICON );
  422. ptScreen.x = rc.left;
  423. ptScreen.y = rc.bottom + 5;
  424. ClientToScreen( &ptScreen );
  425. break;
  426. }
  427. }
  428. if(ptScreen.x == -1 && ptScreen.y == -1)
  429. {
  430. return;
  431. }
  432. /*
  433. RECT rect;
  434. m_ServerList.GetClientRect(&rect);
  435. ptScreen.x = (rect.right - rect.left) / 2;
  436. ptScreen.y = (rect.bottom - rect.top) / 2;
  437. ClientToScreen(&ptScreen);
  438. */
  439. }
  440. else {
  441. Item = m_ServerList.HitTest(ptClient, &flags);
  442. if((Item == 0xFFFFFFFF) || !(flags & LVHT_ONITEM))
  443. return;
  444. }
  445. CMenu menu;
  446. menu.LoadMenu(IDR_SERVER_POPUP);
  447. // set the temp selected item so that handler doesn't think
  448. // this came from the tree
  449. // Get a pointer to our document
  450. CWinAdminDoc *doc = (CWinAdminDoc*)GetDocument();
  451. doc->SetTreeTemp(NULL, NODE_NONE);
  452. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
  453. TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
  454. menu.DestroyMenu();
  455. } // end CAllServerServersPage::OnContextMenu
  456. ////////////////////////////////
  457. // MESSAGE MAP: CAllServerUsersPage
  458. //
  459. IMPLEMENT_DYNCREATE(CAllServerUsersPage, CFormView)
  460. BEGIN_MESSAGE_MAP(CAllServerUsersPage, CFormView)
  461. //{{AFX_MSG_MAP(CAllServerUsersPage)
  462. ON_WM_SIZE()
  463. ON_NOTIFY(LVN_COLUMNCLICK, IDC_USER_LIST, OnColumnclick)
  464. ON_NOTIFY(LVN_ITEMCHANGED, IDC_USER_LIST, OnUserItemChanged)
  465. ON_WM_CONTEXTMENU()
  466. ON_NOTIFY(NM_SETFOCUS, IDC_USER_LIST, OnSetfocusUserList)
  467. //ON_NOTIFY( NM_KILLFOCUS , IDC_USER_LIST , OnKillfocusUserList )
  468. // ON_WM_SETFOCUS( )
  469. //}}AFX_MSG_MAP
  470. END_MESSAGE_MAP()
  471. /////////////////////////////
  472. // F'N: CAllServerUsersPage ctor
  473. //
  474. CAllServerUsersPage::CAllServerUsersPage()
  475. : CAdminPage(CAllServerUsersPage::IDD)
  476. {
  477. //{{AFX_DATA_INIT(CAllServerUsersPage)
  478. // NOTE: the ClassWizard will add member initialization here
  479. //}}AFX_DATA_INIT
  480. m_bSortAscending = TRUE;
  481. } // end CAllServerUsersPage ctor
  482. /////////////////////////////
  483. // F'N: CAllServerUsersPage dtor
  484. //
  485. CAllServerUsersPage::~CAllServerUsersPage()
  486. {
  487. } // end CAllServerUsersPage dtor
  488. ////////////////////////////////////////
  489. // F'N: CAllServerUsersPage::DoDataExchange
  490. //
  491. void CAllServerUsersPage::DoDataExchange(CDataExchange* pDX)
  492. {
  493. CFormView::DoDataExchange(pDX);
  494. //{{AFX_DATA_MAP(CAllServerUsersPage)
  495. DDX_Control(pDX, IDC_USER_LIST, m_UserList);
  496. //}}AFX_DATA_MAP
  497. } // end CAllServerUsersPage::DoDataExchange
  498. #ifdef _DEBUG
  499. /////////////////////////////////////
  500. // F'N: CAllServerUsersPage::AssertValid
  501. //
  502. void CAllServerUsersPage::AssertValid() const
  503. {
  504. CFormView::AssertValid();
  505. } // end CAllServerUsersPage::AssertValid
  506. //////////////////////////////
  507. // F'N: CAllServerUsersPage::Dump
  508. //
  509. void CAllServerUsersPage::Dump(CDumpContext& dc) const
  510. {
  511. CFormView::Dump(dc);
  512. } // end CAllServerUsersPage::Dump
  513. #endif //_DEBUG
  514. //////////////////////////////
  515. // F'N: CAllServerUsersPage::OnSize
  516. //
  517. void CAllServerUsersPage::OnSize(UINT nType, int cx, int cy)
  518. {
  519. RECT rect;
  520. GetClientRect(&rect);
  521. rect.top += LIST_TOP_OFFSET;
  522. if(m_UserList.GetSafeHwnd())
  523. m_UserList.MoveWindow(&rect, TRUE);
  524. // CFormView::OnSize(nType, cx, cy);
  525. } // end CAllServerUsersPage::OnSize
  526. static ColumnDef UserColumns[] = {
  527. CD_SERVER,
  528. CD_USER3,
  529. CD_SESSION,
  530. CD_ID,
  531. CD_STATE,
  532. CD_IDLETIME,
  533. CD_LOGONTIME
  534. };
  535. #define NUM_AS_USER_COLUMNS sizeof(UserColumns)/sizeof(ColumnDef)
  536. //////////////////////////////
  537. // F'N: CAllServerUsersPage::OnInitialUpdate
  538. //
  539. void CAllServerUsersPage::OnInitialUpdate()
  540. {
  541. CFormView::OnInitialUpdate();
  542. BuildImageList(); // builds the image list for the list control
  543. CString columnString;
  544. for(int col = 0; col < NUM_AS_USER_COLUMNS; col++) {
  545. columnString.LoadString(UserColumns[col].stringID);
  546. m_UserList.InsertColumn(col, columnString, UserColumns[col].format, UserColumns[col].width, col);
  547. }
  548. m_CurrentSortColumn = AS_USERS_COL_SERVER;
  549. } // end CAllServerUsersPage::OnInitialUpdate
  550. //////////////////////////////
  551. // F'N: CAllServerUsersPage::OnUserItemChanged
  552. //
  553. void CAllServerUsersPage::OnUserItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
  554. {
  555. NM_LISTVIEW *pLV = (NM_LISTVIEW*)pNMHDR;
  556. if(pLV->uNewState & LVIS_SELECTED)
  557. {
  558. CWinStation *pWinStation = (CWinStation*)m_UserList.GetItemData(pLV->iItem);
  559. pWinStation->SetSelected();
  560. }
  561. if(pLV->uOldState & LVIS_SELECTED && !(pLV->uNewState & LVIS_SELECTED))
  562. {
  563. CWinStation *pWinStation = (CWinStation*)m_UserList.GetItemData(pLV->iItem);
  564. pWinStation->ClearSelected();
  565. }
  566. *pResult = 0;
  567. } // end CAllServerUsersPage::OnUserItemChanged
  568. /////////////////////////////////////
  569. // F'N: CAllServerUsersPage::BuildImageList
  570. //
  571. // - calls m_ImageList.Create(..) to create the image list
  572. // - calls AddIconToImageList(..) to add the icons themselves and save
  573. // off their indices
  574. // - attaches the image list to the list ctrl
  575. //
  576. void CAllServerUsersPage::BuildImageList()
  577. {
  578. m_ImageList.Create(16, 16, TRUE, 2, 0);
  579. m_idxUser = AddIconToImageList(IDI_USER);
  580. m_idxCurrentUser = AddIconToImageList(IDI_CURRENT_USER);
  581. m_UserList.SetImageList(&m_ImageList, LVSIL_SMALL);
  582. } // end CAllServerUsersPage::BuildImageList
  583. /////////////////////////////////////////
  584. // F'N: CAllServerUsersPage::AddIconToImageList
  585. //
  586. // - loads the appropriate icon, adds it to m_ImageList, and returns
  587. // the newly-added icon's index in the image list
  588. //
  589. int CAllServerUsersPage::AddIconToImageList(int iconID)
  590. {
  591. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  592. return m_ImageList.Add(hIcon);
  593. } // end CAllServerUsersPage::AddIconToImageList
  594. //////////////////////////////
  595. // F'N: CAllServerUsersPage::Reset
  596. //
  597. void CAllServerUsersPage::Reset(void *p)
  598. {
  599. CTreeNode *pT = ( CTreeNode * )p;
  600. if( pT != NULL )
  601. {
  602. DisplayUsers( pT->GetNodeType() );
  603. }
  604. else
  605. {
  606. DisplayUsers( NODE_NONE );
  607. }
  608. } // end CAllServerUsersPage::Reset
  609. //////////////////////////////
  610. // F'N: CAllServerUsersPage::AddServer
  611. //
  612. void CAllServerUsersPage::AddServer(CServer *pServer)
  613. {
  614. ASSERT(pServer);
  615. // Add the server's users to the list
  616. if(AddServerToList(pServer)) {
  617. // Sort the list
  618. LockListControl();
  619. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_USERS, &m_UserList, m_CurrentSortColumn, m_bSortAscending);
  620. UnlockListControl();
  621. }
  622. } // end CAllServerUsersPage::AddServer
  623. //////////////////////////////
  624. // F'N: CAllServerUsersPage::RemoveServer
  625. //
  626. void CAllServerUsersPage::RemoveServer(CServer *pServer)
  627. {
  628. ASSERT(pServer);
  629. LockListControl();
  630. int ItemCount = m_UserList.GetItemCount();
  631. // We need to go through the list backward so that we can remove
  632. // more than one item without the item numbers getting messed up
  633. for(int item = ItemCount; item; item--) {
  634. CWinStation *pWinStation = (CWinStation*)m_UserList.GetItemData(item-1);
  635. CServer *pListServer = pWinStation->GetServer();
  636. if(pListServer == pServer) {
  637. m_UserList.DeleteItem(item-1);
  638. pServer->ClearAllSelected();
  639. }
  640. }
  641. UnlockListControl();
  642. } // end CAllServerUsersPage::RemoveServer
  643. //////////////////////////////
  644. // F'N: CAllServerUsersPage::UpdateServer
  645. //
  646. void CAllServerUsersPage::UpdateServer(CServer *pServer)
  647. {
  648. ASSERT(pServer);
  649. if(pServer->IsState(SS_DISCONNECTING))
  650. RemoveServer(pServer);
  651. } // end CAllServerUsersPage::UpdateServer
  652. //////////////////////////////
  653. // F'N: CAllServerUsersPage::UpdateWinStations
  654. //
  655. void CAllServerUsersPage::UpdateWinStations(CServer *pServer)
  656. {
  657. ASSERT(pServer);
  658. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  659. BOOL bAnyChanged = FALSE;
  660. BOOL bAnyAdded = FALSE;
  661. // Loop through the WinStations
  662. pServer->LockWinStationList();
  663. CObList *pWinStationList = pServer->GetWinStationList();
  664. POSITION pos = pWinStationList->GetHeadPosition();
  665. while(pos) {
  666. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos);
  667. LV_FINDINFO FindInfo;
  668. FindInfo.flags = LVFI_PARAM;
  669. FindInfo.lParam = (LPARAM)pWinStation;
  670. // Find the WinStation in our list
  671. int item = m_UserList.FindItem(&FindInfo, -1);
  672. // If the WinStation is new and isn't currently in the list,
  673. // add it to the list
  674. if(pWinStation->IsNew() && pWinStation->HasUser() && item == -1) {
  675. AddUserToList(pWinStation);
  676. bAnyAdded = TRUE;
  677. continue;
  678. }
  679. // If the WinStation is no longer current,
  680. // remove it from the list
  681. if((!pWinStation->IsCurrent() || !pWinStation->HasUser()) && item != -1) {
  682. // Remove the WinStation from the list
  683. m_UserList.DeleteItem(item);
  684. pWinStation->ClearSelected();
  685. continue;
  686. }
  687. // If the WinStation info has changed, change
  688. // it's info in our tree
  689. if(pWinStation->IsChanged() && item != -1) {
  690. // change the user name
  691. m_UserList.SetItemText(item, AS_USERS_COL_USER, pWinStation->GetUserName());
  692. // change the WinStation Name
  693. if(pWinStation->GetName()[0])
  694. m_UserList.SetItemText(item, AS_USERS_COL_WINSTATION, pWinStation->GetName());
  695. else {
  696. CString NameString(" ");
  697. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  698. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  699. m_UserList.SetItemText(item, AS_USERS_COL_WINSTATION, NameString);
  700. }
  701. // change the Connect State
  702. m_UserList.SetItemText(item, AS_USERS_COL_STATE, StrConnectState(pWinStation->GetState(), FALSE));
  703. // change the Idle Time
  704. TCHAR IdleTimeString[MAX_ELAPSED_TIME_LENGTH];
  705. ELAPSEDTIME IdleTime = pWinStation->GetIdleTime();
  706. if(IdleTime.days || IdleTime.hours || IdleTime.minutes || IdleTime.seconds)
  707. {
  708. ElapsedTimeString( &IdleTime, FALSE, IdleTimeString);
  709. }
  710. else wcscpy(IdleTimeString, TEXT("."));
  711. m_UserList.SetItemText(item, AS_USERS_COL_IDLETIME, IdleTimeString);
  712. // change the Logon Time
  713. TCHAR LogonTimeString[MAX_DATE_TIME_LENGTH];
  714. // We don't want to pass a 0 logon time to DateTimeString()
  715. // It will blow up if the timezone is GMT
  716. if(pWinStation->GetState() == State_Active && pWinStation->GetLogonTime().QuadPart) {
  717. DateTimeString(&(pWinStation->GetLogonTime()), LogonTimeString);
  718. pDoc->FixUnknownString(LogonTimeString);
  719. }
  720. else LogonTimeString[0] = '\0';
  721. // change the
  722. m_UserList.SetItemText(item, AS_USERS_COL_LOGONTIME, LogonTimeString);
  723. if(m_CurrentSortColumn != AS_USERS_COL_ID)
  724. bAnyChanged = TRUE;
  725. continue;
  726. }
  727. // If the WinStation is not in the list but now has a user, add it to the list
  728. if(item == -1 && pWinStation->IsCurrent() && pWinStation->HasUser()) {
  729. AddUserToList(pWinStation);
  730. bAnyAdded = TRUE;
  731. }
  732. }
  733. pServer->UnlockWinStationList();
  734. if(bAnyChanged || bAnyAdded) SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_USERS, &m_UserList, m_CurrentSortColumn, m_bSortAscending);
  735. } // end CAllServerUsersPage::UpdateWinStations
  736. //////////////////////////////
  737. // F'N: CAllServerUsersPage::AddUserToList
  738. //
  739. int CAllServerUsersPage::AddUserToList(CWinStation *pWinStation)
  740. {
  741. ASSERT(pWinStation);
  742. CServer *pServer = pWinStation->GetServer();
  743. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  744. LockListControl();
  745. //////////////////////
  746. // Fill in the columns
  747. //////////////////////
  748. // Server - put at the end of the list
  749. int item = m_UserList.InsertItem(m_UserList.GetItemCount(), pServer->GetName(),
  750. pWinStation->IsCurrentUser() ? m_idxCurrentUser : m_idxUser);
  751. // User
  752. m_UserList.SetItemText(item, AS_USERS_COL_USER, pWinStation->GetUserName());
  753. // WinStation Name
  754. if(pWinStation->GetName()[0])
  755. m_UserList.SetItemText(item, AS_USERS_COL_WINSTATION, pWinStation->GetName());
  756. else {
  757. CString NameString(" ");
  758. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  759. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  760. m_UserList.SetItemText(item, AS_USERS_COL_WINSTATION, NameString);
  761. }
  762. // Logon ID
  763. CString ColumnString;
  764. ColumnString.Format(TEXT("%lu"), pWinStation->GetLogonId());
  765. m_UserList.SetItemText(item, AS_USERS_COL_ID, ColumnString);
  766. // Connect State
  767. m_UserList.SetItemText(item, AS_USERS_COL_STATE, StrConnectState(pWinStation->GetState(), FALSE));
  768. // Idle Time
  769. TCHAR IdleTimeString[MAX_ELAPSED_TIME_LENGTH];
  770. ELAPSEDTIME IdleTime = pWinStation->GetIdleTime();
  771. if(IdleTime.days || IdleTime.hours || IdleTime.minutes || IdleTime.seconds)
  772. {
  773. ElapsedTimeString( &IdleTime, FALSE, IdleTimeString);
  774. }
  775. else wcscpy(IdleTimeString, TEXT("."));
  776. m_UserList.SetItemText(item, AS_USERS_COL_IDLETIME, IdleTimeString);
  777. // Logon Time
  778. TCHAR LogonTimeString[MAX_DATE_TIME_LENGTH];
  779. // We don't want to pass a 0 logon time to DateTimeString()
  780. // It will blow up if the timezone is GMT
  781. if(pWinStation->GetState() == State_Active && pWinStation->GetLogonTime().QuadPart) {
  782. DateTimeString(&(pWinStation->GetLogonTime()), LogonTimeString);
  783. pDoc->FixUnknownString(LogonTimeString);
  784. }
  785. else LogonTimeString[0] = '\0';
  786. m_UserList.SetItemText(item, AS_USERS_COL_LOGONTIME, LogonTimeString);
  787. // Attach a pointer to the CWinStation structure to the list item
  788. m_UserList.SetItemData(item, (DWORD_PTR)pWinStation);
  789. //bug #191727
  790. //m_UserList.SetItemState( 0 , LVIS_FOCUSED | LVIS_SELECTED , LVIS_FOCUSED | LVIS_SELECTED );
  791. UnlockListControl();
  792. return item;
  793. } // end CAllServerUsersPage::AddUserToList
  794. //////////////////////////////
  795. // F'N: CAllServerUsersPage::AddServerToList
  796. //
  797. BOOL CAllServerUsersPage::AddServerToList(CServer *pServer)
  798. {
  799. ASSERT(pServer);
  800. pServer->LockWinStationList();
  801. // Get a pointer to this server's list of WinStations
  802. CObList *pWinStationList = pServer->GetWinStationList();
  803. // Iterate through the WinStation list
  804. POSITION pos = pWinStationList->GetHeadPosition();
  805. while(pos) {
  806. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos);
  807. // only show the WinStation if it has a user
  808. if(pWinStation->HasUser()) {
  809. AddUserToList(pWinStation);
  810. }
  811. } // end while(pos)
  812. pServer->UnlockWinStationList();
  813. return TRUE;
  814. } // end CAllServerUsersPage::AddServerToList
  815. //////////////////////////////
  816. // F'N: CAllServerUsersPage::OnColumnclick
  817. //
  818. void CAllServerUsersPage::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
  819. {
  820. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  821. // TODO: Add your control notification handler code here
  822. // If the sort column hasn't changed, flip the ascending mode.
  823. if(m_CurrentSortColumn == pNMListView->iSubItem)
  824. m_bSortAscending = !m_bSortAscending;
  825. else // New sort column, start in ascending mode
  826. m_bSortAscending = TRUE;
  827. m_CurrentSortColumn = pNMListView->iSubItem;
  828. LockListControl();
  829. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_USERS, &m_UserList, m_CurrentSortColumn, m_bSortAscending);
  830. UnlockListControl();
  831. *pResult = 0;
  832. } // end CAllServerUsersPage::OnColumnclick
  833. //////////////////////////////
  834. // F'N: CAllServerUsersPage::OnContextMenu
  835. //
  836. void CAllServerUsersPage::OnContextMenu(CWnd* pWnd, CPoint ptScreen)
  837. {
  838. // TODO: Add your message handler code here
  839. UINT flags;
  840. UINT Item;
  841. CPoint ptClient = ptScreen;
  842. ScreenToClient(&ptClient);
  843. // If we got here from the keyboard,
  844. if(ptScreen.x == -1 && ptScreen.y == -1) {
  845. UINT iCount = m_UserList.GetItemCount( );
  846. RECT rc;
  847. for( Item = 0 ; Item < iCount ; Item++ )
  848. {
  849. if( m_UserList.GetItemState( Item , LVIS_SELECTED ) == LVIS_SELECTED )
  850. {
  851. m_UserList.GetItemRect( Item , &rc , LVIR_ICON );
  852. ptScreen.x = rc.left;
  853. ptScreen.y = rc.bottom + 5;
  854. ClientToScreen( &ptScreen );
  855. break;
  856. }
  857. }
  858. if(ptScreen.x == -1 && ptScreen.y == -1)
  859. {
  860. return;
  861. }
  862. /*
  863. RECT rect;
  864. m_UserList.GetClientRect(&rect);
  865. ptScreen.x = (rect.right - rect.left) / 2;
  866. ptScreen.y = (rect.bottom - rect.top) / 2;
  867. ClientToScreen(&ptScreen);
  868. */
  869. }
  870. else {
  871. Item = m_UserList.HitTest(ptClient, &flags);
  872. if((Item == 0xFFFFFFFF) || !(flags & LVHT_ONITEM))
  873. {
  874. //
  875. // ListView HitTest bug? return -1 but item display as selected.
  876. // workaround for now, Al can fix this later
  877. //
  878. UINT iCount = m_UserList.GetItemCount( );
  879. RECT rc;
  880. for( Item = 0 ; Item < iCount ; Item++ )
  881. {
  882. if( m_UserList.GetItemState( Item , LVIS_SELECTED ) == LVIS_SELECTED )
  883. {
  884. break;
  885. }
  886. }
  887. if( Item >= iCount )
  888. {
  889. return;
  890. }
  891. }
  892. //
  893. // NM_RCLICK (WM_NOTIFY) then WM_CNTEXTMENU but no NM_ITEMCHANGED message
  894. // manually set it to selected state
  895. //
  896. CWinStation *pWinStation = (CWinStation*)m_UserList.GetItemData(Item);
  897. if( !pWinStation )
  898. return;
  899. if( m_UserList.GetItemState( Item , LVIS_SELECTED ) == LVIS_SELECTED )
  900. {
  901. pWinStation->SetSelected();
  902. }
  903. }
  904. CMenu menu;
  905. menu.LoadMenu(IDR_USER_POPUP);
  906. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
  907. TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
  908. menu.DestroyMenu();
  909. } // end CAllServerUsersPage::OnContextMenu
  910. /////////////////////////////////////
  911. // F'N: CAllServerUsersPage::DisplayUsers
  912. //
  913. void CAllServerUsersPage::DisplayUsers( NODETYPE ntType )
  914. {
  915. LockListControl();
  916. // Clear out the list control
  917. m_UserList.DeleteAllItems();
  918. // Get a pointer to the document's list of servers
  919. CObList* pServerList = ((CWinAdminDoc*)GetDocument())->GetServerList();
  920. ((CWinAdminDoc*)GetDocument())->LockServerList();
  921. // Iterate through the server list
  922. POSITION pos2 = pServerList->GetHeadPosition();
  923. while(pos2)
  924. {
  925. CServer *pServer = (CServer*)pServerList->GetNext(pos2);
  926. if( ntType == NODE_FAV_LIST )
  927. {
  928. if( pServer->GetTreeItemFromFav() != NULL )
  929. {
  930. AddServerToList(pServer);
  931. }
  932. }
  933. else if( ntType == NODE_THIS_COMP )
  934. {
  935. if( pServer->GetTreeItemFromThisComputer() != NULL )
  936. {
  937. AddServerToList(pServer);
  938. }
  939. }
  940. else
  941. {
  942. AddServerToList( pServer );
  943. }
  944. } // end while(pos2)
  945. ((CWinAdminDoc*)GetDocument())->UnlockServerList();
  946. UnlockListControl();
  947. } // end CAllServerUsersPage::DisplayUsers
  948. /////////////////////////////////////
  949. // F'N: CAllServerUsersPage::ClearSelections
  950. //
  951. void CAllServerUsersPage::ClearSelections()
  952. {
  953. if(m_UserList.m_hWnd != NULL)
  954. {
  955. POSITION pos = m_UserList.GetFirstSelectedItemPosition();
  956. while (pos)
  957. {
  958. int nItem = m_UserList.GetNextSelectedItem(pos);
  959. // you could do your own processing on nItem here
  960. m_UserList.SetItemState(nItem,0,LVIS_SELECTED);
  961. }
  962. }
  963. }
  964. ////////////////////////////////
  965. // MESSAGE MAP: CAllServerWinStationsPage
  966. //
  967. IMPLEMENT_DYNCREATE(CAllServerWinStationsPage, CFormView)
  968. BEGIN_MESSAGE_MAP(CAllServerWinStationsPage, CFormView)
  969. //{{AFX_MSG_MAP(CAllServerWinStationsPage)
  970. ON_WM_SIZE()
  971. ON_NOTIFY(LVN_COLUMNCLICK, IDC_WINSTATION_LIST, OnColumnclick)
  972. ON_NOTIFY(LVN_ITEMCHANGED, IDC_WINSTATION_LIST, OnWinStationItemChanged)
  973. ON_WM_CONTEXTMENU()
  974. ON_NOTIFY(NM_SETFOCUS, IDC_WINSTATION_LIST, OnSetfocusWinstationList)
  975. //ON_NOTIFY( NM_KILLFOCUS , IDC_WINSTATION_LIST , OnKillfocusWinstationList )
  976. //}}AFX_MSG_MAP
  977. END_MESSAGE_MAP()
  978. /////////////////////////////
  979. // F'N: CAllServerWinStationsPage ctor
  980. //
  981. CAllServerWinStationsPage::CAllServerWinStationsPage()
  982. : CAdminPage(CAllServerWinStationsPage::IDD)
  983. {
  984. //{{AFX_DATA_INIT(CAllServerWinStationsPage)
  985. // NOTE: the ClassWizard will add member initialization here
  986. //}}AFX_DATA_INIT
  987. m_bSortAscending = TRUE;
  988. } // end CAllServerWinStationsPage ctor
  989. /////////////////////////////
  990. // F'N: CAllServerWinStationsPage dtor
  991. //
  992. CAllServerWinStationsPage::~CAllServerWinStationsPage()
  993. {
  994. } // end CAllServerWinStationsPage dtor
  995. ////////////////////////////////////////
  996. // F'N: CAllServerWinStationsPage::DoDataExchange
  997. //
  998. void CAllServerWinStationsPage::DoDataExchange(CDataExchange* pDX)
  999. {
  1000. CFormView::DoDataExchange(pDX);
  1001. //{{AFX_DATA_MAP(CAllServerWinStationsPage)
  1002. DDX_Control(pDX, IDC_WINSTATION_LIST, m_StationList);
  1003. //}}AFX_DATA_MAP
  1004. } // end CAllServerWinStationsPage::DoDataExchange
  1005. #ifdef _DEBUG
  1006. /////////////////////////////////////
  1007. // F'N: CAllServerWinStationsPage::AssertValid
  1008. //
  1009. void CAllServerWinStationsPage::AssertValid() const
  1010. {
  1011. CFormView::AssertValid();
  1012. } // end CAllServerWinStationsPage::AssertValid
  1013. //////////////////////////////
  1014. // F'N: CAllServerWinStationsPage::Dump
  1015. //
  1016. void CAllServerWinStationsPage::Dump(CDumpContext& dc) const
  1017. {
  1018. CFormView::Dump(dc);
  1019. } // end CAllServerWinStationsPage::Dump
  1020. #endif //_DEBUG
  1021. ////////////////////////////////////////
  1022. // F'N: CAllServerWinStationsPage::OnWinStationItemChanged
  1023. //
  1024. void CAllServerWinStationsPage::OnWinStationItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
  1025. {
  1026. NM_LISTVIEW *pLV = (NM_LISTVIEW*)pNMHDR;
  1027. if(pLV->uNewState & LVIS_SELECTED)
  1028. {
  1029. CWinStation *pWinStation = (CWinStation*)m_StationList.GetItemData(pLV->iItem);
  1030. pWinStation->SetSelected();
  1031. }
  1032. if(pLV->uOldState & LVIS_SELECTED && !(pLV->uNewState & LVIS_SELECTED))
  1033. {
  1034. CWinStation *pWinStation = (CWinStation*)m_StationList.GetItemData(pLV->iItem);
  1035. pWinStation->ClearSelected();
  1036. }
  1037. *pResult = 0;
  1038. } // end CAllServerWinStationsPage::OnWinStationItemChanged
  1039. ////////////////////////////////////////
  1040. // F'N: CAllServerWinStationsPage::OnSize
  1041. //
  1042. void CAllServerWinStationsPage::OnSize(UINT nType, int cx, int cy)
  1043. {
  1044. RECT rect;
  1045. GetClientRect(&rect);
  1046. rect.top += LIST_TOP_OFFSET;
  1047. if(m_StationList.GetSafeHwnd())
  1048. m_StationList.MoveWindow(&rect, TRUE);
  1049. // CFormView::OnSize(nType, cx, cy);
  1050. } // end CAllServerWinStationsPage::OnSize
  1051. static ColumnDef WinsColumns[] = {
  1052. CD_SERVER,
  1053. CD_SESSION2,
  1054. CD_USER2,
  1055. CD_ID,
  1056. CD_STATE,
  1057. CD_TYPE,
  1058. CD_CLIENT_NAME,
  1059. CD_IDLETIME,
  1060. CD_LOGONTIME,
  1061. CD_COMMENT
  1062. };
  1063. #define NUM_AS_WINS_COLUMNS sizeof(WinsColumns)/sizeof(ColumnDef)
  1064. ////////////////////////////////////////
  1065. // F'N: CAllServerWinStationsPage::OnInitialUpdate
  1066. //
  1067. void CAllServerWinStationsPage::OnInitialUpdate()
  1068. {
  1069. // Call the parent class
  1070. CFormView::OnInitialUpdate();
  1071. // builds the image list for the list control
  1072. BuildImageList();
  1073. // Add the column headings
  1074. CString columnString;
  1075. for(int col = 0; col < NUM_AS_WINS_COLUMNS; col++) {
  1076. columnString.LoadString(WinsColumns[col].stringID);
  1077. m_StationList.InsertColumn(col, columnString, WinsColumns[col].format, WinsColumns[col].width, col);
  1078. }
  1079. m_CurrentSortColumn = AS_WS_COL_SERVER;
  1080. } // end CAllServerWinStationsPage::OnInitialUpdate
  1081. /////////////////////////////////////
  1082. // F'N: CAllServerWinStationsPage::BuildImageList
  1083. //
  1084. // - calls m_ImageList.Create(..) to create the image list
  1085. // - calls AddIconToImageList(..) to add the icons themselves and save
  1086. // off their indices
  1087. // - attaches the image list to the list ctrl
  1088. //
  1089. void CAllServerWinStationsPage::BuildImageList()
  1090. {
  1091. m_ImageList.Create(16, 16, TRUE, 11, 0);
  1092. m_idxBlank = AddIconToImageList(IDI_BLANK);
  1093. m_idxCitrix = AddIconToImageList(IDR_MAINFRAME);
  1094. m_idxServer = AddIconToImageList(IDI_SERVER);
  1095. m_idxConsole = AddIconToImageList(IDI_CONSOLE);
  1096. m_idxNet = AddIconToImageList(IDI_NET);
  1097. m_idxAsync = AddIconToImageList(IDI_ASYNC);
  1098. m_idxCurrentConsole = AddIconToImageList(IDI_CURRENT_CONSOLE);
  1099. m_idxCurrentNet = AddIconToImageList(IDI_CURRENT_NET);
  1100. m_idxCurrentAsync = AddIconToImageList(IDI_CURRENT_ASYNC);
  1101. m_idxDirectAsync = AddIconToImageList(IDI_DIRECT_ASYNC);
  1102. m_idxCurrentDirectAsync = AddIconToImageList(IDI_CURRENT_DIRECT_ASYNC);
  1103. m_StationList.SetImageList(&m_ImageList, LVSIL_SMALL);
  1104. } // end CAllServerWinStationsPage::BuildImageList
  1105. /////////////////////////////////////////
  1106. // F'N: CAllServerWinStationsPage::AddIconToImageList
  1107. //
  1108. // - loads the appropriate icon, adds it to m_ImageList, and returns
  1109. // the newly-added icon's index in the image list
  1110. //
  1111. int CAllServerWinStationsPage::AddIconToImageList(int iconID)
  1112. {
  1113. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  1114. return m_ImageList.Add(hIcon);
  1115. } // end CAllServerWinStationsPage::AddIconToImageList
  1116. ////////////////////////////////////////
  1117. // F'N: CAllServerWinStationsPage::Reset
  1118. //
  1119. void CAllServerWinStationsPage::Reset(void *p)
  1120. {
  1121. CTreeNode *pT = ( CTreeNode * )p;
  1122. if( pT != NULL )
  1123. {
  1124. DisplayStations( pT->GetNodeType( ) );
  1125. }
  1126. else
  1127. {
  1128. DisplayStations( NODE_NONE );
  1129. }
  1130. } // end CAllServerWinStationsPage::Reset
  1131. ////////////////////////////////////////
  1132. // F'N: CAllServerWinStationsPage::AddServer
  1133. //
  1134. void CAllServerWinStationsPage::AddServer(CServer *pServer)
  1135. {
  1136. ASSERT(pServer);
  1137. // Add server's WinStations to the list
  1138. if(AddServerToList(pServer)) {
  1139. // Sort the list
  1140. LockListControl();
  1141. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_WINSTATIONS, &m_StationList, m_CurrentSortColumn, m_bSortAscending);
  1142. UnlockListControl();
  1143. }
  1144. } // end CAllServerWinStationsPage::AddServer
  1145. ////////////////////////////////////////
  1146. // F'N: CAllServerWinStationsPage::RemoveServer
  1147. //
  1148. void CAllServerWinStationsPage::RemoveServer(CServer *pServer)
  1149. {
  1150. ASSERT(pServer);
  1151. LockListControl();
  1152. int ItemCount = m_StationList.GetItemCount();
  1153. // We need to go through the list backward so that we can remove
  1154. // more than one item without the item numbers getting messed up
  1155. for(int item = ItemCount; item; item--) {
  1156. CWinStation *pWinStation = (CWinStation*)m_StationList.GetItemData(item-1);
  1157. CServer *pListServer = pWinStation->GetServer();
  1158. if(pListServer == pServer) {
  1159. m_StationList.DeleteItem(item-1);
  1160. pServer->ClearAllSelected();
  1161. }
  1162. }
  1163. UnlockListControl();
  1164. } // end CAllServerWinStationsPage::RemoveServer
  1165. //////////////////////////////
  1166. // F'N: CAllServerWinStationsPage::UpdateServer
  1167. //
  1168. void CAllServerWinStationsPage::UpdateServer(CServer *pServer)
  1169. {
  1170. ASSERT(pServer);
  1171. if(pServer->IsState(SS_DISCONNECTING))
  1172. RemoveServer(pServer);
  1173. } // end CAllServerWinStationsPage::UpdateServer
  1174. ////////////////////////////////////////
  1175. // F'N: CAllServerWinStationsPage::UpdateWinStations
  1176. //
  1177. void CAllServerWinStationsPage::UpdateWinStations(CServer *pServer)
  1178. {
  1179. ASSERT(pServer);
  1180. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  1181. BOOL bAnyChanged = FALSE;
  1182. BOOL bAnyAdded = FALSE;
  1183. // Loop through the WinStations
  1184. pServer->LockWinStationList();
  1185. CObList *pWinStationList = pServer->GetWinStationList();
  1186. POSITION pos = pWinStationList->GetHeadPosition();
  1187. while(pos) {
  1188. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos);
  1189. LV_FINDINFO FindInfo;
  1190. FindInfo.flags = LVFI_PARAM;
  1191. FindInfo.lParam = (LPARAM)pWinStation;
  1192. // Find the WinStation in our list
  1193. int item = m_StationList.FindItem(&FindInfo, -1);
  1194. // If the process is new and isn't currently in the list,
  1195. // add it to the list
  1196. if(pWinStation->IsNew() && item == -1) {
  1197. AddWinStationToList(pWinStation);
  1198. bAnyAdded = TRUE;
  1199. continue;
  1200. }
  1201. // If the WinStation is no longer current,
  1202. // remove it from the list
  1203. if(!pWinStation->IsCurrent() && item != -1) {
  1204. // Remove the WinStation from the list
  1205. m_StationList.DeleteItem(item);
  1206. pWinStation->ClearSelected();
  1207. continue;
  1208. }
  1209. // If the WinStation info has changed, change
  1210. // it's info in our tree
  1211. if(pWinStation->IsChanged() && item != -1) {
  1212. // Figure out which icon to use
  1213. int WhichIcon = m_idxBlank;
  1214. BOOL CurrentWinStation = pWinStation->IsCurrentWinStation();
  1215. if(pWinStation->GetState() != State_Disconnected
  1216. && pWinStation->GetState() != State_Idle) {
  1217. switch(pWinStation->GetSdClass()) {
  1218. case SdAsync:
  1219. if(pWinStation->IsDirectAsync())
  1220. WhichIcon = CurrentWinStation ? m_idxCurrentDirectAsync : m_idxDirectAsync;
  1221. else
  1222. WhichIcon = CurrentWinStation ? m_idxCurrentAsync : m_idxAsync;
  1223. break;
  1224. case SdNetwork:
  1225. WhichIcon = CurrentWinStation ? m_idxCurrentNet : m_idxNet;
  1226. break;
  1227. default:
  1228. WhichIcon = CurrentWinStation ? m_idxCurrentConsole : m_idxConsole;
  1229. break;
  1230. }
  1231. }
  1232. m_StationList.SetItem(item, 0, LVIF_IMAGE, 0, WhichIcon, 0, 0, 0L);
  1233. // WinStation Name
  1234. if(pWinStation->GetName()[0])
  1235. m_StationList.SetItemText(item, AS_WS_COL_WINSTATION, pWinStation->GetName());
  1236. else {
  1237. CString NameString(" ");
  1238. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  1239. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  1240. m_StationList.SetItemText(item, AS_WS_COL_WINSTATION, NameString);
  1241. }
  1242. // User
  1243. m_StationList.SetItemText(item, AS_WS_COL_USER, pWinStation->GetUserName());
  1244. // Logon ID
  1245. CString ColumnString;
  1246. ColumnString.Format(TEXT("%lu"), pWinStation->GetLogonId());
  1247. m_StationList.SetItemText(item, AS_WS_COL_ID, ColumnString);
  1248. // Connect State
  1249. m_StationList.SetItemText(item, AS_WS_COL_STATE, StrConnectState(pWinStation->GetState(), FALSE));
  1250. // Type
  1251. m_StationList.SetItemText(item, AS_WS_COL_TYPE, pWinStation->GetWdName());
  1252. // Client Name
  1253. m_StationList.SetItemText(item, AS_WS_COL_CLIENTNAME, pWinStation->GetClientName());
  1254. // Idle Time
  1255. TCHAR IdleTimeString[MAX_ELAPSED_TIME_LENGTH];
  1256. ELAPSEDTIME IdleTime = pWinStation->GetIdleTime();
  1257. if(IdleTime.days || IdleTime.hours || IdleTime.minutes || IdleTime.seconds)
  1258. {
  1259. ElapsedTimeString( &IdleTime, FALSE, IdleTimeString);
  1260. }
  1261. else wcscpy(IdleTimeString, TEXT("."));
  1262. m_StationList.SetItemText(item, AS_WS_COL_IDLETIME, IdleTimeString);
  1263. // Logon Time
  1264. TCHAR LogonTimeString[MAX_DATE_TIME_LENGTH];
  1265. // We don't want to pass a 0 logon time to DateTimeString()
  1266. // It will blow up if the timezone is GMT
  1267. if(pWinStation->GetState() == State_Active && pWinStation->GetLogonTime().QuadPart) {
  1268. DateTimeString(&(pWinStation->GetLogonTime()), LogonTimeString);
  1269. pDoc->FixUnknownString(LogonTimeString);
  1270. }
  1271. else LogonTimeString[0] = '\0';
  1272. m_StationList.SetItemText(item, AS_WS_COL_LOGONTIME, LogonTimeString);
  1273. // Comment
  1274. m_StationList.SetItemText(item, AS_WS_COL_COMMENT, pWinStation->GetComment());
  1275. if(m_CurrentSortColumn != AS_WS_COL_ID)
  1276. bAnyChanged = TRUE;
  1277. }
  1278. }
  1279. pServer->UnlockWinStationList();
  1280. if(bAnyChanged || bAnyAdded) SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_WINSTATIONS, &m_StationList, m_CurrentSortColumn, m_bSortAscending);
  1281. } // end CAllServerWinStationsPage::UpdateWinStations
  1282. ////////////////////////////////////////
  1283. // F'N: CAllServerWinStationsPage::AddWinStationToList
  1284. //
  1285. int CAllServerWinStationsPage::AddWinStationToList(CWinStation *pWinStation)
  1286. {
  1287. ASSERT(pWinStation);
  1288. CServer *pServer = pWinStation->GetServer();
  1289. CWinAdminDoc *pDoc = (CWinAdminDoc*)((CWinAdminApp*)AfxGetApp())->GetDocument();
  1290. // Figure out which icon to use
  1291. int WhichIcon = m_idxBlank;
  1292. BOOL bCurrentWinStation = pWinStation->IsCurrentWinStation();
  1293. if(pWinStation->GetState() != State_Disconnected
  1294. && pWinStation->GetState() != State_Idle) {
  1295. switch(pWinStation->GetSdClass()) {
  1296. case SdAsync:
  1297. if(pWinStation->IsDirectAsync())
  1298. WhichIcon = bCurrentWinStation ? m_idxCurrentDirectAsync : m_idxDirectAsync;
  1299. else
  1300. WhichIcon = bCurrentWinStation ? m_idxCurrentAsync : m_idxAsync;
  1301. break;
  1302. case SdNetwork:
  1303. WhichIcon = bCurrentWinStation ? m_idxCurrentNet : m_idxNet;
  1304. break;
  1305. default:
  1306. WhichIcon = bCurrentWinStation ? m_idxCurrentConsole : m_idxConsole;
  1307. break;
  1308. }
  1309. }
  1310. LockListControl();
  1311. //////////////////////
  1312. // Fill in the columns
  1313. //////////////////////
  1314. // Server Name
  1315. int item = m_StationList.InsertItem(m_StationList.GetItemCount(), pServer->GetName(), WhichIcon);
  1316. // WinStation Name
  1317. if(pWinStation->GetName()[0])
  1318. m_StationList.SetItemText(item, AS_WS_COL_WINSTATION, pWinStation->GetName());
  1319. else {
  1320. CString NameString(" ");
  1321. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  1322. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  1323. m_StationList.SetItemText(item, AS_WS_COL_WINSTATION, NameString);
  1324. }
  1325. // User
  1326. m_StationList.SetItemText(item, AS_WS_COL_USER, pWinStation->GetUserName());
  1327. // Logon ID
  1328. CString ColumnString;
  1329. ColumnString.Format(TEXT("%lu"), pWinStation->GetLogonId());
  1330. m_StationList.SetItemText(item, AS_WS_COL_ID, ColumnString);
  1331. // Connect State
  1332. m_StationList.SetItemText(item, AS_WS_COL_STATE, StrConnectState(pWinStation->GetState(), FALSE));
  1333. // Type
  1334. m_StationList.SetItemText(item, AS_WS_COL_TYPE, pWinStation->GetWdName());
  1335. // Client Name
  1336. m_StationList.SetItemText(item, AS_WS_COL_CLIENTNAME, pWinStation->GetClientName());
  1337. // Idle Time
  1338. TCHAR IdleTimeString[MAX_ELAPSED_TIME_LENGTH];
  1339. if(pWinStation->GetState() == State_Active
  1340. && pWinStation->GetLastInputTime().QuadPart <= pWinStation->GetCurrentTime().QuadPart)
  1341. {
  1342. LARGE_INTEGER DiffTime = CalculateDiffTime(pWinStation->GetLastInputTime(), pWinStation->GetCurrentTime());
  1343. ULONG_PTR d_time = ( ULONG_PTR )DiffTime.QuadPart;
  1344. ELAPSEDTIME IdleTime;
  1345. // Calculate the days, hours, minutes, seconds since specified time.
  1346. IdleTime.days = (USHORT)(d_time / 86400L); // days since
  1347. d_time = d_time % 86400L; // seconds => partial day
  1348. IdleTime.hours = (USHORT)(d_time / 3600L); // hours since
  1349. d_time = d_time % 3600L; // seconds => partial hour
  1350. IdleTime.minutes = (USHORT)(d_time / 60L); // minutes since
  1351. IdleTime.seconds = (USHORT)(d_time % 60L);// seconds remaining
  1352. ElapsedTimeString( &IdleTime, FALSE, IdleTimeString);
  1353. pWinStation->SetIdleTime(IdleTime);
  1354. }
  1355. else wcscpy(IdleTimeString, TEXT("."));
  1356. m_StationList.SetItemText(item, AS_WS_COL_IDLETIME, IdleTimeString);
  1357. // Logon Time
  1358. TCHAR LogonTimeString[MAX_DATE_TIME_LENGTH];
  1359. // We don't want to pass a 0 logon time to DateTimeString()
  1360. // It will blow up if the timezone is GMT
  1361. if(pWinStation->GetState() == State_Active && pWinStation->GetLogonTime().QuadPart)
  1362. {
  1363. DateTimeString(&(pWinStation->GetLogonTime()), LogonTimeString);
  1364. if( LogonTimeString[0] != 0 )
  1365. {
  1366. pDoc->FixUnknownString(LogonTimeString);
  1367. }
  1368. }
  1369. else LogonTimeString[0] = '\0';
  1370. m_StationList.SetItemText(item, AS_WS_COL_LOGONTIME, LogonTimeString);
  1371. // Comment
  1372. m_StationList.SetItemText(item, AS_WS_COL_COMMENT, pWinStation->GetComment());
  1373. // Attach a pointer to the CWinStation structure to the list item
  1374. m_StationList.SetItemData(item, (DWORD_PTR)pWinStation);
  1375. //bug #191727
  1376. //m_StationList.SetItemState( 0 , LVIS_FOCUSED | LVIS_SELECTED , LVIS_FOCUSED | LVIS_SELECTED );
  1377. UnlockListControl();
  1378. return item;
  1379. } // end CAllServerWinStationsPage::AddWinStationToList
  1380. ////////////////////////////////////////
  1381. // F'N: CAllServerWinStationsPage::AddServerToList
  1382. //
  1383. BOOL CAllServerWinStationsPage::AddServerToList(CServer *pServer)
  1384. {
  1385. ASSERT(pServer);
  1386. pServer->LockWinStationList();
  1387. // Get a pointer to this server's list of WinStations
  1388. CObList *pWinStationList = pServer->GetWinStationList();
  1389. // Iterate through the WinStation list
  1390. POSITION pos = pWinStationList->GetHeadPosition();
  1391. while(pos) {
  1392. CWinStation *pWinStation = (CWinStation*)pWinStationList->GetNext(pos);
  1393. AddWinStationToList(pWinStation);
  1394. }
  1395. pServer->UnlockWinStationList();
  1396. return TRUE;
  1397. } // end CAllServerWinStationsPage::AddServerToList
  1398. /////////////////////////////////////
  1399. // F'N: CAllServerWinStationsPage::DisplayStations
  1400. //
  1401. void CAllServerWinStationsPage::DisplayStations( NODETYPE ntType )
  1402. {
  1403. // Clear out the list control
  1404. m_StationList.DeleteAllItems();
  1405. // Get a pointer to the document's list of servers
  1406. CObList* pServerList = ((CWinAdminDoc*)GetDocument())->GetServerList();
  1407. ((CWinAdminDoc*)GetDocument())->LockServerList();
  1408. // Iterate through the server list
  1409. POSITION pos = pServerList->GetHeadPosition();
  1410. while(pos)
  1411. {
  1412. CServer *pServer = (CServer*)pServerList->GetNext(pos);
  1413. if( ntType == NODE_FAV_LIST )
  1414. {
  1415. if( pServer->GetTreeItemFromFav() != NULL )
  1416. {
  1417. AddServerToList(pServer);
  1418. }
  1419. }
  1420. else if( ntType == NODE_THIS_COMP )
  1421. {
  1422. if( pServer->GetTreeItemFromThisComputer() != NULL )
  1423. {
  1424. AddServerToList(pServer);
  1425. }
  1426. }
  1427. else
  1428. {
  1429. AddServerToList( pServer );
  1430. }
  1431. }
  1432. ((CWinAdminDoc*)GetDocument())->UnlockServerList();
  1433. } // end CAllServerWinStationsPage::DisplayStations
  1434. ////////////////////////////////////////
  1435. // F'N: CAllServerWinStationsPage::OnColumnclick
  1436. //
  1437. void CAllServerWinStationsPage::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
  1438. {
  1439. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  1440. // TODO: Add your control notification handler code here
  1441. // If the sort column hasn't changed, flip the ascending mode.
  1442. if(m_CurrentSortColumn == pNMListView->iSubItem)
  1443. m_bSortAscending = !m_bSortAscending;
  1444. else // New sort column, start in ascending mode
  1445. m_bSortAscending = TRUE;
  1446. m_CurrentSortColumn = pNMListView->iSubItem;
  1447. LockListControl();
  1448. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_WINSTATIONS, &m_StationList, m_CurrentSortColumn, m_bSortAscending);
  1449. UnlockListControl();
  1450. *pResult = 0;
  1451. } // end CAllServerWinStationsPage::OnColumnclick
  1452. ////////////////////////////////////////
  1453. // F'N: CAllServerWinStationsPage::OnContextMenu
  1454. //
  1455. void CAllServerWinStationsPage::OnContextMenu(CWnd* pWnd, CPoint ptScreen)
  1456. {
  1457. // TODO: Add your message handler code here
  1458. UINT flags;
  1459. UINT Item;
  1460. CPoint ptClient = ptScreen;
  1461. ScreenToClient(&ptClient);
  1462. // If we got here from the keyboard,
  1463. if(ptScreen.x == -1 && ptScreen.y == -1) {
  1464. UINT iCount = m_StationList.GetItemCount( );
  1465. RECT rc;
  1466. for( Item = 0 ; Item < iCount ; Item++ )
  1467. {
  1468. if( m_StationList.GetItemState( Item , LVIS_SELECTED ) == LVIS_SELECTED )
  1469. {
  1470. m_StationList.GetItemRect( Item , &rc , LVIR_ICON );
  1471. ptScreen.x = rc.left;
  1472. ptScreen.y = rc.bottom + 5;
  1473. ClientToScreen( &ptScreen );
  1474. break;
  1475. }
  1476. }
  1477. if(ptScreen.x == -1 && ptScreen.y == -1)
  1478. {
  1479. return;
  1480. }
  1481. /*
  1482. RECT rect;
  1483. m_StationList.GetClientRect(&rect);
  1484. ptScreen.x = (rect.right - rect.left) / 2;
  1485. ptScreen.y = (rect.bottom - rect.top) / 2;
  1486. ClientToScreen(&ptScreen);
  1487. */
  1488. }
  1489. else {
  1490. Item = m_StationList.HitTest(ptClient, &flags);
  1491. if((Item == 0xFFFFFFFF) || !(flags & LVHT_ONITEM))
  1492. return;
  1493. }
  1494. CMenu menu;
  1495. menu.LoadMenu(IDR_WINSTATION_POPUP);
  1496. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
  1497. TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
  1498. menu.DestroyMenu();
  1499. } // end CAllServerWinStationsPage::OnContextMenu
  1500. //////////////////////////////////
  1501. // MESSAGE MAP: CAllServerProcessesPage
  1502. //
  1503. IMPLEMENT_DYNCREATE(CAllServerProcessesPage, CFormView)
  1504. BEGIN_MESSAGE_MAP(CAllServerProcessesPage, CFormView)
  1505. //{{AFX_MSG_MAP(CAllServerProcessesPage)
  1506. ON_WM_SIZE()
  1507. ON_NOTIFY(LVN_COLUMNCLICK, IDC_PROCESS_LIST, OnColumnclick)
  1508. ON_NOTIFY(LVN_ITEMCHANGED, IDC_PROCESS_LIST, OnProcessItemChanged)
  1509. ON_WM_CONTEXTMENU()
  1510. ON_NOTIFY(NM_SETFOCUS, IDC_PROCESS_LIST, OnSetfocusProcessList)
  1511. //ON_NOTIFY( NM_KILLFOCUS , IDC_PROCESS_LIST , OnKillfocusProcessList )
  1512. //}}AFX_MSG_MAP
  1513. END_MESSAGE_MAP()
  1514. ///////////////////////////////
  1515. // F'N: CAllServerProcessesPage ctor
  1516. //
  1517. CAllServerProcessesPage::CAllServerProcessesPage()
  1518. : CAdminPage(CAllServerProcessesPage::IDD)
  1519. {
  1520. //{{AFX_DATA_INIT(CAllServerProcessesPage)
  1521. // NOTE: the ClassWizard will add member initialization here
  1522. //}}AFX_DATA_INIT
  1523. m_bSortAscending = TRUE;
  1524. } // end CAllServerProcessesPage ctor
  1525. ///////////////////////////////
  1526. // F'N: CAllServerProcessesPage dtor
  1527. //
  1528. CAllServerProcessesPage::~CAllServerProcessesPage()
  1529. {
  1530. } // end CAllServerProcessesPage dtor
  1531. //////////////////////////////////////////
  1532. // F'N: CAllServerProcessesPage::DoDataExchange
  1533. //
  1534. void CAllServerProcessesPage::DoDataExchange(CDataExchange* pDX)
  1535. {
  1536. CFormView::DoDataExchange(pDX);
  1537. //{{AFX_DATA_MAP(CAllServerProcessesPage)
  1538. // NOTE: the ClassWizard will add DDX and DDV calls here
  1539. DDX_Control(pDX, IDC_PROCESS_LIST, m_ProcessList);
  1540. //}}AFX_DATA_MAP
  1541. } // end CAllServerProcessesPage::DoDataExchange
  1542. #ifdef _DEBUG
  1543. ///////////////////////////////////////
  1544. // F'N: CAllServerProcessesPage::AssertValid
  1545. //
  1546. void CAllServerProcessesPage::AssertValid() const
  1547. {
  1548. CFormView::AssertValid();
  1549. } // end CAllServerProcessesPage::AssertValid
  1550. ////////////////////////////////
  1551. // F'N: CAllServerProcessesPage::Dump
  1552. //
  1553. void CAllServerProcessesPage::Dump(CDumpContext& dc) const
  1554. {
  1555. CFormView::Dump(dc);
  1556. } // end CAllServerProcessesPage::Dump
  1557. #endif //_DEBUG
  1558. //////////////////////////////////////////
  1559. // F'N: CAllServerProcessesPage::OnSize
  1560. //
  1561. void CAllServerProcessesPage::OnSize(UINT nType, int cx, int cy)
  1562. {
  1563. RECT rect;
  1564. GetClientRect(&rect);
  1565. rect.top += LIST_TOP_OFFSET;
  1566. if(m_ProcessList.GetSafeHwnd())
  1567. m_ProcessList.MoveWindow(&rect, TRUE);
  1568. // CFormView::OnSize(nType, cx, cy);
  1569. } // end CAllServerProcessesPage::OnSize
  1570. static ColumnDef ProcColumns[] = {
  1571. CD_SERVER,
  1572. CD_USER,
  1573. CD_SESSION,
  1574. CD_PROC_ID,
  1575. CD_PROC_PID,
  1576. CD_PROC_IMAGE
  1577. };
  1578. #define NUM_AS_PROC_COLUMNS sizeof(ProcColumns)/sizeof(ColumnDef)
  1579. //////////////////////////////////////////
  1580. // F'N: CAllServerProcessesPage::OnInitialUpdate
  1581. //
  1582. void CAllServerProcessesPage::OnInitialUpdate()
  1583. {
  1584. CFormView::OnInitialUpdate();
  1585. // Add the column headings
  1586. CString columnString;
  1587. for(int col = 0; col < NUM_AS_PROC_COLUMNS; col++) {
  1588. columnString.LoadString(ProcColumns[col].stringID);
  1589. m_ProcessList.InsertColumn(col, columnString, ProcColumns[col].format, ProcColumns[col].width, col);
  1590. }
  1591. m_CurrentSortColumn = AS_PROC_COL_SERVER;
  1592. } // end CAllServerProcessesPage::OnInitialUpdate
  1593. ////////////////////////////////
  1594. // F'N: CAllServerProcessesPage::Reset
  1595. //
  1596. void CAllServerProcessesPage::Reset(void *)
  1597. {
  1598. // We don't want to display processes until the user clicks
  1599. // on the "Processes" tab
  1600. } // end CAllServerProcessesPage::Reset
  1601. //////////////////////////////////////////
  1602. // F'N: CAllServerProcessesPage::AddServer
  1603. //
  1604. void CAllServerProcessesPage::AddServer(CServer *pServer)
  1605. {
  1606. ASSERT(pServer);
  1607. // Add the Server's processes to the list
  1608. if(AddServerToList(pServer)) {
  1609. // Sort the list
  1610. LockListControl();
  1611. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_PROCESSES, &m_ProcessList, m_CurrentSortColumn, m_bSortAscending);
  1612. UnlockListControl();
  1613. }
  1614. } // end CAllServerProcessesPage::AddServer
  1615. //////////////////////////////////////////
  1616. // F'N: CAllServerProcessesPage::RemoveServer
  1617. //
  1618. void CAllServerProcessesPage::RemoveServer(CServer *pServer)
  1619. {
  1620. ASSERT(pServer);
  1621. LockListControl();
  1622. int ItemCount = m_ProcessList.GetItemCount();
  1623. // We need to go through the list backward so that we can remove
  1624. // more than one item without the item numbers getting messed up
  1625. for(int item = ItemCount; item; item--) {
  1626. CProcess *pProcess = (CProcess*)m_ProcessList.GetItemData(item-1);
  1627. CServer *pListServer = pProcess->GetServer();
  1628. if(pListServer == pServer) {
  1629. m_ProcessList.DeleteItem(item-1);
  1630. pServer->ClearAllSelected();
  1631. }
  1632. }
  1633. UnlockListControl();
  1634. } // end CAllServerProcessesPage::RemoveServer
  1635. //////////////////////////////
  1636. // F'N: CAllServerProcessesPage::UpdateServer
  1637. //
  1638. void CAllServerProcessesPage::UpdateServer(CServer *pServer)
  1639. {
  1640. ASSERT(pServer);
  1641. if(pServer->IsState(SS_DISCONNECTING))
  1642. RemoveServer(pServer);
  1643. } // end CAllServerProcessesPage::UpdateServer
  1644. //////////////////////////////////////////
  1645. // F'N: CAllServerProcessesPage::UpdateProcesses
  1646. //
  1647. void CAllServerProcessesPage::UpdateProcesses(CServer *pServer)
  1648. {
  1649. ASSERT(pServer);
  1650. CWinAdminApp *pApp = (CWinAdminApp*)AfxGetApp();
  1651. BOOL bAnyChanged = FALSE;
  1652. BOOL bAnyAdded = FALSE;
  1653. // Loop through the processes
  1654. pServer->LockProcessList();
  1655. CObList *pProcessList = pServer->GetProcessList();
  1656. POSITION pos = pProcessList->GetHeadPosition();
  1657. while(pos) {
  1658. CProcess *pProcess = (CProcess*)pProcessList->GetNext(pos);
  1659. // If this is a 'system' process and we aren't currently showing them,
  1660. // go to the next process
  1661. if(pProcess->IsSystemProcess() && !pApp->ShowSystemProcesses())
  1662. continue;
  1663. // If this user is not an Admin, don't show him someone else's processes unless it
  1664. // is a System process
  1665. if(!pApp->IsUserAdmin() && !pProcess->IsCurrentUsers() && !pProcess->IsSystemProcess())
  1666. continue;
  1667. // If the process is new, add it to the list
  1668. if(pProcess->IsNew()) {
  1669. if(AddProcessToList(pProcess) != -1)
  1670. bAnyAdded = TRUE;
  1671. continue;
  1672. }
  1673. LV_FINDINFO FindInfo;
  1674. FindInfo.flags = LVFI_PARAM;
  1675. FindInfo.lParam = (LPARAM)pProcess;
  1676. // Find the Process in our list
  1677. int item = m_ProcessList.FindItem(&FindInfo, -1);
  1678. // If the process is no longer current,
  1679. // remove it from the list
  1680. if(!pProcess->IsCurrent() && item != -1) {
  1681. // Remove the Process from the list
  1682. m_ProcessList.DeleteItem(item);
  1683. pProcess->ClearSelected();
  1684. }
  1685. // If the process info has changed, change
  1686. // it's info in our tree
  1687. if(pProcess->IsChanged() && item != -1)
  1688. {
  1689. // WinStation Name
  1690. CWinStation *pWinStation = pProcess->GetWinStation();
  1691. if(pWinStation)
  1692. {
  1693. if(pWinStation->GetName()[0])
  1694. m_ProcessList.SetItemText(item, AS_PROC_COL_WINSTATION, pWinStation->GetName());
  1695. else
  1696. {
  1697. CString NameString(" ");
  1698. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  1699. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  1700. m_ProcessList.SetItemText(item, AS_PROC_COL_WINSTATION, NameString);
  1701. }
  1702. }
  1703. if(m_CurrentSortColumn == AS_PROC_COL_WINSTATION)
  1704. bAnyChanged = TRUE;
  1705. }
  1706. }
  1707. pServer->UnlockProcessList();
  1708. if(bAnyChanged || bAnyAdded) {
  1709. LockListControl();
  1710. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_PROCESSES, &m_ProcessList, m_CurrentSortColumn, m_bSortAscending);
  1711. UnlockListControl();
  1712. }
  1713. } // end CAllServerProcessesPage::UpdateProcesses
  1714. //////////////////////////////////////////
  1715. // F'N: CAllServerProcessesPage::RemoveProcess
  1716. //
  1717. void CAllServerProcessesPage::RemoveProcess(CProcess *pProcess)
  1718. {
  1719. ASSERT(pProcess);
  1720. LockListControl();
  1721. // Find out how many items in the list
  1722. int ItemCount = m_ProcessList.GetItemCount();
  1723. // Go through the items and remove this process
  1724. for(int item = 0; item < ItemCount; item++) {
  1725. CProcess *pListProcess = (CProcess*)m_ProcessList.GetItemData(item);
  1726. if(pListProcess == pProcess) {
  1727. m_ProcessList.DeleteItem(item);
  1728. break;
  1729. }
  1730. }
  1731. UnlockListControl();
  1732. }
  1733. //////////////////////////////////////////
  1734. // F'N: CAllServerProcessesPage::AddProcessToList
  1735. //
  1736. int CAllServerProcessesPage::AddProcessToList(CProcess *pProcess)
  1737. {
  1738. ASSERT(pProcess);
  1739. CWinAdminApp *pApp = (CWinAdminApp*)AfxGetApp();
  1740. CServer *pServer = pProcess->GetServer();
  1741. LockListControl();
  1742. // Server - put at end of list
  1743. int item = m_ProcessList.InsertItem(m_ProcessList.GetItemCount(), pProcess->GetServer()->GetName(), NULL);
  1744. // User
  1745. m_ProcessList.SetItemText(item, AS_PROC_COL_USER, pProcess->GetUserName());
  1746. // WinStation Name
  1747. CWinStation *pWinStation = pProcess->GetWinStation();
  1748. if(pWinStation) {
  1749. if(pWinStation->GetName()[0])
  1750. m_ProcessList.SetItemText(item, AS_PROC_COL_WINSTATION, pWinStation->GetName());
  1751. else {
  1752. CString NameString(" ");
  1753. if(pWinStation->GetState() == State_Disconnected) NameString.LoadString(IDS_DISCONNECTED);
  1754. if(pWinStation->GetState() == State_Idle) NameString.LoadString(IDS_IDLE);
  1755. m_ProcessList.SetItemText(item, AS_PROC_COL_WINSTATION, NameString);
  1756. }
  1757. }
  1758. // ID
  1759. CString ProcString;
  1760. ProcString.Format(TEXT("%lu"), pProcess->GetLogonId());
  1761. m_ProcessList.SetItemText(item, AS_PROC_COL_ID, ProcString);
  1762. // PID
  1763. ProcString.Format(TEXT("%lu"), pProcess->GetPID());
  1764. m_ProcessList.SetItemText(item, AS_PROC_COL_PID, ProcString);
  1765. // Image
  1766. m_ProcessList.SetItemText(item, AS_PROC_COL_IMAGE, pProcess->GetImageName());
  1767. m_ProcessList.SetItemData(item, (DWORD_PTR)pProcess);
  1768. m_ProcessList.SetItemState( 0 , LVIS_FOCUSED | LVIS_SELECTED , LVIS_SELECTED | LVIS_FOCUSED );
  1769. UnlockListControl();
  1770. return item;
  1771. } // end CAllServerProcessesPage::AddProcessToList
  1772. ////////////////////////////////
  1773. // F'N: CAllServerProcessesPage::AddServerToList
  1774. //
  1775. BOOL CAllServerProcessesPage::AddServerToList(CServer *pServer)
  1776. {
  1777. ASSERT(pServer);
  1778. CWinAdminApp *pApp = (CWinAdminApp*)AfxGetApp();
  1779. pServer->EnumerateProcesses();
  1780. CObList *pProcessList = pServer->GetProcessList();
  1781. pServer->LockProcessList();
  1782. POSITION pos = pProcessList->GetHeadPosition();
  1783. while(pos) {
  1784. CProcess *pProcess = (CProcess*)pProcessList->GetNext(pos);
  1785. // If this is a 'system' process and we aren't currently showing them,
  1786. // go to the next process
  1787. if(pProcess->IsSystemProcess() && !pApp->ShowSystemProcesses())
  1788. continue;
  1789. // If this user is not an Admin, don't show him someone else's processes unless it
  1790. // is a System process
  1791. if(!pApp->IsUserAdmin() && !pProcess->IsCurrentUsers() && !pProcess->IsSystemProcess())
  1792. continue;
  1793. AddProcessToList(pProcess);
  1794. }
  1795. pServer->UnlockProcessList();
  1796. return TRUE;
  1797. } // end CAllServerProcessesPage::AddServerToList
  1798. ////////////////////////////////
  1799. // F'N: CAllServerProcessesPage::DisplayProcesses
  1800. //
  1801. void CAllServerProcessesPage::DisplayProcesses( NODETYPE ntType )
  1802. {
  1803. CWaitCursor Nikki;
  1804. LockListControl();
  1805. // Clear out the list control
  1806. m_ProcessList.DeleteAllItems();
  1807. // Get a pointer to the document's list of servers
  1808. CObList* pServerList = ((CWinAdminDoc*)GetDocument())->GetServerList();
  1809. ((CWinAdminDoc*)GetDocument())->LockServerList();
  1810. // Iterate through the server list
  1811. POSITION pos = pServerList->GetHeadPosition();
  1812. CServer *pTempServer;
  1813. while(pos)
  1814. {
  1815. CServer *pServer = (CServer*)pServerList->GetNext(pos);
  1816. pTempServer = NULL;
  1817. if( ntType == NODE_FAV_LIST )
  1818. {
  1819. if( pServer->GetTreeItemFromFav() != NULL )
  1820. {
  1821. pTempServer = pServer;
  1822. }
  1823. }
  1824. else if( ntType == NODE_THIS_COMP )
  1825. {
  1826. if( pServer->GetTreeItemFromThisComputer( ) != NULL )
  1827. {
  1828. pTempServer = pServer;
  1829. }
  1830. }
  1831. else
  1832. {
  1833. pTempServer = pServer;
  1834. }
  1835. if( pTempServer != NULL && pTempServer->IsServerSane())
  1836. {
  1837. AddServerToList( pTempServer );
  1838. } // end if(pServer->IsServerSane())
  1839. } // end while(pos)
  1840. ((CWinAdminDoc*)GetDocument())->UnlockServerList();
  1841. UnlockListControl();
  1842. } // end CAllServerProcessesPage::DisplayProcesses
  1843. //////////////////////////////////////////
  1844. // F'N: CAllServerProcessesPage::OnProcessItemChanged
  1845. //
  1846. void CAllServerProcessesPage::OnProcessItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
  1847. {
  1848. NM_LISTVIEW *pLV = (NM_LISTVIEW*)pNMHDR;
  1849. if(pLV->uNewState & LVIS_SELECTED) {
  1850. CProcess *pProcess = (CProcess*)m_ProcessList.GetItemData(pLV->iItem);
  1851. pProcess->SetSelected();
  1852. }
  1853. if(pLV->uOldState & LVIS_SELECTED && !(pLV->uNewState & LVIS_SELECTED)) {
  1854. CProcess *pProcess = (CProcess*)m_ProcessList.GetItemData(pLV->iItem);
  1855. pProcess->ClearSelected();
  1856. }
  1857. *pResult = 0;
  1858. } // end CAllServerProcessesPage::OnProcessItemChanged
  1859. //////////////////////////////////////////
  1860. // F'N: CAllServerProcessesPage::OnColumnclick
  1861. //
  1862. void CAllServerProcessesPage::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
  1863. {
  1864. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  1865. // TODO: Add your control notification handler code here
  1866. // If the sort column hasn't changed, flip the ascending mode.
  1867. if(m_CurrentSortColumn == pNMListView->iSubItem)
  1868. m_bSortAscending = !m_bSortAscending;
  1869. else // New sort column, start in ascending mode
  1870. m_bSortAscending = TRUE;
  1871. m_CurrentSortColumn = pNMListView->iSubItem;
  1872. LockListControl();
  1873. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_PROCESSES, &m_ProcessList, m_CurrentSortColumn, m_bSortAscending);
  1874. UnlockListControl();
  1875. *pResult = 0;
  1876. } // end CAllServerProcessesPage::OnColumnclick
  1877. //////////////////////////////////////////
  1878. // F'N: CAllServerProcessesPage::OnContextMenu
  1879. //
  1880. void CAllServerProcessesPage::OnContextMenu(CWnd* pWnd, CPoint ptScreen)
  1881. {
  1882. // TODO: Add your message handler code here
  1883. UINT flags;
  1884. UINT Item;
  1885. CPoint ptClient = ptScreen;
  1886. ScreenToClient(&ptClient);
  1887. // If we got here from the keyboard,
  1888. if(ptScreen.x == -1 && ptScreen.y == -1) {
  1889. UINT iCount = m_ProcessList.GetItemCount( );
  1890. RECT rc;
  1891. for( Item = 0 ; Item < iCount ; Item++ )
  1892. {
  1893. if( m_ProcessList.GetItemState( Item , LVIS_SELECTED ) == LVIS_SELECTED )
  1894. {
  1895. m_ProcessList.GetItemRect( Item , &rc , LVIR_ICON );
  1896. ptScreen.x = rc.left;
  1897. ptScreen.y = rc.bottom + 5;
  1898. ClientToScreen( &ptScreen );
  1899. break;
  1900. }
  1901. }
  1902. if(ptScreen.x == -1 && ptScreen.y == -1)
  1903. {
  1904. return;
  1905. }
  1906. /*
  1907. RECT rect;
  1908. m_ProcessList.GetClientRect(&rect);
  1909. ptScreen.x = (rect.right - rect.left) / 2;
  1910. ptScreen.y = (rect.bottom - rect.top) / 2;
  1911. ClientToScreen(&ptScreen);
  1912. */
  1913. }
  1914. else {
  1915. Item = m_ProcessList.HitTest(ptClient, &flags);
  1916. if((Item == 0xFFFFFFFF) || !(flags & LVHT_ONITEM))
  1917. return;
  1918. }
  1919. CMenu menu;
  1920. menu.LoadMenu(IDR_PROCESS_POPUP);
  1921. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
  1922. TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
  1923. menu.DestroyMenu();
  1924. } // end CAllServerProcessesPage::OnContextMenu
  1925. ////////////////////////////////
  1926. // MESSAGE MAP: CAllServerLicensesPage
  1927. //
  1928. IMPLEMENT_DYNCREATE(CAllServerLicensesPage, CFormView)
  1929. BEGIN_MESSAGE_MAP(CAllServerLicensesPage, CFormView)
  1930. //{{AFX_MSG_MAP(CAllServerLicensesPage)
  1931. ON_WM_SIZE()
  1932. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LICENSE_LIST, OnColumnclick)
  1933. ON_NOTIFY(NM_SETFOCUS, IDC_LICENSE_LIST, OnSetfocusLicenseList)
  1934. //ON_NOTIFY( NM_KILLFOCUS , IDC_LICENSE_LIST , OnKillfocusLicenseList )
  1935. //}}AFX_MSG_MAP
  1936. END_MESSAGE_MAP()
  1937. /////////////////////////////
  1938. // F'N: CAllServerLicensesPage ctor
  1939. //
  1940. CAllServerLicensesPage::CAllServerLicensesPage()
  1941. : CAdminPage(CAllServerLicensesPage::IDD)
  1942. {
  1943. //{{AFX_DATA_INIT(CAllServerLicensesPage)
  1944. // NOTE: the ClassWizard will add member initialization here
  1945. //}}AFX_DATA_INIT
  1946. m_bSortAscending = TRUE;
  1947. } // end CAllServerLicensesPage ctor
  1948. /////////////////////////////
  1949. // F'N: CAllServerLicensesPage dtor
  1950. //
  1951. CAllServerLicensesPage::~CAllServerLicensesPage()
  1952. {
  1953. } // end CAllServerLicensesPage dtor
  1954. ////////////////////////////////////////
  1955. // F'N: CAllServerLicensesPage::DoDataExchange
  1956. //
  1957. void CAllServerLicensesPage::DoDataExchange(CDataExchange* pDX)
  1958. {
  1959. CFormView::DoDataExchange(pDX);
  1960. //{{AFX_DATA_MAP(CAllServerLicensesPage)
  1961. DDX_Control(pDX, IDC_LICENSE_LIST, m_LicenseList);
  1962. //}}AFX_DATA_MAP
  1963. } // end CAllServerLicensesPage::DoDataExchange
  1964. #ifdef _DEBUG
  1965. /////////////////////////////////////
  1966. // F'N: CAllServerLicensesPage::AssertValid
  1967. //
  1968. void CAllServerLicensesPage::AssertValid() const
  1969. {
  1970. CFormView::AssertValid();
  1971. } // end CAllServerLicensesPage::AssertValid
  1972. //////////////////////////////
  1973. // F'N: CAllServerLicensesPage::Dump
  1974. //
  1975. void CAllServerLicensesPage::Dump(CDumpContext& dc) const
  1976. {
  1977. CFormView::Dump(dc);
  1978. } // end CAllServerLicensesPage::Dump
  1979. #endif //_DEBUG
  1980. /////////////////////////////////////
  1981. // F'N: CAllServerLicensesPage::OnSize
  1982. //
  1983. void CAllServerLicensesPage::OnSize(UINT nType, int cx, int cy)
  1984. {
  1985. RECT rect;
  1986. GetWindowRect(&rect);
  1987. CWnd *pWnd = GetDlgItem(IDC_LOCAL_AVAILABLE);
  1988. if(pWnd) {
  1989. RECT rect2;
  1990. pWnd->GetWindowRect(&rect2);
  1991. rect.top = rect2.bottom + 5;
  1992. }
  1993. ScreenToClient(&rect);
  1994. if(m_LicenseList.GetSafeHwnd())
  1995. m_LicenseList.MoveWindow(&rect, TRUE);
  1996. // CFormView::OnSize(nType, cx, cy);
  1997. } // end CAllServerLicensesPage::OnSize
  1998. static ColumnDef LicenseColumns[] = {
  1999. CD_SERVER,
  2000. CD_LICENSE_DESC,
  2001. CD_LICENSE_REG,
  2002. CD_USERCOUNT,
  2003. CD_POOLCOUNT,
  2004. CD_LICENSE_NUM
  2005. };
  2006. #define NUM_AS_LICENSE_COLUMNS sizeof(LicenseColumns)/sizeof(ColumnDef)
  2007. /////////////////////////////////////
  2008. // F'N: CAllServerLicensesPage::OnInitialUpdate
  2009. //
  2010. void CAllServerLicensesPage::OnInitialUpdate()
  2011. {
  2012. CFormView::OnInitialUpdate();
  2013. BuildImageList(); // builds the image list for the list control
  2014. CString columnString;
  2015. for(int col = 0; col < NUM_AS_LICENSE_COLUMNS; col++) {
  2016. columnString.LoadString(LicenseColumns[col].stringID);
  2017. m_LicenseList.InsertColumn(col, columnString, LicenseColumns[col].format, LicenseColumns[col].width, col);
  2018. }
  2019. m_CurrentSortColumn = AS_LICENSE_COL_SERVER;
  2020. } // end CAllServerLicensesPage::OnInitialUpdate
  2021. /////////////////////////////////////
  2022. // F'N: CAllServerLicensePage::BuildImageList
  2023. //
  2024. // - calls m_ImageList.Create(..) to create the image list
  2025. // - calls AddIconToImageList(..) to add the icons themselves and save
  2026. // off their indices
  2027. // - attaches the image list to the list ctrl
  2028. //
  2029. void CAllServerLicensesPage::BuildImageList()
  2030. {
  2031. m_ImageList.Create(16, 16, TRUE, 5, 0);
  2032. m_idxBase = AddIconToImageList(IDI_BASE);
  2033. m_idxBump = AddIconToImageList(IDI_BUMP);
  2034. m_idxEnabler = AddIconToImageList(IDI_ENABLER);
  2035. m_idxUnknown = AddIconToImageList(IDI_UNKNOWN);
  2036. m_LicenseList.SetImageList(&m_ImageList, LVSIL_SMALL);
  2037. } // end CAllServerLicensesPage::BuildImageList
  2038. /////////////////////////////////////////
  2039. // F'N: CAllServerLicensesPage::AddIconToImageList
  2040. //
  2041. // - loads the appropriate icon, adds it to m_ImageList, and returns
  2042. // the newly-added icon's index in the image list
  2043. //
  2044. int CAllServerLicensesPage::AddIconToImageList(int iconID)
  2045. {
  2046. HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(iconID));
  2047. return m_ImageList.Add(hIcon);
  2048. } // end CAllServerLicensesPage::AddIconToImageList
  2049. /////////////////////////////////////
  2050. // F'N: CAllServerLicensesPage::Reset
  2051. //
  2052. void CAllServerLicensesPage::Reset(void *p)
  2053. {
  2054. DisplayLicenses();
  2055. DisplayLicenseCounts();
  2056. } // end CAllServerLicensesPage::Reset
  2057. /////////////////////////////////////
  2058. // F'N: CAllServerLicensesPage::AddServer
  2059. //
  2060. void CAllServerLicensesPage::AddServer(CServer *pServer)
  2061. {
  2062. ASSERT(pServer);
  2063. // Add the Server's licenses to the list
  2064. if(AddServerToList(pServer)) {
  2065. // Sort the list
  2066. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_LICENSES, &m_LicenseList, m_CurrentSortColumn, m_bSortAscending);
  2067. }
  2068. } // end F'N: CAllServerLicensesPage::AddServer
  2069. /////////////////////////////////////
  2070. // F'N: CAllServerLicensesPage::RemoveServer
  2071. //
  2072. void CAllServerLicensesPage::RemoveServer(CServer *pServer)
  2073. {
  2074. ASSERT(pServer);
  2075. int ItemCount = m_LicenseList.GetItemCount();
  2076. // We need to go through the list backward so that we can remove
  2077. // more than one item without the item numbers getting messed up
  2078. for(int item = ItemCount; item; item--) {
  2079. CLicense *pLicense = (CLicense*)m_LicenseList.GetItemData(item-1);
  2080. CServer *pListServer = pLicense->GetServer();
  2081. if(pListServer == pServer) {
  2082. m_LicenseList.DeleteItem(item-1);
  2083. pServer->ClearAllSelected();
  2084. }
  2085. }
  2086. } // end CAllServerLicensesPage::RemoveServer
  2087. //////////////////////////////
  2088. // F'N: CAllServerLicensesPage::UpdateServer
  2089. //
  2090. void CAllServerLicensesPage::UpdateServer(CServer *pServer)
  2091. {
  2092. ASSERT(pServer);
  2093. if(pServer->IsState(SS_DISCONNECTING))
  2094. RemoveServer(pServer);
  2095. if(pServer->IsState(SS_GOOD))
  2096. AddServer(pServer);
  2097. } // end CAllServerLicensesPage::UpdateServer
  2098. /////////////////////////////////////
  2099. // F'N: CAllServerLicensesPage::AddServerToList
  2100. //
  2101. BOOL CAllServerLicensesPage::AddServerToList(CServer *pServer)
  2102. {
  2103. ASSERT(pServer);
  2104. int item;
  2105. pServer->LockLicenseList();
  2106. // Get a pointer to the Server's list of licenses
  2107. CObList *pLicenseList = pServer->GetLicenseList();
  2108. // Iterate through the License list
  2109. POSITION pos = pLicenseList->GetHeadPosition();
  2110. while(pos) {
  2111. CLicense *pLicense = (CLicense*)pLicenseList->GetNext(pos);
  2112. //////////////////////
  2113. // Fill in the columns
  2114. //////////////////////
  2115. int WhichIcon;
  2116. switch(pLicense->GetClass()) {
  2117. case LicenseBase:
  2118. WhichIcon = m_idxBase;
  2119. break;
  2120. case LicenseBump:
  2121. WhichIcon = m_idxBump;
  2122. break;
  2123. case LicenseEnabler:
  2124. WhichIcon = m_idxEnabler;
  2125. break;
  2126. case LicenseUnknown:
  2127. WhichIcon = m_idxUnknown;
  2128. break;
  2129. }
  2130. // Server Name
  2131. item = m_LicenseList.InsertItem(m_LicenseList.GetItemCount(), pServer->GetName(), WhichIcon);
  2132. // Description
  2133. m_LicenseList.SetItemText(item, AS_LICENSE_COL_DESCRIPTION, pLicense->GetDescription());
  2134. // Registered
  2135. CString RegString;
  2136. RegString.LoadString(pLicense->IsRegistered() ? IDS_YES : IDS_NO);
  2137. m_LicenseList.SetItemText(item, AS_LICENSE_COL_REGISTERED, RegString);
  2138. BOOL bUnlimited = (pLicense->GetClass() == LicenseBase
  2139. && pLicense->GetTotalCount() == 4095
  2140. && pServer->GetCTXVersionNum() == 0x00000040);
  2141. // User (Total) Count
  2142. CString CountString;
  2143. if(bUnlimited)
  2144. CountString.LoadString(IDS_UNLIMITED);
  2145. else
  2146. CountString.Format(TEXT("%lu"), pLicense->GetTotalCount());
  2147. m_LicenseList.SetItemText(item, AS_LICENSE_COL_USERCOUNT, CountString);
  2148. // Pool Count
  2149. if(bUnlimited)
  2150. CountString.LoadString(IDS_NOT_APPLICABLE);
  2151. else
  2152. CountString.Format(TEXT("%lu"), pLicense->GetPoolCount());
  2153. m_LicenseList.SetItemText(item, AS_LICENSE_COL_POOLCOUNT, CountString);
  2154. // License Number
  2155. m_LicenseList.SetItemText(item, AS_LICENSE_COL_NUMBER, pLicense->GetLicenseNumber());
  2156. m_LicenseList.SetItemData(item, (DWORD_PTR)pLicense);
  2157. } // end while(pos)
  2158. pServer->UnlockLicenseList();
  2159. return TRUE;
  2160. } // end CAllServerLicensesPage::AddServerToList
  2161. /////////////////////////////////////
  2162. // F'N: CAllServerLicensesPage::DisplayLicenseCounts
  2163. //
  2164. void CAllServerLicensesPage::DisplayLicenseCounts()
  2165. {
  2166. // Get a pointer to our document
  2167. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  2168. ExtGlobalInfo *pExtGlobalInfo = pDoc->GetExtGlobalInfo();
  2169. if(pExtGlobalInfo) {
  2170. BOOL bUnlimited = (pExtGlobalInfo->NetworkLocalAvailable == 32767);
  2171. CString LicenseString;
  2172. if(bUnlimited) {
  2173. LicenseString.LoadString(IDS_UNLIMITED);
  2174. SetDlgItemText(IDC_LOCAL_INSTALLED, LicenseString);
  2175. SetDlgItemText(IDC_LOCAL_AVAILABLE, LicenseString);
  2176. SetDlgItemText(IDC_TOTAL_INSTALLED, LicenseString);
  2177. SetDlgItemText(IDC_TOTAL_AVAILABLE, LicenseString);
  2178. } else {
  2179. LicenseString.Format(TEXT("%lu"), pExtGlobalInfo->NetworkLocalInstalled);
  2180. SetDlgItemText(IDC_LOCAL_INSTALLED, LicenseString);
  2181. LicenseString.Format(TEXT("%lu"), pExtGlobalInfo->NetworkLocalAvailable);
  2182. SetDlgItemText(IDC_LOCAL_AVAILABLE, LicenseString);
  2183. LicenseString.Format(TEXT("%lu"),
  2184. pExtGlobalInfo->NetworkPoolInstalled + pExtGlobalInfo->NetworkLocalInstalled);
  2185. SetDlgItemText(IDC_TOTAL_INSTALLED, LicenseString);
  2186. LicenseString.Format(TEXT("%lu"),
  2187. pExtGlobalInfo->NetworkPoolAvailable + pExtGlobalInfo->NetworkLocalAvailable);
  2188. SetDlgItemText(IDC_TOTAL_AVAILABLE, LicenseString);
  2189. }
  2190. LicenseString.Format(TEXT("%lu"), pExtGlobalInfo->NetworkLocalInUse);
  2191. SetDlgItemText(IDC_LOCAL_INUSE, LicenseString);
  2192. LicenseString.Format(TEXT("%lu"), pExtGlobalInfo->NetworkPoolInstalled);
  2193. SetDlgItemText(IDC_POOL_INSTALLED, LicenseString);
  2194. LicenseString.Format(TEXT("%lu"), pExtGlobalInfo->NetworkPoolInUse);
  2195. SetDlgItemText(IDC_POOL_INUSE, LicenseString);
  2196. LicenseString.Format(TEXT("%lu"), pExtGlobalInfo->NetworkPoolAvailable);
  2197. SetDlgItemText(IDC_POOL_AVAILABLE, LicenseString);
  2198. LicenseString.Format(TEXT("%lu"),
  2199. pExtGlobalInfo->NetworkPoolInUse + pExtGlobalInfo->NetworkLocalInUse);
  2200. SetDlgItemText(IDC_TOTAL_INUSE, LicenseString);
  2201. }
  2202. } // end CAllServerLicensesPage::DisplayLicenseCounts
  2203. /////////////////////////////////////
  2204. // F'N: CAllServerLicensesPage::DisplayLicenses
  2205. //
  2206. void CAllServerLicensesPage::DisplayLicenses()
  2207. {
  2208. // Clear out the list control
  2209. m_LicenseList.DeleteAllItems();
  2210. // Get a pointer to the document's list of servers
  2211. CObList* pServerList = ((CWinAdminDoc*)GetDocument())->GetServerList();
  2212. ((CWinAdminDoc*)GetDocument())->LockServerList();
  2213. // Iterate through the server list
  2214. POSITION pos = pServerList->GetHeadPosition();
  2215. while(pos) {
  2216. CServer *pServer = (CServer*)pServerList->GetNext(pos);
  2217. AddServerToList(pServer);
  2218. }
  2219. ((CWinAdminDoc*)GetDocument())->UnlockServerList();
  2220. } // end CAllServerLicensesPage::DisplayLicenses
  2221. /////////////////////////////////////
  2222. // F'N: CAllServerLicensesPage::OnColumnclick
  2223. //
  2224. void CAllServerLicensesPage::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
  2225. {
  2226. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  2227. // TODO: Add your control notification handler code here
  2228. // If the sort column hasn't changed, flip the ascending mode.
  2229. if(m_CurrentSortColumn == pNMListView->iSubItem)
  2230. m_bSortAscending = !m_bSortAscending;
  2231. else // New sort column, start in ascending mode
  2232. m_bSortAscending = TRUE;
  2233. m_CurrentSortColumn = pNMListView->iSubItem;
  2234. SortByColumn(VIEW_ALL_SERVERS, PAGE_AS_LICENSES, &m_LicenseList, m_CurrentSortColumn, m_bSortAscending);
  2235. *pResult = 0;
  2236. } // end CAllServerLicensesPage::OnColumnclick
  2237. //=-----------------------------------------------------------------------------------------
  2238. void CAllServerUsersPage::OnKillfocusUserList(NMHDR* , LRESULT* pResult)
  2239. {
  2240. m_UserList.Invalidate( );
  2241. *pResult = 0;
  2242. }
  2243. void CAllServerUsersPage::OnSetfocusUserList(NMHDR* pNMHDR, LRESULT* pResult)
  2244. {
  2245. ODS( L" CAllServerUsersPage::OnSetfocusUserList\n" );
  2246. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  2247. m_UserList.Invalidate( );
  2248. /*
  2249. int nItem;
  2250. int nCount = m_UserList.GetSelectedCount();
  2251. if( nCount == 0 )
  2252. {
  2253. m_UserList.SetItemState( 0 , LVIS_SELECTED , LVIS_SELECTED );
  2254. }
  2255. else
  2256. {
  2257. for( int i = 0 ; i < nCount; +++i )
  2258. {
  2259. nItem = m_UserList.GetNextItem( -1 , LVNI_FOCUSED );
  2260. m_UserList.Update( nItem );
  2261. }
  2262. }
  2263. */
  2264. pDoc->RegisterLastFocus( PAGED_ITEM );
  2265. *pResult = 0;
  2266. }
  2267. //=-----------------------------------------------------------------------------------------
  2268. void CAllServerProcessesPage::OnKillfocusProcessList(NMHDR* pNMHDR, LRESULT* pResult)
  2269. {
  2270. m_ProcessList.Invalidate( );
  2271. *pResult = 0;
  2272. }
  2273. void CAllServerProcessesPage::OnSetfocusProcessList(NMHDR* pNMHDR, LRESULT* pResult)
  2274. {
  2275. ODS( L" CAllServerProcessesPage::OnSetfocusProcessList\n" );
  2276. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  2277. m_ProcessList.Invalidate();
  2278. /*
  2279. int nItem;
  2280. int nCount = m_ProcessList.GetSelectedCount();
  2281. if( nCount == 0 )
  2282. {
  2283. m_ProcessList.SetItemState( 0 , LVIS_SELECTED , LVIS_SELECTED );
  2284. }
  2285. else
  2286. {
  2287. for( int i = 0 ; i < nCount; +++i )
  2288. {
  2289. nItem = m_ProcessList.GetNextItem( -1 , LVNI_FOCUSED );
  2290. m_ProcessList.Update( nItem );
  2291. }
  2292. }
  2293. */
  2294. pDoc->RegisterLastFocus( PAGED_ITEM );
  2295. *pResult = 0;
  2296. }
  2297. //=-----------------------------------------------------------------------------------------
  2298. void CAllServerWinStationsPage::OnKillfocusWinstationList(NMHDR* , LRESULT* pResult)
  2299. {
  2300. m_StationList.Invalidate( );
  2301. *pResult = 0;
  2302. }
  2303. //=-----------------------------------------------------------------------------------------
  2304. void CAllServerWinStationsPage::OnSetfocusWinstationList(NMHDR* pNMHDR, LRESULT* pResult)
  2305. {
  2306. ODS( L"CAllServerWinStationsPage::OnSetfocusWinstationList\n" );
  2307. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  2308. m_StationList.Invalidate();
  2309. /*
  2310. int nItem;
  2311. int nCount = m_StationList.GetSelectedCount();
  2312. if( nCount == 0 )
  2313. {
  2314. m_StationList.SetItemState( 0 , LVIS_SELECTED , LVIS_SELECTED );
  2315. }
  2316. else
  2317. {
  2318. for( int i = 0 ; i < nCount; +++i )
  2319. {
  2320. nItem = m_StationList.GetNextItem( -1 , LVNI_FOCUSED );
  2321. m_StationList.Update( nItem );
  2322. }
  2323. }
  2324. */
  2325. pDoc->RegisterLastFocus( PAGED_ITEM );
  2326. *pResult = 0;
  2327. }
  2328. /////////////////////////////////////
  2329. // F'N: CAllServerWinStationsPage::ClearSelections
  2330. //
  2331. void CAllServerWinStationsPage::ClearSelections()
  2332. {
  2333. if(m_StationList.m_hWnd != NULL)
  2334. {
  2335. POSITION pos = m_StationList.GetFirstSelectedItemPosition();
  2336. while (pos)
  2337. {
  2338. int nItem = m_StationList.GetNextSelectedItem(pos);
  2339. // you could do your own processing on nItem here
  2340. m_StationList.SetItemState(nItem,0,LVIS_SELECTED);
  2341. }
  2342. }
  2343. }
  2344. //=-----------------------------------------------------------------------------------------
  2345. void CAllServerServersPage::OnKillfocusServerList(NMHDR* pNMHDR, LRESULT* pResult)
  2346. {
  2347. m_ServerList.Invalidate();
  2348. *pResult = 0;
  2349. }
  2350. void CAllServerServersPage::OnSetfocusServerList(NMHDR* pNMHDR, LRESULT* pResult)
  2351. {
  2352. ODS( L"CAllServerServersPage::OnSetfocusServerList\n" );
  2353. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  2354. /*
  2355. int nItem;
  2356. int nCount = m_ServerList.GetSelectedCount();
  2357. if( nCount == 0 )
  2358. {
  2359. m_ServerList.SetItemState( 0 , LVIS_SELECTED , LVIS_SELECTED );
  2360. }
  2361. else
  2362. {
  2363. for( int i = 0 ; i < nCount; +++i )
  2364. {
  2365. nItem = m_ServerList.GetNextItem( -1 , LVNI_FOCUSED );
  2366. m_ServerList.Update( nItem );
  2367. }
  2368. }
  2369. */
  2370. m_ServerList.Invalidate();
  2371. pDoc->RegisterLastFocus( PAGED_ITEM );
  2372. *pResult = 0;
  2373. }
  2374. //=-----------------------------------------------------------------------------------------
  2375. void CAllServerLicensesPage::OnKillfocusLicenseList(NMHDR*, LRESULT* pResult)
  2376. {
  2377. m_LicenseList.Invalidate();
  2378. *pResult = 0;
  2379. }
  2380. void CAllServerLicensesPage::OnSetfocusLicenseList(NMHDR* pNMHDR, LRESULT* pResult)
  2381. {
  2382. ODS( L"CAllServerLicensesPage::OnSetfocusLicenseList\n" );
  2383. CWinAdminDoc *pDoc = (CWinAdminDoc*)GetDocument();
  2384. m_LicenseList.Invalidate();
  2385. /*
  2386. int nItem;
  2387. int nCount = m_LicenseList.GetSelectedCount();
  2388. if( nCount == 0 )
  2389. {
  2390. m_LicenseList.SetItemState( 0 , LVIS_SELECTED , LVIS_SELECTED );
  2391. }
  2392. else
  2393. {
  2394. for( int i = 0 ; i < nCount; +++i )
  2395. {
  2396. nItem = m_LicenseList.GetNextItem( -1 , LVNI_FOCUSED );
  2397. m_LicenseList.Update( nItem );
  2398. }
  2399. }
  2400. */
  2401. pDoc->RegisterLastFocus( PAGED_ITEM );
  2402. *pResult = 0;
  2403. }