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.

840 lines
20 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. //
  5. // SERVER.CPP - Handles the "IntelliMirror" IDD_PROP_INTELLIMIRROR_SERVER tab
  6. //
  7. #include "pch.h"
  8. #include <dns.h>
  9. #include "utils.h"
  10. #include "cservice.h"
  11. #include "cenumsif.h"
  12. #include "ccomputr.h"
  13. #include "server.h"
  14. #include "dpguidqy.h"
  15. #include "querypb.h"
  16. DEFINE_MODULE("IMADMUI")
  17. DEFINE_THISCLASS("CServerTab")
  18. #define THISCLASS CServerTab
  19. #define LPTHISCLASS LPSERVERTAB
  20. DWORD aServerHelpMap[] = {
  21. IDC_C_RESPOND, HIDC_C_RESPOND,
  22. IDC_C_KNOWNCLIENTS, HIDC_C_KNOWNCLIENTS,
  23. IDC_B_CHECKSERVER, HIDC_B_CHECKSERVER,
  24. IDC_B_CLIENTS, HIDC_B_CLIENTS,
  25. IDC_B_SERVICE, HIDC_B_SERVICE,
  26. IDC_G_CHECKSERVER, HIDC_G_CHECKSERVER,
  27. IDC_G_CLIENTSERVICING, HIDC_G_CLIENTSERVICING,
  28. NULL, NULL
  29. };
  30. //
  31. // CreateInstance()
  32. //
  33. LPVOID
  34. CServerTab_CreateInstance( void )
  35. {
  36. TraceFunc( "CServerTab_CreateInstance()\n" );
  37. LPTHISCLASS lpcc = new THISCLASS( );
  38. HRESULT hr = THR( lpcc->Init( ) );
  39. if ( hr )
  40. {
  41. delete lpcc;
  42. RETURN(NULL);
  43. }
  44. RETURN((LPVOID) lpcc);
  45. }
  46. //
  47. // Constructor
  48. //
  49. THISCLASS::THISCLASS( )
  50. {
  51. TraceClsFunc( "CServerTab()\n" );
  52. InterlockIncrement( g_cObjects );
  53. Assert( !_punkService );
  54. Assert( !_pido );
  55. Assert( !_pszGroupDN );
  56. Assert( !_pszSCPDN );
  57. TraceFuncExit();
  58. }
  59. //
  60. // Init()
  61. //
  62. STDMETHODIMP
  63. THISCLASS::Init( )
  64. {
  65. HRESULT hr = S_OK;
  66. TraceClsFunc( "Init()\n" );
  67. _uMode = MODE_SHELL; // default
  68. HRETURN(hr);
  69. }
  70. //
  71. // Destructor
  72. //
  73. THISCLASS::~THISCLASS( )
  74. {
  75. TraceClsFunc( "~CServerTab()\n" );
  76. if ( _pido )
  77. _pido->Release( );
  78. if ( _punkService )
  79. _punkService->Release( );
  80. if ( _punkComputer )
  81. _punkComputer->Release( );
  82. if ( _pszSCPDN )
  83. TraceFree( _pszSCPDN );
  84. if ( _pszGroupDN )
  85. TraceFree( _pszGroupDN );
  86. // tell ADS to destroy the notify object
  87. // NOTE: Another property page may do this before us. Ignore errors.
  88. SendMessage( _hNotify, WM_ADSPROP_NOTIFY_EXIT, 0, 0 );
  89. InterlockDecrement( g_cObjects );
  90. TraceFuncExit();
  91. };
  92. // *************************************************************************
  93. //
  94. // ITab
  95. //
  96. // *************************************************************************
  97. STDMETHODIMP
  98. THISCLASS::AddPages(
  99. LPFNADDPROPSHEETPAGE lpfnAddPage,
  100. LPARAM lParam,
  101. LPUNKNOWN punk )
  102. {
  103. TraceClsFunc( "AddPages( )\n" );
  104. if ( !punk )
  105. RRETURN(E_POINTER);
  106. HRESULT hr = S_OK;
  107. PROPSHEETPAGE psp;
  108. HPROPSHEETPAGE hpage;
  109. psp.dwSize = sizeof(psp);
  110. psp.dwFlags = PSP_USEREFPARENT | PSP_USECALLBACK;
  111. psp.hInstance = (HINSTANCE) g_hInstance;
  112. psp.pszTemplate = MAKEINTRESOURCE(IDD_PROP_INTELLIMIRROR_SERVER);
  113. psp.pcRefParent = (UINT *) &g_cObjects;
  114. psp.pfnCallback = (LPFNPSPCALLBACK) PropSheetPageProc;
  115. psp.pfnDlgProc = PropSheetDlgProc;
  116. psp.lParam = (LPARAM) this;
  117. LPSHELLEXTINIT pShellExtInit = NULL;
  118. IMAO * pmao = NULL;
  119. _punkComputer = punk;
  120. _punkComputer->AddRef( );
  121. hr = THR( _punkComputer->QueryInterface( IID_IMAO, (void**) &pmao ) );
  122. if (FAILED( hr ))
  123. goto Error;
  124. hr = THR( pmao->GetDataObject( &_pido ) );
  125. if (FAILED( hr ))
  126. goto Error;
  127. _punkService = (LPUNKNOWN) CService_CreateInstance( );
  128. if ( !_punkService )
  129. goto OutOfMemory;
  130. hr = THR( _punkService->QueryInterface( IID_IShellExtInit, (void **) &pShellExtInit ) );
  131. if (FAILED( hr ))
  132. goto Error;
  133. hr = THR( pShellExtInit->Initialize( NULL, _pido, NULL ) );
  134. if (FAILED( hr ))
  135. goto Error;
  136. hpage = CreatePropertySheetPage( &psp );
  137. if ( hpage )
  138. {
  139. if ( !lpfnAddPage( hpage, lParam ) )
  140. {
  141. DestroyPropertySheetPage( hpage );
  142. hr = THR(E_FAIL);
  143. }
  144. }
  145. Cleanup:
  146. if ( pShellExtInit )
  147. pShellExtInit->Release( );
  148. if ( pmao )
  149. pmao->Release( );
  150. HRETURN(hr);
  151. OutOfMemory:
  152. hr = E_OUTOFMEMORY;
  153. goto Cleanup;
  154. Error:
  155. MessageBoxFromHResult( NULL, NULL, hr );
  156. goto Cleanup;
  157. }
  158. //
  159. // ReplacePage()
  160. //
  161. STDMETHODIMP
  162. THISCLASS::ReplacePage(
  163. UINT uPageID,
  164. LPFNADDPROPSHEETPAGE lpfnReplaceWith,
  165. LPARAM lParam,
  166. LPUNKNOWN punk )
  167. {
  168. TraceClsFunc( "ReplacePage( ) *** NOT_IMPLEMENTED ***\n" );
  169. HRETURN(E_NOTIMPL);
  170. }
  171. //
  172. // QueryInformation( )
  173. //
  174. STDMETHODIMP
  175. THISCLASS::QueryInformation(
  176. LPWSTR pszAttribute,
  177. LPWSTR * pszResult )
  178. {
  179. TraceClsFunc( "QueryInformation( )\n" );
  180. HRETURN(E_NOTIMPL);
  181. }
  182. //
  183. // AllowActivation( )
  184. //
  185. STDMETHODIMP
  186. THISCLASS::AllowActivation(
  187. BOOL * pfAllow )
  188. {
  189. TraceClsFunc( "AllowActivation( )\n" );
  190. HRETURN(E_NOTIMPL);
  191. }
  192. // ************************************************************************
  193. //
  194. // Property Sheet Functions
  195. //
  196. // ************************************************************************
  197. //
  198. // PropSheetDlgProc()
  199. //
  200. INT_PTR CALLBACK
  201. THISCLASS::PropSheetDlgProc(
  202. HWND hDlg,
  203. UINT uMsg,
  204. WPARAM wParam,
  205. LPARAM lParam )
  206. {
  207. //TraceMsg( TEXT("PropSheetDlgProc(") );
  208. //TraceMsg( TF_FUNC, TEXT(" hDlg = 0x%08x, uMsg = 0x%08x, wParam = 0x%08x, lParam = 0x%08x )\n"),
  209. // hDlg, uMsg, wParam, lParam );
  210. LPTHISCLASS pcc = (LPTHISCLASS) GetWindowLongPtr( hDlg, GWLP_USERDATA );
  211. if ( uMsg == WM_INITDIALOG )
  212. {
  213. TraceMsg( TF_WM, TEXT("WM_INITDIALOG\n"));
  214. LPPROPSHEETPAGE psp = (LPPROPSHEETPAGE) lParam;
  215. SetWindowLongPtr( hDlg, GWLP_USERDATA, psp->lParam );
  216. pcc = (LPTHISCLASS) psp->lParam;
  217. return pcc->_InitDialog( hDlg, lParam );
  218. }
  219. if (pcc)
  220. {
  221. Assert( hDlg == pcc->_hDlg );
  222. switch ( uMsg )
  223. {
  224. case WM_NOTIFY:
  225. return pcc->_OnNotify( wParam, lParam );
  226. case WM_COMMAND:
  227. TraceMsg( TF_WM, TEXT("WM_COMMAND\n") );
  228. return pcc->_OnCommand( wParam, lParam );
  229. break;
  230. case WM_HELP:// F1
  231. {
  232. LPHELPINFO phelp = (LPHELPINFO) lParam;
  233. WinHelp( (HWND) phelp->hItemHandle, g_cszHelpFile, HELP_WM_HELP, (DWORD_PTR) &aServerHelpMap );
  234. }
  235. break;
  236. case WM_CONTEXTMENU: // right mouse click
  237. WinHelp((HWND) wParam, g_cszHelpFile, HELP_CONTEXTMENU, (DWORD_PTR) &aServerHelpMap );
  238. break;
  239. case WM_ADSPROP_PAGE_GET_NOTIFY:
  240. {
  241. HWND *phwnd = (HWND *) wParam;
  242. *phwnd = pcc->_hNotify;
  243. }
  244. return TRUE;
  245. }
  246. }
  247. return FALSE;
  248. }
  249. //
  250. // PropSheetPageProc()
  251. //
  252. UINT CALLBACK
  253. THISCLASS::PropSheetPageProc(
  254. HWND hwnd,
  255. UINT uMsg,
  256. LPPROPSHEETPAGE ppsp )
  257. {
  258. TraceClsFunc( "PropSheetPageProc( " );
  259. TraceMsg( TF_FUNC, TEXT("hwnd = 0x%08x, uMsg = 0x%08x, ppsp= 0x%08x )\n"),
  260. hwnd, uMsg, ppsp );
  261. switch ( uMsg )
  262. {
  263. case PSPCB_CREATE:
  264. RETURN(TRUE); // create it
  265. break;
  266. case PSPCB_RELEASE:
  267. LPTHISCLASS pcc = (LPTHISCLASS) ppsp->lParam;
  268. delete pcc;
  269. break;
  270. }
  271. RETURN(FALSE);
  272. }
  273. //
  274. // _InitDialog( )
  275. //
  276. BOOL
  277. THISCLASS::_InitDialog(
  278. HWND hDlg,
  279. LPARAM lParam )
  280. {
  281. TraceClsFunc( "_InitDialog( )\n" );
  282. CWaitCursor Wait;
  283. BOOL fAdmin = FALSE;
  284. LPINTELLIMIRRORSAP pimsap = NULL;
  285. HRESULT hr;
  286. HRESULT hResult = S_OK;
  287. WCHAR szRISETUPPath[ MAX_PATH ];
  288. HANDLE hFind;
  289. BOOL fOnOff;
  290. IMAO * pmao = NULL;
  291. #if 0
  292. ULONG uCount;
  293. #endif
  294. WIN32_FIND_DATA fda;
  295. _hDlg = hDlg;
  296. hr = THR( _punkService->QueryInterface( IID_IIntelliMirrorSAP, (void**) &pimsap ) );
  297. if (FAILED( hr ))
  298. goto Error;
  299. hr = THR( _punkComputer->QueryInterface( IID_IMAO, (void**) &pmao ) );
  300. if (FAILED( hr ))
  301. goto Error;
  302. hr = THR( pmao->GetNotifyWindow( &_hNotify ) );
  303. if (FAILED( hr ))
  304. goto Error;
  305. ADsPropSetHwnd( _hNotify, _hDlg );
  306. hr = THR( pimsap->IsAdmin( &fAdmin ) );
  307. Assert( SUCCEEDED(hr) || fAdmin == FALSE );
  308. #if 0
  309. hr = THR( pimsap->GetAllowNewClients( &fOnOff) );
  310. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND && hResult == S_OK )
  311. {
  312. hResult = hr;
  313. }
  314. Assert( SUCCEEDED(hr) || fOnOff == FALSE );
  315. Button_SetCheck( GetDlgItem( _hDlg, IDC_C_ALLOWNEWCLIENT ), ( fOnOff ? BST_CHECKED : BST_UNCHECKED ) );
  316. EnableWindow( GetDlgItem( _hDlg, IDC_C_LIMITCLIENT ), fOnOff );
  317. hr = THR( pimsap->GetLimitClients( &fOnOff ) );
  318. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND && hResult == S_OK )
  319. {
  320. hResult = hr;
  321. }
  322. Assert( SUCCEEDED(hr) || fOnOff == FALSE );
  323. Button_SetCheck( GetDlgItem( _hDlg, IDC_C_ALLOWNEWCLIENT ), ( fOnOff ? BST_CHECKED : BST_UNCHECKED ) );
  324. hr = THR( pimsap->GetMaxClients( &uCount ) );
  325. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND && hResult == S_OK )
  326. {
  327. hResult = hr;
  328. }
  329. Assert( SUCCEEDED(hr) || uCount == 0 );
  330. {
  331. WCHAR szText[ 13 ];
  332. wsprintf( szText, "%u", uCount );
  333. SetDlgItemText( _hDlg, IDC_E_LIMIT, szText );
  334. }
  335. hr = THR( pimsap->GetCurrentClientCount( &uCount ) );
  336. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND && hResult == S_OK )
  337. {
  338. hResult = hr;
  339. }
  340. Assert( SUCCEEDED(hr) || uCount == 0 );
  341. {
  342. WCHAR szText[ 13 ];
  343. wsprintf( szText, "%u", uCount );
  344. SetDlgItemText( _hDlg, IDC_S_CURRENTCOUNT, szText );
  345. }
  346. #endif
  347. hr = THR( pimsap->GetAnswerRequests( &fOnOff) );
  348. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND && hResult == S_OK )
  349. {
  350. hResult = hr;
  351. }
  352. Assert( SUCCEEDED(hr) || fOnOff == FALSE );
  353. Button_SetCheck( GetDlgItem( _hDlg, IDC_C_RESPOND ), ( fOnOff ? BST_CHECKED : BST_UNCHECKED ) );
  354. EnableWindow( GetDlgItem( _hDlg, IDC_C_KNOWNCLIENTS ), fOnOff );
  355. hr = THR( pimsap->GetAnswerOnlyValidClients( &fOnOff) );
  356. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND && hResult == S_OK )
  357. {
  358. hResult = hr;
  359. }
  360. Assert( SUCCEEDED(hr) || fOnOff == FALSE );
  361. Button_SetCheck( GetDlgItem( _hDlg, IDC_C_KNOWNCLIENTS ), ( fOnOff ? BST_CHECKED : BST_UNCHECKED ) );
  362. #if 0
  363. // Change the text on the button if it already is in a group.
  364. Assert( !_pszGroupDN );
  365. hr = THR( pimsap->GetGroupDN( &_pszGroupDN ) );
  366. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND )
  367. goto Error;
  368. if ( _pszGroupDN ) {
  369. DWORD dw;
  370. WCHAR szManageGroup[ 64 ];
  371. dw = LoadString( g_hInstance, IDS_MANAGE_GROUP, szManageGroup, ARRAYSIZE(szManageGroup) );
  372. Assert( dw );
  373. // SetWindowText( GetDlgItem( _hDlg, IDC_B_GROUP ), szManageGroup );
  374. }
  375. #endif
  376. // See if we can enable the "Check Server" button.
  377. GetWindowsDirectory( szRISETUPPath, ARRAYSIZE(szRISETUPPath) );
  378. wcscat( szRISETUPPath, L"\\system32\\risetup.exe" );
  379. hFind = FindFirstFile( szRISETUPPath, &fda );
  380. if ( hFind != INVALID_HANDLE_VALUE )
  381. {
  382. FindClose( hFind );
  383. LPWSTR pszServerName;
  384. WCHAR szFQDNS[ DNS_MAX_NAME_BUFFER_LENGTH ];
  385. DWORD cbSize = ARRAYSIZE( szFQDNS );
  386. hr = THR( pimsap->GetServerName( &pszServerName ) );
  387. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND )
  388. goto Error;
  389. if (SUCCEEDED( hr ))
  390. {
  391. GetComputerNameEx( ComputerNameNetBIOS, szFQDNS, &cbSize );
  392. if ( StrCmpI( szFQDNS, pszServerName ) == 0)
  393. {
  394. EnableWindow( GetDlgItem( _hDlg, IDC_B_CHECKSERVER ), TRUE );
  395. }
  396. TraceFree( pszServerName );
  397. }
  398. }
  399. Assert( !_pszSCPDN );
  400. hr = THR( pimsap->GetSCPDN( &_pszSCPDN ) );
  401. if (FAILED( hr ))
  402. goto Error;
  403. EnableWindow( GetDlgItem( _hDlg, IDC_B_SERVICE ), !!_pszSCPDN );
  404. if (FAILED( hResult ))
  405. {
  406. MessageBoxFromHResult( _hDlg, IDS_ERROR_READINGCOMPUTERACCOUNT, hResult );
  407. }
  408. Cleanup:
  409. if ( pmao )
  410. pmao->Release( );
  411. if ( pimsap )
  412. pimsap->Release( );
  413. RETURN(FALSE);
  414. Error:
  415. MessageBoxFromHResult( _hDlg, IDS_ERROR_READINGCOMPUTERACCOUNT, hr );
  416. goto Cleanup;
  417. }
  418. //
  419. // _DisplayClientsQueryForm( )
  420. //
  421. HRESULT
  422. THISCLASS::_DisplayClientsQueryForm( )
  423. {
  424. TraceClsFunc( "_DisplayClientsQueryForm( )\n" );
  425. HRESULT hr;
  426. DSQUERYINITPARAMS dqip;
  427. OPENQUERYWINDOW oqw;
  428. LPDSOBJECTNAMES pDsObjects;
  429. ICommonQuery * pCommonQuery = NULL;
  430. IPropertyBag * ppb = NULL;
  431. VARIANT var;
  432. LPINTELLIMIRRORSAP pimsap = NULL;
  433. LPWSTR pszServerName = NULL;
  434. WCHAR szServerQuery[ DNS_MAX_NAME_BUFFER_LENGTH + 1 ];
  435. VariantInit( &var );
  436. hr = THR( _punkService->QueryInterface( IID_IIntelliMirrorSAP, (void**) &pimsap ) );
  437. if (FAILED( hr ))
  438. goto Clients_Error;
  439. hr = THR( pimsap->GetServerName( &pszServerName ) );
  440. if (FAILED( hr ) && hr != E_ADS_PROPERTY_NOT_FOUND )
  441. goto Clients_Error;
  442. hr = THR( CoCreateInstance( CLSID_CommonQuery, NULL, CLSCTX_INPROC_SERVER, IID_ICommonQuery, (PVOID *)&pCommonQuery) );
  443. if (FAILED( hr ))
  444. goto Clients_Error;
  445. wcscpy( szServerQuery, pszServerName );
  446. wcscat( szServerQuery, L"*" );
  447. V_VT( &var ) = VT_BSTR;
  448. V_BSTR( &var ) = SysAllocString( szServerQuery );
  449. ZeroMemory( &dqip, sizeof(dqip) );
  450. dqip.cbStruct = sizeof(dqip);
  451. dqip.dwFlags = DSQPF_NOSAVE | DSQPF_SHOWHIDDENOBJECTS | DSQPF_ENABLEADMINFEATURES;
  452. dqip.dwFlags |= DSQPF_ENABLEADVANCEDFEATURES;
  453. ppb = (IPropertyBag *) QueryPropertyBag_CreateInstance( );
  454. if ( !ppb )
  455. {
  456. hr = E_OUTOFMEMORY;
  457. goto Clients_Error;
  458. }
  459. hr = THR( ppb->Write( L"ServerName", &var ) );
  460. if (hr)
  461. goto Clients_Error;
  462. ZeroMemory( &oqw, sizeof(oqw) );
  463. oqw.cbStruct = sizeof(oqw);
  464. oqw.dwFlags = OQWF_SHOWOPTIONAL | OQWF_ISSUEONOPEN | OQWF_DEFAULTFORM;
  465. oqw.clsidHandler = CLSID_DsQuery;
  466. oqw.pHandlerParameters = &dqip;
  467. oqw.clsidDefaultForm = CLSID_RIQueryForm;
  468. oqw.pFormParameters = ppb;
  469. hr = pCommonQuery->OpenQueryWindow( _hDlg, &oqw, NULL /* don't need results */);
  470. Clients_Error:
  471. VariantClear( &var );
  472. if ( ppb )
  473. ppb->Release( );
  474. if ( pCommonQuery )
  475. pCommonQuery->Release( );
  476. if ( pszServerName )
  477. TraceFree( pszServerName );
  478. if ( pimsap )
  479. pimsap->Release( );
  480. HRETURN(hr);
  481. }
  482. //
  483. // _OnCommand( )
  484. //
  485. BOOL
  486. THISCLASS::_OnCommand( WPARAM wParam, LPARAM lParam )
  487. {
  488. TraceClsFunc( "_OnCommand( " );
  489. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  490. BOOL fChanged = FALSE;
  491. BOOL fReturn = FALSE;
  492. HWND hwndCtl = (HWND) lParam;
  493. switch( LOWORD(wParam) )
  494. {
  495. case IDC_C_RESPOND:
  496. if ( HIWORD(wParam) == BN_CLICKED )
  497. {
  498. EnableWindow( GetDlgItem( _hDlg, IDC_C_KNOWNCLIENTS ), Button_GetCheck( hwndCtl ) == BST_CHECKED );
  499. fChanged = TRUE;
  500. }
  501. break;
  502. case IDC_C_KNOWNCLIENTS:
  503. if ( HIWORD(wParam) == BN_CLICKED )
  504. {
  505. fChanged = TRUE;
  506. }
  507. break;
  508. case IDC_B_CLIENTS:
  509. if ( HIWORD(wParam) == BN_CLICKED )
  510. {
  511. _DisplayClientsQueryForm( );
  512. }
  513. break;
  514. case IDC_B_CHECKSERVER:
  515. {
  516. WCHAR szCommand[ MAX_PATH ] = { L"RISETUP.EXE -check" };
  517. STARTUPINFO startupInfo;
  518. PROCESS_INFORMATION pi;
  519. BOOL b;
  520. ZeroMemory( &startupInfo, sizeof( startupInfo) );
  521. startupInfo.cb = sizeof( startupInfo );
  522. b = CreateProcess( NULL,
  523. szCommand,
  524. NULL,
  525. NULL,
  526. TRUE,
  527. NORMAL_PRIORITY_CLASS,
  528. NULL,
  529. NULL,
  530. &startupInfo,
  531. &pi );
  532. if ( b )
  533. {
  534. CloseHandle( pi.hProcess );
  535. CloseHandle( pi.hThread );
  536. }
  537. else
  538. {
  539. DWORD dwErr = GetLastError( );
  540. MessageBoxFromError( _hDlg, IDS_RISETUP_FAILED_TO_START, dwErr );
  541. }
  542. }
  543. break;
  544. case IDC_B_SERVICE:
  545. if ( HIWORD(wParam) == BN_CLICKED )
  546. {
  547. Assert( _pszSCPDN );
  548. THR( PostADsPropSheet( _pszSCPDN, _pido, _hDlg, FALSE) );
  549. }
  550. break;
  551. }
  552. if ( fChanged )
  553. {
  554. if ( !_fChanged )
  555. {
  556. _fChanged = TRUE;
  557. SendMessage( GetParent( _hDlg ), PSM_CHANGED, 0, 0 );
  558. }
  559. }
  560. RETURN(fReturn);
  561. }
  562. //
  563. // _ApplyChanges( )
  564. //
  565. HRESULT
  566. THISCLASS::_ApplyChanges( )
  567. {
  568. TraceClsFunc( "_ApplyChanges( )\n" );
  569. if ( !_fChanged )
  570. HRETURN(S_FALSE); // nop
  571. HRESULT hr;
  572. HRESULT hResult = S_OK;
  573. BOOL fOnOff;
  574. HWND hwnd;
  575. LPINTELLIMIRRORSAP pimsap;
  576. WCHAR szBuffer[ 10 ];
  577. hr = THR( _punkService->QueryInterface( IID_IIntelliMirrorSAP, (void**) &pimsap ) );
  578. if (FAILED( hr ))
  579. goto Error;
  580. #if 0
  581. hwnd = GetDlgItem( _hDlg, IDC_C_ALLOWNEWCLIENT );
  582. fOnOff = Button_GetCheck( hwnd ) == BST_CHECKED;
  583. hr = THR( pimsap->SetAllowNewClients( fOnOff ) );
  584. if(FAILED( hr ) && hResult == S_OK )
  585. {
  586. hResult = hr;
  587. SetFocus( hwnd );
  588. }
  589. hwnd = GetDlgItem( _hDlg, IDC_C_LIMITCLIENT );
  590. fOnOff = Button_GetCheck( hwnd ) == BST_CHECKED;
  591. hr = THR( pimsap->SetLimitClients( fOnOff ) );
  592. if(FAILED( hr ) && hResult == S_OK )
  593. {
  594. hResult = hr;
  595. SetFocus( hwnd );
  596. }
  597. hwnd = GetDlgItem( _hDlg, IDC_E_LIMIT );
  598. GetWindowText( hwnd , szBuffer, ARRAYSIZE(szBuffer) );
  599. uValue = wcstol( szBuffer, NULL, 10 );
  600. hr = THR( pimsap->SetMaxClients( uValue ) );
  601. if(FAILED( hr ) && hResult == S_OK )
  602. {
  603. hResult = hr;
  604. SetFocus( hwnd );
  605. }
  606. #endif
  607. hwnd = GetDlgItem( _hDlg, IDC_C_RESPOND );
  608. fOnOff = Button_GetCheck( hwnd ) == BST_CHECKED;
  609. hr = THR( pimsap->SetAnswerRequests( fOnOff ) );
  610. if(FAILED( hr ) && hResult == S_OK )
  611. {
  612. hResult = hr;
  613. SetFocus( hwnd );
  614. }
  615. hwnd = GetDlgItem( _hDlg, IDC_C_KNOWNCLIENTS );
  616. fOnOff = Button_GetCheck( hwnd ) == BST_CHECKED;
  617. hr = THR( pimsap->SetAnswerOnlyValidClients( fOnOff ) );
  618. if(FAILED( hr ) && hResult == S_OK )
  619. {
  620. hResult = hr;
  621. SetFocus( hwnd );
  622. }
  623. hr = THR( pimsap->CommitChanges() );
  624. if(FAILED( hr ))
  625. goto Error;
  626. if (FAILED( hResult ))
  627. {
  628. MessageBoxFromHResult( NULL, NULL, hResult );
  629. hr = hResult;
  630. }
  631. Cleanup:
  632. if ( pimsap )
  633. pimsap->Release( );
  634. // Tell DSA that someone hit Apply
  635. SendMessage( _hNotify, WM_ADSPROP_NOTIFY_APPLY, !!SUCCEEDED( hr ), 0 );
  636. HRETURN(hr);
  637. Error:
  638. MessageBoxFromHResult( NULL, NULL, hr );
  639. goto Cleanup;
  640. }
  641. //
  642. // _OnNotify( )
  643. //
  644. INT
  645. THISCLASS::_OnNotify(
  646. WPARAM wParam,
  647. LPARAM lParam )
  648. {
  649. TraceClsFunc( "_OnNotify( " );
  650. TraceMsg( TF_FUNC, "wParam = 0x%08x, lParam = 0x%08x )\n", wParam, lParam );
  651. LV_DISPINFO * plvdi = (LV_DISPINFO *) lParam;
  652. switch( plvdi->hdr.code )
  653. {
  654. case PSN_APPLY:
  655. {
  656. HRESULT hr;
  657. TraceMsg( TF_WM, TEXT("WM_NOTIFY: PSN_APPLY\n"));
  658. hr = _ApplyChanges( );
  659. _fChanged = FALSE;
  660. SetWindowLongPtr( _hDlg, DWLP_MSGRESULT, ( SUCCEEDED(hr) ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE ));
  661. RETURN(TRUE);
  662. }
  663. break;
  664. #if 0
  665. case LVN_DELETEALLITEMS:
  666. fReturn = TRUE;
  667. break;
  668. case LVN_DELETEITEM:
  669. {
  670. LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
  671. LPSIFTABLE psif = (LPSIFTABLE) pnmv->lParam;
  672. Assert( psif );
  673. if ( psif )
  674. {
  675. TraceFree( psif->pszName );
  676. TraceFree( psif->pszLanguage );
  677. TraceFree( psif->pszSIF );
  678. TraceFree( psif );
  679. }
  680. }
  681. break;
  682. #endif
  683. default:
  684. break;
  685. }
  686. RETURN(FALSE);
  687. }