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.

177 lines
4.9 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: newbrows.cpp
  7. //
  8. // Contents: implementation of the new GPO browser
  9. //
  10. // Functions: BrowseForGPO
  11. //
  12. // History: 04-30-1998 stevebl Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "main.h"
  16. #include "browser.h"
  17. #include "compspp.h"
  18. int CALLBACK PSCallback(HWND hwndDlg, UINT uMsg, LPARAM lParam);
  19. //+--------------------------------------------------------------------------
  20. //
  21. // Function: BrowseForGPO
  22. //
  23. // Synopsis: the GPO browser
  24. //
  25. // Arguments: [lpBrowseInfo] - structure that defines the behavior of the
  26. // browser and contains the results
  27. //
  28. // Returns: S_OK - success
  29. //
  30. // Modifies:
  31. //
  32. // History: 04-30-1998 stevebl Created
  33. //
  34. // Notes:
  35. //
  36. //---------------------------------------------------------------------------
  37. HRESULT BrowseForGPO(LPGPOBROWSEINFO lpBrowseInfo)
  38. {
  39. LPOLESTR szCaption;
  40. if (NULL != lpBrowseInfo->lpTitle)
  41. {
  42. szCaption = lpBrowseInfo->lpTitle;
  43. }
  44. else
  45. {
  46. szCaption = new OLECHAR[256];
  47. if (szCaption)
  48. {
  49. LoadString(g_hInstance, IDS_CAPTION, szCaption, 256);
  50. }
  51. }
  52. // bind to lpBrowseInfo->lpInitialOU and see if it is a site
  53. BOOL fSite = FALSE;
  54. IADs * pADs = NULL;
  55. HRESULT hr = OpenDSObject(lpBrowseInfo->lpInitialOU, IID_IADs, (void **)&pADs);
  56. if (SUCCEEDED(hr))
  57. {
  58. VARIANT var;
  59. VariantInit(&var);
  60. BSTR bstrProperty = SysAllocString(L"objectClass");
  61. if (bstrProperty)
  62. {
  63. hr = pADs->Get(bstrProperty, &var);
  64. if (SUCCEEDED(hr))
  65. {
  66. int cElements = var.parray->rgsabound[0].cElements;
  67. VARIANT * rgData = (VARIANT *)var.parray->pvData;
  68. while (cElements--)
  69. {
  70. if (0 == _wcsicmp(L"site", rgData[cElements].bstrVal))
  71. {
  72. fSite = TRUE;
  73. }
  74. }
  75. }
  76. SysFreeString(bstrProperty);
  77. }
  78. VariantClear(&var);
  79. pADs->Release();
  80. }
  81. HPROPSHEETPAGE hpage[4];
  82. int nPage = 0;
  83. int nStartPage = 0;
  84. void * pActive;
  85. CBrowserPP ppDomains;
  86. if (0 == (lpBrowseInfo->dwFlags & GPO_BROWSE_NODSGPOS))
  87. hpage[nPage++]= ppDomains.Initialize(PAGETYPE_DOMAINS, lpBrowseInfo, &pActive);
  88. CBrowserPP ppSites;
  89. if (0 == (lpBrowseInfo->dwFlags & GPO_BROWSE_NODSGPOS))
  90. {
  91. if (fSite)
  92. {
  93. nStartPage = nPage;
  94. }
  95. hpage[nPage++]= ppSites.Initialize(PAGETYPE_SITES, lpBrowseInfo, &pActive);
  96. }
  97. CCompsPP ppComputers;
  98. if (0 == (lpBrowseInfo->dwFlags & GPO_BROWSE_NOCOMPUTERS))
  99. hpage[nPage++]= ppComputers.Initialize(PAGETYPE_COMPUTERS, lpBrowseInfo, &pActive);
  100. CBrowserPP ppAll;
  101. if (0 == (lpBrowseInfo->dwFlags & GPO_BROWSE_NODSGPOS))
  102. {
  103. if (lpBrowseInfo->dwFlags & GPO_BROWSE_INITTOALL)
  104. {
  105. nStartPage = nPage;
  106. }
  107. hpage[nPage++]= ppAll.Initialize(PAGETYPE_ALL, lpBrowseInfo, &pActive);
  108. }
  109. PROPSHEETHEADER psh;
  110. memset(&psh, 0, sizeof(psh));
  111. psh.dwSize = sizeof(psh);
  112. psh.dwFlags = PSH_NOAPPLYNOW | ((lpBrowseInfo->dwFlags & GPO_BROWSE_OPENBUTTON) ? PSH_USECALLBACK : 0);
  113. psh.hwndParent = lpBrowseInfo->hwndOwner;
  114. psh.pszCaption = szCaption;
  115. psh.nPages = nPage;
  116. psh.phpage = hpage;
  117. psh.pfnCallback = PSCallback;
  118. psh.nStartPage = nStartPage;
  119. int iReturn = (int)PropertySheet(&psh);
  120. if (szCaption && (szCaption != lpBrowseInfo->lpTitle))
  121. {
  122. delete [] szCaption;
  123. }
  124. if (IDOK == iReturn)
  125. {
  126. return S_OK;
  127. }
  128. else
  129. return HRESULT_FROM_WIN32(ERROR_CANCELLED);
  130. }
  131. //+--------------------------------------------------------------------------
  132. //
  133. // Function: PSCallback
  134. //
  135. // Synopsis: Callback function called by Windows during property sheet
  136. // initialization (among others).
  137. //
  138. // Arguments: [hwndDlg] - handle to the property sheet
  139. // [uMsg] - message ID
  140. // [lParam] - additional message specific info
  141. //
  142. // Returns: 0
  143. //
  144. // History: 04-30-1998 stevebl Created
  145. //
  146. // Notes: This is used to change the text of the OK button
  147. //
  148. //---------------------------------------------------------------------------
  149. int CALLBACK PSCallback(HWND hwndDlg, UINT uMsg, LPARAM lParam)
  150. {
  151. if (uMsg == PSCB_INITIALIZED)
  152. {
  153. TCHAR szOpen[64];
  154. LoadString(g_hInstance, IDS_OPENBUTTON, szOpen, ARRAYSIZE(szOpen));
  155. SetDlgItemText(hwndDlg, IDOK, szOpen);
  156. }
  157. return 0;
  158. }