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.

686 lines
16 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. // MangDlg.CPP - Handles the IDD_MANAGED_WIZARD_PAGE
  5. //
  6. #include "pch.h"
  7. #include "mangdlg.h"
  8. #include "utils.h"
  9. #include "newcmptr.h"
  10. #include "dpguidqy.h"
  11. #include "querypb.h"
  12. DEFINE_MODULE("IMADMUI")
  13. DEFINE_THISCLASS("CManagedPage")
  14. #define THISCLASS CManagedPage
  15. #define LPTHISCLASS LPCManagedPage
  16. DWORD aManagedHelpMap[] = {
  17. IDC_E_GUID, HIDC_E_GUID,
  18. IDC_C_MANAGED_PC, HIDC_C_MANAGED_PC,
  19. NULL, NULL
  20. };
  21. //
  22. // CreateInstance()
  23. //
  24. LPVOID
  25. CManagedPage_CreateInstance( void )
  26. {
  27. TraceFunc( "CManagedPage_CreateInstance()\n" );
  28. LPTHISCLASS lpcc = new THISCLASS( );
  29. HRESULT hr = THR( lpcc->Init( ) );
  30. if ( FAILED(hr))
  31. {
  32. delete lpcc;
  33. RETURN(NULL);
  34. }
  35. RETURN((LPVOID) lpcc);
  36. }
  37. //
  38. // Constructor
  39. //
  40. THISCLASS::THISCLASS( ) :
  41. _hDlg(NULL),
  42. _pNewComputerExtension(NULL),
  43. _pszGuid(NULL),
  44. _pfActivate(NULL)
  45. {
  46. TraceClsFunc( "CManagedPage()\n" );
  47. InterlockIncrement( g_cObjects );
  48. TraceFuncExit();
  49. }
  50. //
  51. // Init()
  52. //
  53. STDMETHODIMP
  54. THISCLASS::Init( )
  55. {
  56. HRESULT hr = S_OK;
  57. TraceClsFunc( "Init()\n" );
  58. Assert( !_pNewComputerExtension );
  59. Assert( !_pszGuid );
  60. Assert( !_pfActivate );
  61. HRETURN(hr);
  62. }
  63. //
  64. // Destructor
  65. //
  66. THISCLASS::~THISCLASS( )
  67. {
  68. TraceClsFunc( "~CManagedPage()\n" );
  69. InterlockDecrement( g_cObjects );
  70. TraceFuncExit();
  71. };
  72. // *************************************************************************
  73. //
  74. // ITab
  75. //
  76. // *************************************************************************
  77. STDMETHODIMP
  78. THISCLASS::AddPages(
  79. LPFNADDPROPSHEETPAGE lpfnAddPage,
  80. LPARAM lParam,
  81. LPUNKNOWN punk )
  82. {
  83. TraceClsFunc( "AddPages( )\n" );
  84. HRESULT hr = S_OK;
  85. PROPSHEETPAGE psp;
  86. HPROPSHEETPAGE hpage;
  87. Assert( lpfnAddPage );
  88. if ( !lpfnAddPage )
  89. HRETURN(E_INVALIDARG);
  90. psp.dwSize = sizeof(psp);
  91. psp.dwFlags = PSP_DEFAULT | PSP_USECALLBACK;
  92. psp.hInstance = (HINSTANCE) g_hInstance;
  93. psp.pszTemplate = MAKEINTRESOURCE(IDD_MANAGED_WIZARD_PAGE);
  94. psp.pcRefParent = (UINT *) &g_cObjects;
  95. psp.pfnCallback = (LPFNPSPCALLBACK) PropSheetPageProc;
  96. psp.pfnDlgProc = PropSheetDlgProc;
  97. psp.lParam = (LPARAM) this;
  98. hpage = CreatePropertySheetPage( &psp );
  99. if ( hpage )
  100. {
  101. if ( !lpfnAddPage( hpage, lParam ) )
  102. {
  103. DestroyPropertySheetPage( hpage );
  104. hr = THR(E_FAIL);
  105. goto Error;
  106. }
  107. }
  108. Error:
  109. HRETURN(hr);
  110. }
  111. //
  112. // ReplacePage()
  113. //
  114. STDMETHODIMP
  115. THISCLASS::ReplacePage(
  116. UINT uPageID,
  117. LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  118. LPARAM lParam,
  119. LPUNKNOWN punk )
  120. {
  121. TraceClsFunc( "ReplacePage( ) *** NOT_IMPLEMENTED ***\n" );
  122. RETURN(E_NOTIMPL);
  123. }
  124. //
  125. // QueryInformation( )
  126. //
  127. STDMETHODIMP
  128. THISCLASS::QueryInformation(
  129. LPWSTR pszAttribute,
  130. LPWSTR * pszResult )
  131. {
  132. TraceClsFunc( "QueryInformation( )\n" );
  133. if ( !pszResult )
  134. HRETURN(E_POINTER);
  135. if ( !pszAttribute )
  136. HRETURN(E_INVALIDARG);
  137. HRESULT hr = E_INVALIDARG;
  138. LRESULT lResult;
  139. *pszResult = NULL;
  140. lResult = Button_GetCheck( GetDlgItem( _hDlg, IDC_C_MANAGED_PC ) );
  141. if ( lResult )
  142. {
  143. if ( _wcsicmp( pszAttribute, NETBOOTGUID ) == 0 )
  144. {
  145. HWND hwndGuid = GetDlgItem( _hDlg, IDC_E_GUID );
  146. DWORD dw = Edit_GetTextLength( hwndGuid ) + 1;
  147. *pszResult = (LPWSTR) TraceAllocString( LMEM_FIXED, dw );
  148. if ( !*pszResult )
  149. {
  150. hr = E_OUTOFMEMORY;
  151. goto Cleanup;
  152. }
  153. Edit_GetText( hwndGuid, *pszResult, dw );
  154. hr = S_OK;
  155. }
  156. if ( _wcsicmp( pszAttribute, L"Guid" ) == 0 )
  157. {
  158. HWND hwndGuid = GetDlgItem( _hDlg, IDC_E_GUID );
  159. DWORD dw = Edit_GetTextLength( hwndGuid ) + 1;
  160. GUID Guid;
  161. LPWSTR pszTemp;
  162. pszTemp = (LPWSTR) TraceAllocString( LMEM_FIXED, dw );
  163. if ( !pszTemp )
  164. {
  165. hr = E_OUTOFMEMORY;
  166. goto Cleanup;
  167. }
  168. Edit_GetText( hwndGuid, pszTemp, dw );
  169. hr = ValidateGuid( pszTemp, &Guid, NULL );
  170. Assert( hr == S_OK );
  171. TraceFree( pszTemp );
  172. LPWSTR pszPrettyString = PrettyPrintGuid( &Guid );
  173. if ( !pszPrettyString )
  174. {
  175. hr = E_OUTOFMEMORY;
  176. goto Cleanup;
  177. }
  178. *pszResult = pszPrettyString;
  179. hr = S_OK;
  180. }
  181. }
  182. else
  183. {
  184. hr = S_OK;
  185. }
  186. Cleanup:
  187. HRETURN(hr);
  188. }
  189. //
  190. // AllowActivation( )
  191. //
  192. STDMETHODIMP
  193. THISCLASS::AllowActivation(
  194. BOOL * pfAllow )
  195. {
  196. TraceClsFunc( "AllowActivation( )\n" );
  197. _pfActivate = pfAllow;
  198. HRETURN(S_OK);
  199. }
  200. // ************************************************************************
  201. //
  202. // Property Sheet Functions
  203. //
  204. // ************************************************************************
  205. //
  206. // PropSheetDlgProc()
  207. //
  208. INT_PTR CALLBACK
  209. THISCLASS::PropSheetDlgProc(
  210. HWND hDlg,
  211. UINT uMsg,
  212. WPARAM wParam,
  213. LPARAM lParam )
  214. {
  215. //TraceMsg( TEXT("PropSheetDlgProc(") );
  216. //TraceMsg( TF_FUNC, TEXT(" hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x )\n"),
  217. // hDlg, uMsg, wParam, lParam );
  218. LPTHISCLASS pcc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  219. if ( uMsg == WM_INITDIALOG )
  220. {
  221. TraceMsg( TF_WM, TEXT("WM_INITDIALOG\n"));
  222. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE) lParam;
  223. SetWindowLongPtr( hDlg, GWLP_USERDATA, psp->lParam );
  224. pcc = (LPTHISCLASS) psp->lParam;
  225. pcc->_InitDialog( hDlg, lParam );
  226. }
  227. if (pcc)
  228. {
  229. Assert( hDlg == pcc->_hDlg );
  230. switch ( uMsg )
  231. {
  232. case WM_NOTIFY:
  233. TraceMsg( TF_WM, TEXT("WM_NOTIFY\n") );
  234. return pcc->_OnNotify( wParam, lParam );
  235. case WM_COMMAND:
  236. TraceMsg( TF_WM, TEXT("WM_COMMAND\n") );
  237. return pcc->_OnCommand( wParam, lParam );
  238. case WM_HELP:// F1
  239. {
  240. LPHELPINFO phelp = (LPHELPINFO) lParam;
  241. WinHelp( (HWND) phelp->hItemHandle, g_cszHelpFile, HELP_WM_HELP, (DWORD_PTR) &aManagedHelpMap );
  242. }
  243. break;
  244. case WM_CONTEXTMENU: // right mouse click
  245. WinHelp((HWND) wParam, g_cszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR) &aManagedHelpMap );
  246. break;
  247. }
  248. }
  249. return FALSE;
  250. }
  251. //
  252. // PropSheetPageProc()
  253. //
  254. UINT CALLBACK
  255. THISCLASS::PropSheetPageProc(
  256. HWND hwnd,
  257. UINT uMsg,
  258. LPPROPSHEETPAGE ppsp )
  259. {
  260. TraceClsFunc( "PropSheetPageProc( " );
  261. TraceMsg( TF_FUNC, TEXT("hwnd = 0x%08x, uMsg = 0x%08x, ppsp= 0x%08x )\n"),
  262. hwnd, uMsg, ppsp );
  263. Assert( ppsp );
  264. LPTHISCLASS pcc = (LPTHISCLASS) ppsp->lParam;
  265. switch ( uMsg )
  266. {
  267. case PSPCB_CREATE:
  268. TraceMsg( TF_WM, "PSPCB_CREATE\n" );
  269. if ( S_OK == pcc->_OnPSPCB_Create( ) )
  270. {
  271. RETURN(TRUE); // create it
  272. }
  273. break;
  274. case PSPCB_RELEASE:
  275. TraceMsg( TF_WM, "PSPCB_RELEASE\n" );
  276. delete pcc;
  277. break;
  278. }
  279. RETURN(FALSE);
  280. }
  281. //
  282. // _OnPSPCB_Create( )
  283. //
  284. HRESULT
  285. THISCLASS::_OnPSPCB_Create( )
  286. {
  287. TraceClsFunc( "_OnPSPCB_Create( )\n" );
  288. return S_OK;
  289. }
  290. //
  291. // _InitDialog( )
  292. //
  293. HRESULT
  294. THISCLASS::_InitDialog(
  295. HWND hDlg,
  296. LPARAM lParam )
  297. {
  298. TraceClsFunc( "_InitDialog( )\n" );
  299. _hDlg = hDlg;
  300. Assert( _pNewComputerExtension );
  301. SetWindowText( GetParent( _hDlg ), _pNewComputerExtension->_pszWizTitle );
  302. SetDlgItemText( _hDlg, IDC_S_CREATEIN, _pNewComputerExtension->_pszContDisplayName );
  303. SendMessage( GetDlgItem( _hDlg, IDC_S_ICON ), STM_SETICON, (WPARAM) _pNewComputerExtension->_hIcon, 0 );
  304. Edit_LimitText( GetDlgItem( _hDlg, IDC_E_GUID), MAX_INPUT_GUID_STRING - 1 );
  305. HRETURN(S_OK);
  306. }
  307. //
  308. // _OnCommand( )
  309. //
  310. INT
  311. THISCLASS::_OnCommand( WPARAM wParam, LPARAM lParam )
  312. {
  313. TraceClsFunc( "_OnCommand( " );
  314. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  315. switch ( LOWORD(wParam) )
  316. {
  317. case IDC_C_MANAGED_PC:
  318. if ( HIWORD(wParam) == BN_CLICKED )
  319. {
  320. LRESULT lResult = Button_GetCheck( GetDlgItem( _hDlg, IDC_C_MANAGED_PC ) );
  321. EnableWindow( GetDlgItem( _hDlg, IDC_E_GUID), (BOOL)lResult );
  322. EnableWindow( GetDlgItem( _hDlg, IDC_S_GUID), (BOOL)lResult );
  323. _UpdateWizardButtons( );
  324. }
  325. break;
  326. case IDC_E_GUID:
  327. if ( HIWORD(wParam) == EN_CHANGE )
  328. {
  329. _UpdateWizardButtons( );
  330. }
  331. break;
  332. }
  333. RETURN(FALSE);
  334. }
  335. //
  336. // _UpdateWizardButtons( )
  337. //
  338. HRESULT
  339. THISCLASS::_UpdateWizardButtons( )
  340. {
  341. TraceClsFunc( "_UpdateWizardButtons( )\n" );
  342. HRESULT hr = S_OK;
  343. LRESULT lResult = Button_GetCheck( GetDlgItem( _hDlg, IDC_C_MANAGED_PC ) );
  344. if ( lResult == BST_CHECKED )
  345. {
  346. WCHAR szGuid[ MAX_INPUT_GUID_STRING ];
  347. if (!Edit_GetText( GetDlgItem( _hDlg, IDC_E_GUID ), szGuid, ARRAYSIZE(szGuid)) ||
  348. S_OK != (hr = ValidateGuid( szGuid, NULL, NULL ))) {
  349. if (hr == S_OK) {
  350. hr = E_INVALIDARG;
  351. }
  352. PropSheet_SetWizButtons( GetParent( _hDlg ), PSWIZB_BACK );
  353. } else {
  354. PropSheet_SetWizButtons( GetParent( _hDlg ), PSWIZB_NEXT | PSWIZB_BACK );
  355. }
  356. }
  357. else
  358. {
  359. PropSheet_SetWizButtons( GetParent( _hDlg ), PSWIZB_NEXT | PSWIZB_BACK );
  360. }
  361. HRETURN(hr);
  362. }
  363. //
  364. // _OnNotify( )
  365. //
  366. INT
  367. THISCLASS::_OnNotify(
  368. WPARAM wParam,
  369. LPARAM lParam )
  370. {
  371. TraceClsFunc( "_OnNotify( " );
  372. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  373. LPNMHDR lpnmhdr = (LPNMHDR) lParam;
  374. TraceMsg( TF_WM, "NMHDR: HWND = 0x%08x, idFrom = 0x%08x, code = 0x%08x\n",
  375. lpnmhdr->hwndFrom, lpnmhdr->idFrom, lpnmhdr->code );
  376. switch( lpnmhdr->code )
  377. {
  378. case PSN_SETACTIVE:
  379. TraceMsg( TF_WM, "PSN_SETACTIVE\n" );
  380. Assert( _pfActivate );
  381. *_pfActivate = FALSE;
  382. _UpdateWizardButtons( );
  383. break;
  384. case PSN_WIZNEXT:
  385. TraceMsg( TF_WM, "PSN_WIZNEXT\n" );
  386. {
  387. HRESULT hr = _OnKillActive( );
  388. if (FAILED(hr))
  389. {
  390. SetFocus( GetDlgItem( _hDlg, IDC_E_GUID ) );
  391. SetWindowLongPtr( _hDlg, DWLP_MSGRESULT, -1 ); // don't continue
  392. RETURN(TRUE);
  393. }
  394. }
  395. break;
  396. default:
  397. break;
  398. }
  399. RETURN(FALSE);
  400. }
  401. //
  402. // _OnKillActive( )
  403. //
  404. HRESULT
  405. THISCLASS::_OnKillActive( )
  406. {
  407. TraceClsFunc( "_OnKillActive( )\n" );
  408. HRESULT hr;
  409. LRESULT lResult = Button_GetCheck( GetDlgItem( _hDlg, IDC_C_MANAGED_PC ) );
  410. Assert( _pfActivate );
  411. *_pfActivate = ( lResult == BST_CHECKED );
  412. if ( *_pfActivate )
  413. {
  414. HWND hwndGuid = GetDlgItem( _hDlg, IDC_E_GUID );
  415. DWORD dw = Edit_GetTextLength( hwndGuid ) + 1;
  416. GUID Guid;
  417. Assert( !_pszGuid );
  418. _pszGuid = (LPWSTR) TraceAllocString( LMEM_FIXED, dw );
  419. if ( !_pszGuid )
  420. {
  421. hr = E_OUTOFMEMORY;
  422. goto Error;
  423. }
  424. Edit_GetText( hwndGuid, _pszGuid, dw );
  425. hr = ValidateGuid( _pszGuid, &Guid, NULL );
  426. Assert( hr == S_OK );
  427. if (FAILED(hr)) {
  428. goto Error;
  429. }
  430. hr = CheckForDuplicateGuid( &Guid );
  431. if ( hr == S_FALSE )
  432. {
  433. INT i = (INT)DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_DUPLICATE_GUID), _hDlg, DupGuidDlgProc, (LPARAM) this );
  434. switch ( i )
  435. {
  436. case IDOK:
  437. hr = S_OK; // ignore problem and continue
  438. break;
  439. case IDCANCEL:
  440. hr = E_FAIL; // go back and change the GUID
  441. break;
  442. #ifdef DEBUG
  443. default:
  444. AssertMsg( 0, "Invalid return value from DialogBox( )\n" );
  445. break;
  446. #endif // debug
  447. }
  448. }
  449. else if ( FAILED( hr ) )
  450. {
  451. goto Error;
  452. }
  453. }
  454. else
  455. {
  456. hr = S_OK;
  457. }
  458. Cleanup:
  459. if ( _pszGuid )
  460. {
  461. TraceFree( _pszGuid );
  462. _pszGuid = NULL;
  463. }
  464. HRETURN(hr);
  465. Error:
  466. MessageBoxFromHResult( _hDlg, NULL, hr );
  467. goto Cleanup;
  468. }
  469. HRESULT
  470. THISCLASS::_OnQuery(
  471. HWND hDlg )
  472. {
  473. TraceClsFunc( "_OnQuery( )\n" );
  474. HRESULT hr;
  475. DSQUERYINITPARAMS dqip;
  476. OPENQUERYWINDOW oqw;
  477. LPDSOBJECTNAMES pDsObjects;
  478. VARIANT var;
  479. IPropertyBag * ppb = NULL;
  480. ICommonQuery * pCommonQuery = NULL;
  481. VariantInit( &var );
  482. hr = THR( CoCreateInstance( CLSID_CommonQuery, NULL, CLSCTX_INPROC_SERVER, IID_ICommonQuery, (PVOID *)&pCommonQuery) );
  483. if (FAILED(hr)) {
  484. goto Error;
  485. }
  486. ZeroMemory( &dqip, sizeof(dqip) );
  487. dqip.cbStruct = sizeof(dqip);
  488. dqip.dwFlags = DSQPF_NOSAVE | DSQPF_SHOWHIDDENOBJECTS | DSQPF_ENABLEADMINFEATURES;
  489. dqip.dwFlags |= DSQPF_ENABLEADVANCEDFEATURES;
  490. ppb = (IPropertyBag *) QueryPropertyBag_CreateInstance( );
  491. if ( !ppb )
  492. {
  493. hr = E_OUTOFMEMORY;
  494. goto Error;
  495. }
  496. BSTR tmp = SysAllocString( _pszGuid );
  497. if (!tmp) {
  498. hr = E_OUTOFMEMORY;
  499. goto Error;
  500. }
  501. V_VT( &var ) = VT_BSTR;
  502. V_BSTR( &var ) = tmp;
  503. hr = ppb->Write( L"ClientGuid", &var );
  504. if (FAILED(hr)) {
  505. goto Error;
  506. }
  507. ZeroMemory( &oqw, sizeof(oqw) );
  508. oqw.cbStruct = sizeof(oqw);
  509. oqw.dwFlags = OQWF_SHOWOPTIONAL | OQWF_ISSUEONOPEN
  510. | OQWF_REMOVESCOPES | OQWF_REMOVEFORMS
  511. | OQWF_DEFAULTFORM;
  512. oqw.clsidHandler = CLSID_DsQuery;
  513. oqw.pHandlerParameters = &dqip;
  514. oqw.clsidDefaultForm = CLSID_RIQueryForm;
  515. oqw.pFormParameters = ppb;
  516. hr = pCommonQuery->OpenQueryWindow( hDlg, &oqw, NULL /* don't need results */);
  517. Error:
  518. VariantClear( &var );
  519. if ( ppb )
  520. ppb->Release( );
  521. if ( pCommonQuery )
  522. pCommonQuery->Release();
  523. HRETURN(hr);
  524. }
  525. //
  526. // DupGuidDlgProc()
  527. //
  528. INT_PTR CALLBACK
  529. THISCLASS::DupGuidDlgProc(
  530. HWND hDlg,
  531. UINT uMsg,
  532. WPARAM wParam,
  533. LPARAM lParam )
  534. {
  535. //TraceMsg( TEXT("DupGuidDlgProc(") );
  536. //TraceMsg( TF_FUNC, TEXT(" hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x )\n"),
  537. // hDlg, uMsg, wParam, lParam );
  538. LPTHISCLASS pcc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  539. if ( uMsg == WM_INITDIALOG )
  540. {
  541. TraceMsg( TF_WM, TEXT("WM_INITDIALOG\n"));
  542. SetWindowLongPtr( hDlg, GWLP_USERDATA, (LPARAM) lParam );
  543. }
  544. switch ( uMsg )
  545. {
  546. case WM_COMMAND:
  547. TraceMsg( TF_WM, TEXT("WM_COMMAND\n") );
  548. switch( LOWORD(wParam) )
  549. {
  550. case IDOK:
  551. case IDCANCEL:
  552. EndDialog( hDlg, LOWORD(wParam) );
  553. break;
  554. case IDC_B_QUERY:
  555. if ( HIWORD(wParam) == BN_CLICKED )
  556. {
  557. if (pcc)
  558. {
  559. pcc->_OnQuery( NULL );
  560. }
  561. }
  562. break;
  563. }
  564. }
  565. return FALSE;
  566. }