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.

265 lines
8.1 KiB

  1. // clustestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "clustest.h"
  5. #include "clusDlg.h"
  6. #include "msclus.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CClustestDlg dialog
  51. CClustestDlg::CClustestDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CClustestDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CClustestDlg)
  55. // NOTE: the ClassWizard will add member initialization here
  56. //}}AFX_DATA_INIT
  57. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  58. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60. void CClustestDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CClustestDlg)
  64. DDX_Control(pDX, IDC_TREE1, m_ClusTree);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CClustestDlg, CDialog)
  68. //{{AFX_MSG_MAP(CClustestDlg)
  69. ON_WM_SYSCOMMAND()
  70. ON_WM_PAINT()
  71. ON_WM_QUERYDRAGICON()
  72. //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CClustestDlg message handlers
  76. BOOL CClustestDlg::OnInitDialog()
  77. {
  78. CDialog::OnInitDialog();
  79. // Add "About..." menu item to system menu.
  80. // IDM_ABOUTBOX must be in the system command range.
  81. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  82. ASSERT(IDM_ABOUTBOX < 0xF000);
  83. CMenu* pSysMenu = GetSystemMenu(FALSE);
  84. CString strAboutMenu;
  85. strAboutMenu.LoadString(IDS_ABOUTBOX);
  86. if (!strAboutMenu.IsEmpty())
  87. {
  88. pSysMenu->AppendMenu(MF_SEPARATOR);
  89. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  90. }
  91. // Set the icon for this dialog. The framework does this automatically
  92. // when the application's main window is not a dialog
  93. SetIcon(m_hIcon, TRUE); // Set big icon
  94. SetIcon(m_hIcon, FALSE); // Set small icon
  95. // TODO: Add extra initialization here
  96. EnumerateCluster();
  97. return TRUE; // return TRUE unless you set the focus to a control
  98. }
  99. void CClustestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  100. {
  101. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  102. {
  103. CAboutDlg dlgAbout;
  104. dlgAbout.DoModal();
  105. }
  106. else
  107. {
  108. CDialog::OnSysCommand(nID, lParam);
  109. }
  110. }
  111. // If you add a minimize button to your dialog, you will need the code below
  112. // to draw the icon. For MFC applications using the document/view model,
  113. // this is automatically done for you by the framework.
  114. void CClustestDlg::OnPaint()
  115. {
  116. if (IsIconic())
  117. {
  118. CPaintDC dc(this); // device context for painting
  119. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  120. // Center icon in client rectangle
  121. int cxIcon = GetSystemMetrics(SM_CXICON);
  122. int cyIcon = GetSystemMetrics(SM_CYICON);
  123. CRect rect;
  124. GetClientRect(&rect);
  125. int x = (rect.Width() - cxIcon + 1) / 2;
  126. int y = (rect.Height() - cyIcon + 1) / 2;
  127. // Draw the icon
  128. dc.DrawIcon(x, y, m_hIcon);
  129. }
  130. else
  131. {
  132. CDialog::OnPaint();
  133. }
  134. }
  135. // The system calls this to obtain the cursor to display while the user drags
  136. // the minimized window.
  137. HCURSOR CClustestDlg::OnQueryDragIcon()
  138. {
  139. return (HCURSOR) m_hIcon;
  140. }
  141. BOOL CClustestDlg::EnumerateCluster()
  142. {
  143. COleException e;
  144. CLSID clsid;
  145. long nDomainCnt, nClusterCnt, nGroupCnt, nResCnt;
  146. IClusterApplication ClusterApp;
  147. DomainNames DomainList;
  148. ClusterNames ClusterList;
  149. VARIANT v;
  150. CString strDomainName, strClusterName, strGroupName,strResourceName;
  151. ICluster m_Cluster;
  152. HTREEITEM hItem,hDomainItem, hClustersItem,hClusterItem, hGroupsItem, hGroupItem;
  153. HTREEITEM hResourcesItem, hResourceItem;
  154. try
  155. {
  156. if (CLSIDFromProgID(OLESTR("MSCluster.Application"), &clsid) == NOERROR)
  157. {
  158. if (ClusterApp.CreateDispatch(clsid, &e))
  159. {
  160. DomainList.AttachDispatch(ClusterApp.GetDomainNames());
  161. nDomainCnt = DomainList.GetCount();
  162. hItem = AddItem(_T("Domains"), NULL,TRUE);
  163. while(nDomainCnt >0)
  164. {
  165. strDomainName = DomainList.GetItem(nDomainCnt--);
  166. ClusterList.AttachDispatch(ClusterApp.GetClusterNames(strDomainName));
  167. nClusterCnt = ClusterList.GetCount();
  168. hDomainItem = AddItem(strDomainName.GetBuffer(strDomainName.GetLength()), hItem,TRUE);
  169. strDomainName.ReleaseBuffer(-1);
  170. if(nClusterCnt == 0)
  171. return FALSE;
  172. hClustersItem = AddItem(_T("Clusters"), hDomainItem, TRUE);
  173. while(nClusterCnt > 1)
  174. {
  175. strClusterName = ClusterList.GetItem(nClusterCnt--);
  176. hClusterItem = AddItem(strClusterName.GetBuffer(strClusterName.GetLength()), hClustersItem,TRUE);
  177. strClusterName.ReleaseBuffer(-1);
  178. m_Cluster.AttachDispatch(ClusterApp.OpenCluster(strClusterName));
  179. ClusResGroups ClusGroups(m_Cluster.GetResourceGroups());
  180. nGroupCnt = ClusGroups.GetCount();
  181. if(nGroupCnt == 0)
  182. return FALSE;
  183. hGroupsItem = AddItem(_T("Groups"), hClusterItem,TRUE);
  184. while(nGroupCnt >0)
  185. {
  186. v.lVal = nGroupCnt--;
  187. v.vt = VT_I4 ;
  188. ClusResGroup ClusGroup(ClusGroups.GetItem(v));
  189. strGroupName = ClusGroup.GetName();
  190. hGroupItem = AddItem(strGroupName.GetBuffer(strGroupName.GetLength()), hGroupsItem,TRUE);
  191. strGroupName.ReleaseBuffer(-1);
  192. ClusGroupResources Resources(ClusGroup.GetResources());
  193. nResCnt = Resources.GetCount();
  194. if(nResCnt ==0)
  195. return FALSE;
  196. hResourcesItem = AddItem(_T("Resources"), hGroupItem,TRUE);
  197. while(nResCnt >0)
  198. {
  199. v.lVal = nResCnt--;
  200. v.vt = VT_I4 ;
  201. ClusResource Resource(Resources.GetItem(v));
  202. strResourceName = Resource.GetName();
  203. hResourceItem = AddItem(strResourceName.GetBuffer(strResourceName.GetLength()), hResourcesItem,FALSE);
  204. strResourceName.ReleaseBuffer(-1);
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. }
  212. catch(CException *e)
  213. {
  214. e->ReportError();
  215. e->Delete();
  216. }
  217. return TRUE;
  218. }
  219. HTREEITEM CClustestDlg::AddItem(LPTSTR pStrName, HTREEITEM pParent,BOOL bHasChildren)
  220. {
  221. HTREEITEM hItem;
  222. TV_ITEM tvi; // TreeView Item.
  223. TV_INSERTSTRUCT tvins; // TreeView Insert Struct.
  224. tvins.hParent = pParent;
  225. tvins.hInsertAfter = TVI_LAST;
  226. tvi.cChildren=1;
  227. tvi.mask = TVIF_TEXT;
  228. tvi.pszText = pStrName;
  229. tvi.cchTextMax = _tcslen(pStrName) * sizeof(TCHAR);
  230. if(bHasChildren)
  231. tvi.mask |= TVIF_CHILDREN;
  232. tvins.item = tvi;
  233. hItem = m_ClusTree.InsertItem(&tvins);
  234. return hItem;
  235. }