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.

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