Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
11 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: CompsPP.cpp
  7. //
  8. // Contents: Implementation for the "computers" property page of the GPO
  9. // browser.
  10. //
  11. // Classes: CCompsPP
  12. //
  13. // History: 04-30-1998 stevebl Created
  14. //
  15. //---------------------------------------------------------------------------
  16. #include "main.h"
  17. #include "CompsPP.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. //
  24. // Help ids
  25. //
  26. DWORD aBrowserComputerHelpIds[] =
  27. {
  28. IDC_RADIO1, IDH_BROWSER_LOCALCOMPUTER,
  29. IDC_RADIO2, IDH_BROWSER_REMOTECOMPUTER,
  30. IDC_EDIT1, IDH_BROWSER_REMOTECOMPUTER,
  31. IDC_BUTTON1, IDH_BROWSER_BROWSE,
  32. 0, 0
  33. };
  34. CCompsPP::CCompsPP()
  35. {
  36. m_szComputer = _T("");
  37. m_iSelection = 0;
  38. m_ppActive = NULL;
  39. m_pGBI;
  40. }
  41. //+--------------------------------------------------------------------------
  42. //
  43. // Member: CCompsPP::Initialize
  44. //
  45. // Synopsis: Initializes the property page.
  46. //
  47. // Arguments: [dwPageType] - used to identify which page this is. (See
  48. // notes.)
  49. // [pGBI] - pointer to the browse info structure passed
  50. // by caller
  51. // [ppActive] - pointer to a common variable that remembers
  52. // which object was last given the focus.
  53. // Needed because only the page with the focus
  54. // is allowed to return data to the caller when
  55. // the property sheet is dismissed.
  56. //
  57. // Returns: Handle to the newly created property page.
  58. //
  59. // Modifies:
  60. //
  61. // Derivation:
  62. //
  63. // History: 04-30-1998 stevebl Created
  64. //
  65. // Notes: This class implements the PAGETYPE_COMPUTERS page. The
  66. // other pages are all implemented by CBrowserPP:
  67. //
  68. // PAGETYPE_DOMAINS - GPO's linked to domains
  69. // PAGETYPE_SITES - GPO's linked to sites
  70. // PAGETYPE_ALL - All GPO's in a selected
  71. //
  72. //---------------------------------------------------------------------------
  73. HPROPSHEETPAGE CCompsPP::Initialize(DWORD dwPageType, LPGPOBROWSEINFO pGBI, void ** ppActive)
  74. {
  75. m_ppActive = ppActive;
  76. m_dwPageType = dwPageType;
  77. m_pGBI = pGBI;
  78. PROPSHEETPAGE psp;
  79. memset(&psp, 0, sizeof(psp));
  80. psp.dwSize = sizeof(psp);
  81. psp.dwFlags = PSP_DEFAULT;
  82. psp.hInstance = g_hInstance;
  83. psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPPAGE_COMPUTERS);
  84. return CreatePropertySheetPage(&psp);
  85. }
  86. CCompsPP::~CCompsPP()
  87. {
  88. }
  89. #include "objsel.h"
  90. //+--------------------------------------------------------------------------
  91. //
  92. // Member: CCompsPP::OnBrowseComputers
  93. //
  94. // Synopsis: browses for computers in the entire directory
  95. //
  96. // Arguments: [in] hwndDlg : the handle to the window to which the computer
  97. // selection dialog is made modal.
  98. //
  99. // Returns: nothing
  100. //
  101. // History: 1/8/1999 RahulTh created
  102. //
  103. // Notes: in case of errors, this function bails out silently
  104. //
  105. //---------------------------------------------------------------------------
  106. void CCompsPP::OnBrowseComputers (HWND hwndDlg)
  107. {
  108. HRESULT hr;
  109. IDsObjectPicker * pDsObjectPicker = NULL;
  110. const ULONG cbNumScopes = 4; //make sure this number matches the number of scopes initialized
  111. DSOP_SCOPE_INIT_INFO ascopes [cbNumScopes];
  112. DSOP_INIT_INFO InitInfo;
  113. IDataObject * pdo = NULL;
  114. STGMEDIUM stgmedium = {
  115. TYMED_HGLOBAL,
  116. NULL
  117. };
  118. UINT cf = 0;
  119. FORMATETC formatetc = {
  120. (CLIPFORMAT)cf,
  121. NULL,
  122. DVASPECT_CONTENT,
  123. -1,
  124. TYMED_HGLOBAL
  125. };
  126. BOOL bAllocatedStgMedium = FALSE;
  127. PDS_SELECTION_LIST pDsSelList = NULL;
  128. PDS_SELECTION pDsSelection = NULL;
  129. PCWSTR lpAttributes [] = {L"dNSHostName", 0};
  130. VARIANT * pVarAttributes;
  131. hr = CoInitialize (NULL);
  132. if (FAILED(hr))
  133. goto BrowseComps_Cleanup;
  134. hr = CoCreateInstance (CLSID_DsObjectPicker,
  135. NULL,
  136. CLSCTX_INPROC_SERVER,
  137. IID_IDsObjectPicker,
  138. (void **) & pDsObjectPicker
  139. );
  140. if (FAILED(hr))
  141. goto BrowseComps_Cleanup;
  142. //Initialize the scopes.
  143. ZeroMemory (ascopes, cbNumScopes * sizeof (DSOP_SCOPE_INIT_INFO));
  144. ascopes[0].cbSize = ascopes[1].cbSize = ascopes[2].cbSize = ascopes[3].cbSize
  145. = sizeof (DSOP_SCOPE_INIT_INFO);
  146. ascopes[0].flType = DSOP_SCOPE_TYPE_GLOBAL_CATALOG;
  147. ascopes[0].flScope = DSOP_SCOPE_FLAG_STARTING_SCOPE;
  148. ascopes[0].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  149. ascopes[1].flType = DSOP_SCOPE_TYPE_ENTERPRISE_DOMAIN;
  150. ascopes[1].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  151. ascopes[2].flType = DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN |
  152. DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN |
  153. DSOP_SCOPE_TYPE_WORKGROUP;
  154. ascopes[2].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  155. ascopes[2].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  156. ascopes[3].flType = DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE |
  157. DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE;
  158. ascopes[3].FilterFlags.Uplevel.flBothModes = DSOP_FILTER_COMPUTERS;
  159. ascopes[3].FilterFlags.flDownlevel = DSOP_DOWNLEVEL_FILTER_COMPUTERS;
  160. //populate the InitInfo structure that will be used to initialize the
  161. //object picker
  162. ZeroMemory (&InitInfo, sizeof (DSOP_INIT_INFO));
  163. InitInfo.cbSize = sizeof (DSOP_INIT_INFO);
  164. InitInfo.cDsScopeInfos = cbNumScopes;
  165. InitInfo.aDsScopeInfos = ascopes;
  166. InitInfo.apwzAttributeNames = lpAttributes;
  167. InitInfo.cAttributesToFetch = 1;
  168. hr = pDsObjectPicker->Initialize (&InitInfo);
  169. if (FAILED(hr))
  170. goto BrowseComps_Cleanup;
  171. hr = pDsObjectPicker->InvokeDialog (hwndDlg, &pdo);
  172. //if the computer selection dialog cannot be invoked or if the user
  173. //hits cancel, bail out.
  174. if (FAILED(hr) || S_FALSE == hr)
  175. goto BrowseComps_Cleanup;
  176. //if we are here, the user chose, OK, so find out what group was chosen
  177. cf = RegisterClipboardFormat (CFSTR_DSOP_DS_SELECTION_LIST);
  178. if (0 == cf)
  179. goto BrowseComps_Cleanup;
  180. //set the clipboard format for the FORMATETC structure
  181. formatetc.cfFormat = (CLIPFORMAT)cf;
  182. hr = pdo->GetData (&formatetc, &stgmedium);
  183. if (FAILED (hr))
  184. goto BrowseComps_Cleanup;
  185. bAllocatedStgMedium = TRUE;
  186. pDsSelList = (PDS_SELECTION_LIST) GlobalLock (stgmedium.hGlobal);
  187. //
  188. // Since the dialog was in single-select mode and the user was able
  189. // to hit OK, there should be exactly one selection.
  190. //
  191. ASSERT (1 == pDsSelList->cItems);
  192. pDsSelection = &(pDsSelList->aDsSelection[0]);
  193. pVarAttributes = pDsSelection->pvarFetchedAttributes;
  194. if (pVarAttributes->vt != VT_EMPTY)
  195. {
  196. //
  197. // Put the machine name in the edit control
  198. //
  199. SetWindowText (GetDlgItem (hwndDlg, IDC_EDIT1), pVarAttributes->bstrVal);
  200. }
  201. else
  202. {
  203. //
  204. // Put the machine name in the edit control
  205. //
  206. SetWindowText (GetDlgItem (hwndDlg, IDC_EDIT1), pDsSelection->pwzName);
  207. }
  208. BrowseComps_Cleanup:
  209. if (pDsSelList)
  210. GlobalUnlock (pDsSelList);
  211. if (bAllocatedStgMedium)
  212. ReleaseStgMedium (&stgmedium);
  213. if (pdo)
  214. pdo->Release();
  215. if (pDsObjectPicker)
  216. pDsObjectPicker->Release();
  217. return;
  218. }
  219. BOOL CCompsPP::DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  220. {
  221. switch (uMsg)
  222. {
  223. case WM_INITDIALOG:
  224. {
  225. // Initialize dialog data
  226. SendMessage(GetDlgItem(hwndDlg, IDC_RADIO1), BM_SETCHECK, TRUE, 0);
  227. EnableWindow (GetDlgItem(GetParent(hwndDlg), IDOK), TRUE);
  228. }
  229. break;
  230. case WM_NOTIFY:
  231. {
  232. LPNMHDR pnmh = (LPNMHDR) lParam;
  233. switch (pnmh->code)
  234. {
  235. case PSN_APPLY:
  236. {
  237. if (*m_ppActive == this)
  238. {
  239. if (SendMessage(GetDlgItem(hwndDlg, IDC_RADIO1), BM_GETCHECK, 0, 0))
  240. {
  241. // local computer is selected
  242. m_pGBI->gpoType = GPOTypeLocal;
  243. }
  244. else
  245. {
  246. // other computer is selected
  247. m_pGBI->gpoType = GPOTypeRemote;
  248. int cch = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_EDIT1));
  249. LPWSTR sz = new WCHAR[cch + 1];
  250. if (sz)
  251. {
  252. GetWindowText(GetDlgItem(hwndDlg, IDC_EDIT1), sz, cch+1);
  253. wcsncpy(m_pGBI->lpName, sz, m_pGBI->dwNameSize);
  254. delete [] sz;
  255. }
  256. }
  257. }
  258. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE); // accept changes
  259. }
  260. break;
  261. case PSN_SETACTIVE:
  262. *m_ppActive = this;
  263. EnableWindow (GetDlgItem(GetParent(hwndDlg), IDOK), TRUE);
  264. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 0);
  265. break;
  266. default:
  267. break;
  268. }
  269. }
  270. break;
  271. case WM_COMMAND:
  272. if (IDC_BUTTON1 == LOWORD(wParam))
  273. {
  274. OnBrowseComputers (hwndDlg);
  275. return TRUE;
  276. }
  277. if (IDC_RADIO1 == LOWORD(wParam))
  278. {
  279. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON1), FALSE);
  280. EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT1), FALSE);
  281. return TRUE;
  282. }
  283. if (IDC_RADIO2 == LOWORD(wParam))
  284. {
  285. EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON1), TRUE);
  286. EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT1), TRUE);
  287. SetFocus (GetDlgItem(hwndDlg, IDC_EDIT1));
  288. return TRUE;
  289. }
  290. break;
  291. case WM_ACTIVATE:
  292. if (WA_INACTIVE != LOWORD(wParam))
  293. {
  294. *m_ppActive = this;
  295. }
  296. break;
  297. case WM_HELP: // F1
  298. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, HELP_FILE, HELP_WM_HELP,
  299. (ULONG_PTR) (LPSTR) aBrowserComputerHelpIds);
  300. break;
  301. case WM_CONTEXTMENU: // right mouse click
  302. WinHelp((HWND) wParam, HELP_FILE, HELP_CONTEXTMENU,
  303. (ULONG_PTR) (LPSTR) aBrowserComputerHelpIds);
  304. return (TRUE);
  305. default:
  306. break;
  307. }
  308. return (FALSE);
  309. }