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.

457 lines
10 KiB

  1. // colldlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "viewex.h"
  5. #include "colldlg.h"
  6. #include "delgrpit.h"
  7. #include "grpcrtit.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CCollectionDialog dialog
  15. CCollectionDialog::CCollectionDialog(CWnd* pParent /*=NULL*/)
  16. : CDialog(CCollectionDialog::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CCollectionDialog)
  19. //}}AFX_DATA_INIT
  20. m_pCollection = NULL;
  21. m_pMembers = NULL;
  22. m_pGroup = NULL;
  23. m_nSelectedItem = -1;
  24. }
  25. CCollectionDialog::~CCollectionDialog( )
  26. {
  27. m_Paths.RemoveAll( );
  28. m_Types.RemoveAll( );
  29. m_Names.RemoveAll( );
  30. if( NULL != m_pGroup && NULL != m_pMembers )
  31. {
  32. m_pMembers->Release( );
  33. }
  34. }
  35. void CCollectionDialog::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CCollectionDialog)
  39. DDX_Control(pDX, IDC_ITEMTYPE, m_strItemType);
  40. DDX_Control(pDX, IDC_ITEMOLEDSPATH, m_strItemOleDsPath);
  41. DDX_Control(pDX, IDC_COLLECTONITEMSLIST, m_ItemsList);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CCollectionDialog, CDialog)
  45. //{{AFX_MSG_MAP(CCollectionDialog)
  46. ON_LBN_SELCHANGE(IDC_COLLECTONITEMSLIST, OnSelchangeItemCollection)
  47. ON_BN_CLICKED(IDC_ADD, OnAdd)
  48. ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  49. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CCollectionDialog message handlers
  54. /***********************************************************
  55. Function:
  56. Arguments:
  57. Return:
  58. Purpose:
  59. Author(s):
  60. Revision:
  61. Date:
  62. ***********************************************************/
  63. void CCollectionDialog::SetCollectionInterface( IADsCollection* pICollection )
  64. {
  65. m_pCollection = pICollection;
  66. BuildStrings( );
  67. }
  68. /***********************************************************
  69. Function: CCollectionDialog::SetGroup
  70. Arguments:
  71. Return:
  72. Purpose:
  73. Author(s):
  74. Revision:
  75. Date:
  76. ***********************************************************/
  77. void CCollectionDialog::SetGroup( IADsGroup* pGroup )
  78. {
  79. HRESULT hResult;
  80. ASSERT( NULL == m_pMembers );
  81. hResult = pGroup->Members( &m_pMembers );
  82. BuildStrings( );
  83. m_pGroup = pGroup;
  84. }
  85. /***********************************************************
  86. Function:
  87. Arguments:
  88. Return:
  89. Purpose:
  90. Author(s):
  91. Revision:
  92. Date:
  93. ***********************************************************/
  94. void CCollectionDialog::SetMembersInterface( IADsMembers* pIMembers )
  95. {
  96. m_pMembers = pIMembers;
  97. BuildStrings( );
  98. }
  99. /***********************************************************
  100. Function:
  101. Arguments:
  102. Return:
  103. Purpose:
  104. Author(s):
  105. Revision:
  106. Date:
  107. ***********************************************************/
  108. void CCollectionDialog::DisplayActiveItemData( )
  109. {
  110. if( m_Types.GetSize( ) )
  111. {
  112. m_strItemType.SetWindowText( m_Types[ m_nSelectedItem ] );
  113. m_strItemOleDsPath.SetWindowText( m_Paths[ m_nSelectedItem ] );
  114. }
  115. }
  116. /***********************************************************
  117. Function:
  118. Arguments:
  119. Return:
  120. Purpose:
  121. Author(s):
  122. Revision:
  123. Date:
  124. ***********************************************************/
  125. void CCollectionDialog::BuildStrings( )
  126. {
  127. IUnknown* pIEnum = NULL;
  128. IEnumVARIANT* pIEnumVar = NULL;
  129. HRESULT hResult;
  130. VARIANT var;
  131. IADs* pIOleDs = NULL;
  132. BSTR bstrPath;
  133. BSTR bstrName;
  134. BSTR bstrClass;
  135. ULONG ulFetch;
  136. TCHAR szTemp[ 1024 ];
  137. m_Paths.RemoveAll( );
  138. m_Names.RemoveAll( );
  139. m_Types.RemoveAll( );
  140. while( TRUE )
  141. {
  142. if( NULL != m_pCollection )
  143. {
  144. hResult = m_pCollection->get__NewEnum( &pIEnum );
  145. ASSERT( SUCCEEDED( hResult ) );
  146. if( FAILED( hResult ) )
  147. break;
  148. }
  149. else
  150. {
  151. hResult = m_pMembers->get__NewEnum( &pIEnum );
  152. ASSERT( SUCCEEDED( hResult ) );
  153. if( FAILED( hResult ) )
  154. break;
  155. }
  156. hResult = pIEnum->QueryInterface( IID_IEnumVARIANT,
  157. (void**)&pIEnumVar );
  158. ASSERT( SUCCEEDED( hResult ) );
  159. if( FAILED( hResult ) )
  160. break;
  161. VariantInit( &var );
  162. hResult = pIEnumVar->Next( 1, &var, &ulFetch );
  163. while( ulFetch )
  164. {
  165. hResult = V_DISPATCH( &var )->QueryInterface( IID_IADs,
  166. (void**)&pIOleDs );
  167. VariantClear( &var );
  168. ASSERT( SUCCEEDED( hResult ) );
  169. bstrPath = NULL;
  170. bstrName = NULL;
  171. bstrClass = NULL;
  172. hResult = pIOleDs->get_ADsPath( &bstrPath );
  173. ASSERT( SUCCEEDED( hResult ) );
  174. hResult = pIOleDs->get_Name( &bstrName );
  175. ASSERT( SUCCEEDED( hResult ) );
  176. hResult = pIOleDs->get_Class( &bstrClass );
  177. ASSERT( SUCCEEDED( hResult ) );
  178. _tcscpy( szTemp, _T("NA") );
  179. if( bstrName )
  180. {
  181. _tcscpy( szTemp, _T("") );
  182. StringCat( szTemp, bstrName );
  183. }
  184. m_Names.Add( szTemp );
  185. _tcscpy( szTemp, _T("NA") );
  186. if( bstrClass )
  187. {
  188. _tcscpy( szTemp, _T("") );
  189. StringCat( szTemp, bstrClass );
  190. }
  191. m_Types.Add( szTemp );
  192. _tcscpy( szTemp, _T("NA") );
  193. if( bstrPath )
  194. {
  195. _tcscpy( szTemp, _T("") );
  196. StringCat( szTemp, bstrPath );
  197. }
  198. m_Paths.Add( szTemp );
  199. pIOleDs->Release( );
  200. SysFreeString( bstrPath );
  201. bstrPath = NULL;
  202. SysFreeString( bstrName );
  203. bstrName = NULL;
  204. SysFreeString( bstrClass );
  205. bstrClass = NULL;
  206. hResult = pIEnumVar->Next( 1, &var, &ulFetch );
  207. }
  208. pIEnumVar->Release( );
  209. pIEnum->Release( );
  210. break;
  211. }
  212. }
  213. /***********************************************************
  214. Function:
  215. Arguments:
  216. Return:
  217. Purpose:
  218. Author(s):
  219. Revision:
  220. Date:
  221. ***********************************************************/
  222. BOOL CCollectionDialog::OnInitDialog()
  223. {
  224. CDialog::OnInitDialog();
  225. // TODO: Add extra initialization here
  226. if( NULL == m_pGroup && NULL == m_pCollection )
  227. {
  228. GetDlgItem( IDC_ADD )->EnableWindow( FALSE );
  229. GetDlgItem( IDC_REMOVE )->EnableWindow( FALSE );
  230. }
  231. if( m_pCollection != NULL || m_pMembers != NULL )
  232. {
  233. int nItems, nIdx;
  234. nItems = (int)m_Paths.GetSize( );
  235. for( nIdx = 0; nIdx < nItems ; nIdx++ )
  236. {
  237. m_ItemsList.AddString( m_Names[ nIdx ] );
  238. }
  239. m_nSelectedItem = 0;
  240. m_ItemsList.SetCurSel( 0 );
  241. DisplayActiveItemData( );
  242. }
  243. return TRUE; // return TRUE unless you set the focus to a control
  244. // EXCEPTION: OCX Property Pages should return FALSE
  245. }
  246. /***********************************************************
  247. Function:
  248. Arguments:
  249. Return:
  250. Purpose:
  251. Author(s):
  252. Revision:
  253. Date:
  254. ***********************************************************/
  255. void CCollectionDialog::OnSelchangeItemCollection()
  256. {
  257. // TODO: Add your control notification handler code here
  258. int nSelected;
  259. nSelected = m_ItemsList.GetCurSel( );
  260. if( nSelected != m_nSelectedItem )
  261. {
  262. m_nSelectedItem = nSelected;
  263. DisplayActiveItemData( );
  264. }
  265. }
  266. /***********************************************************
  267. Function:
  268. Arguments:
  269. Return:
  270. Purpose:
  271. Author(s):
  272. Revision:
  273. Date:
  274. ***********************************************************/
  275. void CCollectionDialog::OnAdd()
  276. {
  277. // TODO: Add your control notification handler code here
  278. CGroupCreateItem* m_pAddItem;
  279. if( NULL == m_pGroup )
  280. return;
  281. m_pAddItem = new CGroupCreateItem;
  282. if( IDOK == m_pAddItem->DoModal( ) )
  283. {
  284. BSTR bstrName;
  285. HRESULT hResult;
  286. bstrName = AllocBSTR( m_pAddItem->m_strNewItemName.GetBuffer( 512 ) );
  287. hResult = m_pGroup->Add( bstrName );
  288. SysFreeString( bstrName );
  289. MessageBox( (LPCTSTR)OleDsGetErrorText( hResult ), _T("Add") );
  290. OnRefresh( );
  291. if( SUCCEEDED( hResult ) )
  292. {
  293. m_ItemsList.SelectString( 0, m_pAddItem->m_strNewItemName );
  294. }
  295. }
  296. delete m_pAddItem;
  297. }
  298. /***********************************************************
  299. Function:
  300. Arguments:
  301. Return:
  302. Purpose:
  303. Author(s):
  304. Revision:
  305. Date:
  306. ***********************************************************/
  307. void CCollectionDialog::OnRefresh()
  308. {
  309. // TODO: Add your control notification handler code here
  310. int nItems, nIdx;
  311. if( NULL == m_pGroup )
  312. return;
  313. if( NULL != m_pMembers )
  314. {
  315. m_pMembers->Release( );
  316. m_pMembers = NULL;
  317. }
  318. m_pGroup->GetInfo( );
  319. SetGroup( m_pGroup );
  320. nItems = (int)m_Paths.GetSize( );
  321. m_ItemsList.ResetContent( );
  322. for( nIdx = 0; nIdx < nItems ; nIdx++ )
  323. {
  324. m_ItemsList.AddString( m_Names[ nIdx ] );
  325. }
  326. m_nSelectedItem = 0;
  327. m_ItemsList.SetCurSel( 0 );
  328. DisplayActiveItemData( );
  329. }
  330. /***********************************************************
  331. Function: CCollectionDialog::OnRemove
  332. Arguments:
  333. Return:
  334. Purpose:
  335. Author(s):
  336. Revision:
  337. Date:
  338. ***********************************************************/
  339. void CCollectionDialog::OnRemove()
  340. {
  341. // TODO: Add your control notification handler code here
  342. int nSelect;
  343. CDeleteGroupItem* m_pDeleteItem;
  344. if( NULL == m_pGroup )
  345. return;
  346. nSelect = m_ItemsList.GetCurSel( );
  347. if( LB_ERR == nSelect )
  348. return;
  349. m_pDeleteItem = new CDeleteGroupItem;
  350. m_pDeleteItem->m_strItemName = m_Paths[ nSelect ];
  351. //CString m_strParent;
  352. m_pDeleteItem->m_strItemType = m_Types[ nSelect ];
  353. if( IDOK == m_pDeleteItem->DoModal( ) )
  354. {
  355. BSTR bstrName;
  356. HRESULT hResult;
  357. bstrName = AllocBSTR( m_pDeleteItem->m_strItemName.GetBuffer( 512 ) );
  358. hResult = m_pGroup->Remove( bstrName );
  359. SysFreeString( bstrName );
  360. MessageBox( (LPCTSTR)OleDsGetErrorText( hResult ), _T("Remove") );
  361. OnRefresh( );
  362. }
  363. delete m_pDeleteItem;
  364. }
  365.