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.

3964 lines
99 KiB

  1. //---------------------------------------------------------------------------
  2. // Copyright (c) 1998, Microsoft Corporation
  3. // All Rights Reserved
  4. // Information Contained Herein Is Proprietary and Confidential
  5. //
  6. // Author: alhen
  7. //---------------------------------------------------------------------------
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include "tsusrsht.h"
  11. //#include <dsgetdc.h>
  12. #include <icanon.h>
  13. #include <shlwapi.h>
  14. // extern BOOL g_bPagesHaveBeenInvoked;
  15. /*NTSTATUS GetDomainName( PWCHAR ServerNamePtr, // name of server to get domain of
  16. LPTSTR DomainNamePtr // alloc and set ptr (free with NetApiBufferFree)
  17. );
  18. */
  19. WNDPROC CTimeOutDlg::m_pfWndproc = 0;
  20. //-------------------------------------------------------------------------------
  21. /*
  22. static TOKTABLE tokday[ 4 ] = {
  23. { NULL , IDS_D },
  24. { NULL , IDS_DAY },
  25. { NULL , IDS_DAYS },
  26. { NULL , ( DWORD )-1 }
  27. };
  28. static TOKTABLE tokhour[ 6 ] = {
  29. { NULL , IDS_H },
  30. { NULL , IDS_HR },
  31. { NULL , IDS_HRS },
  32. { NULL , IDS_HOUR },
  33. { NULL , IDS_HOURS },
  34. { NULL , ( DWORD )-1 }
  35. };
  36. static TOKTABLE tokmin[ 5 ] = {
  37. { NULL , IDS_M },
  38. { NULL , IDS_MIN },
  39. { NULL , IDS_MINUTE },
  40. { NULL , IDS_MINUTES },
  41. { NULL , ( DWORD )-1 }
  42. };
  43. */
  44. TCHAR * GetNextToken( TCHAR *pszString , TCHAR *tchToken );
  45. void ErrorMessage1( HWND hParent , DWORD dwStatus );
  46. void ErrorMessage2( HWND hParent , DWORD dwStatus );
  47. void xxErrorMessage( HWND hParent , DWORD dwStatus , UINT );
  48. //-------------------------------------------------------------------------------
  49. // CTUSerDlg::ctor
  50. //-------------------------------------------------------------------------------
  51. CTSUserSheet::CTSUserSheet( )
  52. {
  53. m_pstrMachinename = NULL;
  54. m_pstrUsername = NULL;
  55. m_cref = 0;
  56. m_bIsConfigLoaded = FALSE;
  57. m_szRemoteServerName[0] = 0;
  58. m_pUserSid = NULL;
  59. for( int tt = 0 ; tt < NUM_OF_PAGES ; ++tt )
  60. {
  61. m_pDlg[ tt ] = NULL;
  62. }
  63. }
  64. //-------------------------------------------------------------------------------
  65. // CTUSerDlg::dtor
  66. //-------------------------------------------------------------------------------
  67. CTSUserSheet::~CTSUserSheet()
  68. {
  69. if( m_pstrMachinename != NULL )
  70. {
  71. delete[] m_pstrMachinename;
  72. }
  73. if( m_pstrUsername != NULL )
  74. {
  75. delete[] m_pstrUsername;
  76. }
  77. for( int tt = 0 ; tt < NUM_OF_PAGES ; ++tt )
  78. {
  79. if( m_pDlg[ tt ] != NULL )
  80. {
  81. delete m_pDlg[ tt ];
  82. }
  83. }
  84. if( m_pUserSid != NULL )
  85. {
  86. delete[] m_pUserSid;
  87. }
  88. ODS( TEXT("Main object released!\n") );
  89. }
  90. //-------------------------------------------------------------------------------
  91. // AddRef
  92. //-------------------------------------------------------------------------------
  93. UINT CTSUserSheet::AddRef( )
  94. {
  95. return ++m_cref;
  96. }
  97. //-------------------------------------------------------------------------------
  98. // Release
  99. //-------------------------------------------------------------------------------
  100. UINT CTSUserSheet::Release( )
  101. {
  102. if( --m_cref == 0 )
  103. {
  104. delete this;
  105. return 0;
  106. }
  107. return m_cref;
  108. }
  109. //-------------------------------------------------------------------------------
  110. // SetServerAndUser
  111. //-------------------------------------------------------------------------------
  112. BOOL CTSUserSheet::SetServerAndUser( LPWSTR pwstrMachineName , LPWSTR pwstrUserName )
  113. {
  114. if( pwstrMachineName != NULL && pwstrUserName != NULL )
  115. {
  116. KdPrint( ("TSUSEREX : SystemName %ws UserName %ws\n",pwstrMachineName,pwstrUserName) );
  117. DWORD dwLen = wcslen( pwstrMachineName );
  118. m_pstrMachinename = ( LPTSTR )new TCHAR [ dwLen + 1 ];
  119. if( m_pstrMachinename != NULL )
  120. {
  121. COPYWCHAR2TCHAR( m_pstrMachinename , pwstrMachineName );
  122. }
  123. dwLen = wcslen( pwstrUserName );
  124. m_pstrUsername = ( LPTSTR )new TCHAR[ dwLen + 1 ];
  125. if( m_pstrUsername != NULL )
  126. {
  127. COPYWCHAR2TCHAR( m_pstrUsername , pwstrUserName );
  128. }
  129. return TRUE;
  130. }
  131. return FALSE;
  132. }
  133. //-------------------------------------------------------------------------------
  134. // AddPagesToPropSheet
  135. //-------------------------------------------------------------------------------
  136. HRESULT CTSUserSheet::AddPagesToPropSheet( LPPROPERTYSHEETCALLBACK pProvider )
  137. {
  138. PROPSHEETPAGE psp;
  139. //
  140. // List of objects goes here
  141. //
  142. m_pDlg[0] = new CEnviroDlg( this );
  143. m_pDlg[1] = new CTimeOutDlg( this );
  144. m_pDlg[2] = new CShadowDlg( this );
  145. m_pDlg[3] = new CProfileDlg( this );
  146. //
  147. // Let each object initialize there own propsheet
  148. //
  149. for( int idx = 0; idx < NUM_OF_PAGES; ++idx )
  150. {
  151. if( m_pDlg[ idx ] != NULL )
  152. {
  153. if( !m_pDlg[ idx ]->GetPropertySheetPage( psp ) )
  154. {
  155. continue;
  156. }
  157. if( FAILED( pProvider->AddPage( CreatePropertySheetPage( &psp ) ) ) )
  158. {
  159. return E_FAIL;
  160. }
  161. }
  162. }
  163. return S_OK;
  164. }
  165. //-------------------------------------------------------------------------------
  166. // AddPagesToDSAPropSheet
  167. //-------------------------------------------------------------------------------
  168. HRESULT CTSUserSheet::AddPagesToDSAPropSheet( LPFNADDPROPSHEETPAGE lpfnAddPage , LPARAM lp )
  169. {
  170. PROPSHEETPAGE psp;
  171. //
  172. // List of objects goes here
  173. //
  174. m_pDlg[0] = new CEnviroDlg( this );
  175. m_pDlg[1] = new CTimeOutDlg( this );
  176. m_pDlg[2] = new CShadowDlg( this );
  177. m_pDlg[3] = new CProfileDlg( this );
  178. //
  179. // Let each object initialize there own propsheet
  180. //
  181. for( int idx = 0; idx < NUM_OF_PAGES; ++idx )
  182. {
  183. if( m_pDlg[ idx ] != NULL )
  184. {
  185. if( !m_pDlg[ idx ]->GetPropertySheetPage( psp ) )
  186. {
  187. continue;
  188. }
  189. lpfnAddPage( CreatePropertySheetPage( &psp ) , lp );
  190. }
  191. }
  192. return S_OK;
  193. }
  194. //-------------------------------------------------------------------------------
  195. // SetUserConfig
  196. //-------------------------------------------------------------------------------
  197. BOOL CTSUserSheet::SetUserConfig( USERCONFIG& uc , PDWORD pdwStatus )
  198. {
  199. ASSERT_( pdwStatus != NULL );
  200. if( IsBadReadPtr( &uc , sizeof( USERCONFIG ) ) )
  201. {
  202. return FALSE;
  203. }
  204. //
  205. //
  206. // mov esi,dword ptr [uc]
  207. // mov edi,dword ptr [this]
  208. // add edi,1Ch
  209. // mov ecx,27Ah
  210. // rep movs dword ptr es:[edi],dword ptr [esi]
  211. //
  212. // is the codegen for struct = struct
  213. //
  214. m_userconfig = uc;
  215. #if BETA_3
  216. TCHAR tchServerName[ MAX_PATH ];
  217. if( m_bDC )
  218. {
  219. ODS( L"TSUSEREX - Saving settings on remote or local-dc system\n" );
  220. lstrcpy( tchServerName , m_szRemoteServerName );
  221. }
  222. else
  223. {
  224. lstrcpy( tchServerName , m_pstrMachinename );
  225. }
  226. #endif // BETA_3
  227. if( ( *pdwStatus = RegUserConfigSet( m_pstrMachinename , m_pstrUsername , &m_userconfig , sizeof( USERCONFIG ) ) ) == ERROR_SUCCESS )
  228. {
  229. return TRUE;
  230. }
  231. return FALSE;
  232. }
  233. //-------------------------------------------------------------------------------
  234. // GetCurrentUserConfig
  235. //-------------------------------------------------------------------------------
  236. USERCONFIG& CTSUserSheet::GetCurrentUserConfig( PDWORD pdwStatus )
  237. {
  238. *pdwStatus = ERROR_SUCCESS;
  239. if( !m_bIsConfigLoaded )
  240. {
  241. m_bIsConfigLoaded = GetUserConfig( pdwStatus );
  242. }
  243. // ASSERT_( m_bIsConfigLoaded );
  244. return m_userconfig;
  245. }
  246. //-------------------------------------------------------------------------------
  247. // GetUserConfig
  248. //-------------------------------------------------------------------------------
  249. BOOL CTSUserSheet::GetUserConfig( PDWORD pdwStatus )
  250. {
  251. ASSERT_( pdwStatus != NULL );
  252. //
  253. // This should only be called once
  254. //
  255. DWORD cbWritten = 0;
  256. #if BETA_3
  257. PSERVER_INFO_101 psinfo;
  258. // check to see if we're trying to administer a local system that happens to be a dc
  259. *pdwStatus = NetServerGetInfo( NULL , 101 , ( LPBYTE * )&psinfo );
  260. KdPrint( ("TSUSEREX : NetServerGetInfo returned 0x%x\n",*pdwStatus ) );
  261. KdPrint( ("TSUSEREX : LastError was 0x%x\n",GetLastError( ) ) );
  262. if( *pdwStatus == NERR_Success )
  263. {
  264. // used to avoid access violation
  265. if( psinfo != NULL )
  266. {
  267. KdPrint( ("TSUSEREX : PSERVER_INFO_101 returned 0x%x\n",psinfo->sv101_type ) );
  268. m_bDC = ( BOOL )( psinfo->sv101_type & ( SV_TYPE_DOMAIN_CTRL | SV_TYPE_DOMAIN_BAKCTRL ) );
  269. if( m_bDC )
  270. {
  271. // get the domaincontroller name of the remote machine
  272. DOMAIN_CONTROLLER_INFO *pdinfo;
  273. // m_pstrMachinename is really the domain name. This was obtain
  274. // from LookUpAccountSid in interfaces.cpp
  275. *pdwStatus = DsGetDcName( NULL , m_pstrMachinename , NULL , NULL , DS_PDC_REQUIRED , &pdinfo );
  276. KdPrint( ( "TSUSEREX : DsGetDcName: %ws returned 0x%x\n", pdinfo->DomainControllerName , *pdwStatus ) );
  277. if( *pdwStatus == NO_ERROR )
  278. {
  279. lstrcpy( m_szRemoteServerName , pdinfo->DomainControllerName );
  280. NetApiBufferFree( pdinfo );
  281. }
  282. else
  283. {
  284. m_szRemoteServerName[0] = 0;
  285. }
  286. }
  287. // not documented in the docs but NetServerGetInfo leaves it up to the caller to free up this blob
  288. NetApiBufferFree( psinfo );
  289. }
  290. TCHAR tchServerName[ MAX_PATH ];
  291. if( m_bDC )
  292. {
  293. lstrcpy( tchServerName , m_szRemoteServerName );
  294. }
  295. else
  296. {
  297. lstrcpy( tchServerName , m_pstrMachinename );
  298. }
  299. if( ( *pdwStatus = ( DWORD )RegUserConfigQuery( tchServerName , m_pstrUsername , &m_userconfig , sizeof( USERCONFIG ) , &cbWritten ) ) == ERROR_SUCCESS )
  300. {
  301. return TRUE;
  302. }
  303. }
  304. #endif // BETA_3
  305. if( ( *pdwStatus = ( DWORD )RegUserConfigQuery( m_pstrMachinename , m_pstrUsername , &m_userconfig , sizeof( USERCONFIG ) , &cbWritten ) ) == ERROR_SUCCESS )
  306. {
  307. return TRUE;
  308. }
  309. ODS( L"TSUSEREX: We're getting default properties\n" );
  310. RegDefaultUserConfigQuery( m_pstrMachinename , &m_userconfig , sizeof( USERCONFIG ) , &cbWritten );
  311. return FALSE;
  312. }
  313. void CTSUserSheet::CopyUserSid( PSID psid )
  314. {
  315. if( !IsValidSid( psid ) )
  316. {
  317. ODS( L"TSUSEREX : CTSUserSheet::CopyUserSid invalid arg\n" ) ;
  318. return;
  319. }
  320. m_pUserSid = psid;
  321. }
  322. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  323. //-------------------------------------------------------------------------------
  324. // Base class initi
  325. //-------------------------------------------------------------------------------
  326. CDialogBase::CDialogBase( )
  327. {
  328. m_hWnd = NULL;
  329. }
  330. //-------------------------------------------------------------------------------
  331. // Base initialization
  332. //-------------------------------------------------------------------------------
  333. BOOL CDialogBase::OnInitDialog( HWND hwnd , WPARAM , LPARAM )
  334. {
  335. m_hWnd = hwnd;
  336. return FALSE;
  337. }
  338. //-------------------------------------------------------------------------------
  339. // OnNotify - base class method
  340. //-------------------------------------------------------------------------------
  341. BOOL CDialogBase::OnNotify( int , LPNMHDR pnmh , HWND hDlg )
  342. {
  343. if( pnmh->code == PSN_APPLY )
  344. {
  345. if( !m_bPersisted )
  346. {
  347. m_bPersisted = PersistSettings( hDlg );
  348. }
  349. }
  350. else if( pnmh->code == PSN_KILLACTIVE )
  351. {
  352. if( !m_bPersisted )
  353. {
  354. if( !IsValidSettings( hDlg ) )
  355. {
  356. SetWindowLongPtr( hDlg , DWLP_MSGRESULT , PSNRET_INVALID_NOCHANGEPAGE );
  357. return TRUE;
  358. }
  359. }
  360. }
  361. return FALSE;
  362. }
  363. //-------------------------------------------------------------------------------
  364. // OnCOntextMenu -- base class operation
  365. //-------------------------------------------------------------------------------
  366. BOOL CDialogBase::OnContextMenu( HWND hwnd , POINT& )
  367. {
  368. TCHAR tchHelpFile[ MAX_PATH ];
  369. if( m_hWnd == GetParent( hwnd ) )
  370. {
  371. //
  372. // Make sure its not a dummy window
  373. //
  374. if( GetDlgCtrlID( hwnd ) <= ( int )-1 )
  375. {
  376. return FALSE;
  377. }
  378. DWORD rgdw[ 2 ];
  379. rgdw[ 0 ] = GetDlgCtrlID( hwnd );
  380. rgdw[ 1 ] = GetWindowContextHelpId( hwnd );
  381. LoadString( _Module.GetModuleInstance( ) , IDS_HELPFILE , tchHelpFile , sizeof( tchHelpFile ) / sizeof( TCHAR ) );
  382. WinHelp( hwnd , tchHelpFile , HELP_CONTEXTMENU , (ULONG_PTR)&rgdw );
  383. }
  384. return TRUE;
  385. }
  386. //-------------------------------------------------------------------------------
  387. // Each control has a helpid assign to them. Some controls share the same topic
  388. // check for these.
  389. //-------------------------------------------------------------------------------
  390. BOOL CDialogBase::OnHelp( HWND hwnd , LPHELPINFO lphi )
  391. {
  392. TCHAR tchHelpFile[ MAX_PATH ];
  393. //
  394. // For the information to winhelp api
  395. //
  396. if( IsBadReadPtr( lphi , sizeof( HELPINFO ) ) )
  397. {
  398. return FALSE;
  399. }
  400. if( lphi->iCtrlId <= -1 )
  401. {
  402. return FALSE;
  403. }
  404. LoadString( _Module.GetModuleInstance( ) , IDS_HELPFILE , tchHelpFile , sizeof( tchHelpFile ) / sizeof( TCHAR ) );
  405. WinHelp( hwnd , tchHelpFile , HELP_CONTEXTPOPUP , lphi->dwContextId );
  406. return TRUE;
  407. }
  408. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  409. //-------------------------------------------------------------------------------
  410. // CEnviroDlg::ctor
  411. //-------------------------------------------------------------------------------
  412. CEnviroDlg::CEnviroDlg( CTSUserSheet *pUSht )
  413. {
  414. m_pUSht = pUSht;
  415. }
  416. //-------------------------------------------------------------------------------
  417. // InitDialog for ProfileDlg
  418. //-------------------------------------------------------------------------------
  419. BOOL CEnviroDlg::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  420. {
  421. DWORD dwStatus;
  422. if( IsBadReadPtr( m_pUSht ,sizeof( CTSUserSheet ) ) )
  423. {
  424. return FALSE;
  425. }
  426. m_pUSht->AddRef( );
  427. USERCONFIG uc;
  428. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  429. // This means any true problems from obtaining user info from the sam
  430. // will disable this dialog
  431. if( dwStatus != ERROR_FILE_NOT_FOUND && dwStatus != ERROR_SUCCESS )
  432. {
  433. INT nId[ ] = {
  434. IDC_CHECK_USEDEFAULT,
  435. IDC_EDIT_CMDLINE,
  436. IDC_EDIT_WDIR,
  437. IDC_CHECK_CCDL,
  438. IDC_CHECK_CCPL,
  439. IDC_CHECK_DMCP,
  440. -1
  441. };
  442. for( int idx = 0; nId[ idx ] != -1 ; ++idx )
  443. {
  444. EnableWindow( GetDlgItem( hwnd , nId[ idx ] ) , FALSE );
  445. }
  446. ErrorMessage1( hwnd , dwStatus );
  447. return FALSE;
  448. }
  449. SendMessage( GetDlgItem( hwnd , IDC_EDIT_CMDLINE ) , EM_SETLIMITTEXT , ( WPARAM )DIRECTORY_LENGTH , 0 );
  450. SendMessage( GetDlgItem( hwnd , IDC_EDIT_WDIR ) , EM_SETLIMITTEXT , ( WPARAM )DIRECTORY_LENGTH , 0 );
  451. //
  452. // Set controls to default status
  453. //
  454. SendMessage( GetDlgItem( hwnd , IDC_CHECK_USEDEFAULT ) , BM_SETCHECK , !( WPARAM )uc.fInheritInitialProgram , 0 );
  455. SetWindowText( GetDlgItem( hwnd , IDC_EDIT_WDIR ) , uc.WorkDirectory );
  456. SetWindowText( GetDlgItem( hwnd , IDC_EDIT_CMDLINE ) , uc.InitialProgram ) ;
  457. EnableWindow( GetDlgItem( hwnd , IDC_EDIT_WDIR ) , !uc.fInheritInitialProgram );
  458. EnableWindow( GetDlgItem( hwnd , IDC_EDIT_CMDLINE ) , !uc.fInheritInitialProgram );
  459. EnableWindow( GetDlgItem( hwnd , IDC_STATIC_WD ) , !uc.fInheritInitialProgram );
  460. EnableWindow( GetDlgItem( hwnd , IDC_STATIC_CMD ) , !uc.fInheritInitialProgram );
  461. //
  462. // The controls are initially enabled - - resetting them is done
  463. // via WM_COMMAND
  464. //
  465. SendMessage( GetDlgItem( hwnd , IDC_CHECK_CCDL ) , BM_SETCHECK , ( WPARAM )uc.fAutoClientDrives , 0 );
  466. SendMessage( GetDlgItem( hwnd , IDC_CHECK_CCPL ) , BM_SETCHECK , ( WPARAM )uc.fAutoClientLpts , 0 );
  467. SendMessage( GetDlgItem( hwnd , IDC_CHECK_DMCP ) , BM_SETCHECK , ( WPARAM )uc.fForceClientLptDef , 0 );
  468. m_bPersisted = TRUE;
  469. return CDialogBase::OnInitDialog( hwnd , wp , lp );
  470. }
  471. //-------------------------------------------------------------------------------
  472. // Environment Dialog Page
  473. // -- static methods lacks this ptr
  474. //-------------------------------------------------------------------------------
  475. INT_PTR CALLBACK CEnviroDlg::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  476. {
  477. CEnviroDlg *pDlg;
  478. if( msg == WM_INITDIALOG )
  479. {
  480. CEnviroDlg *pDlg = ( CEnviroDlg * )( ( PROPSHEETPAGE *)lp )->lParam ;
  481. //
  482. // Don't use a static pointer here
  483. // There will be concurrency issues
  484. //
  485. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  486. if( !IsBadReadPtr( pDlg , sizeof( CEnviroDlg ) ) )
  487. {
  488. pDlg->OnInitDialog( hwnd , wp , lp );
  489. }
  490. return 0;
  491. }
  492. else
  493. {
  494. pDlg = ( CEnviroDlg * )GetWindowLongPtr( hwnd , DWLP_USER );
  495. if( IsBadReadPtr( pDlg , sizeof( CEnviroDlg ) ) )
  496. {
  497. return FALSE;
  498. }
  499. }
  500. switch( msg )
  501. {
  502. case WM_NCDESTROY:
  503. pDlg->OnDestroy( );
  504. break;
  505. case WM_COMMAND:
  506. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  507. break;
  508. case WM_NOTIFY:
  509. pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  510. break;
  511. case WM_HELP:
  512. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  513. break;
  514. case WM_RBUTTONUP:
  515. {
  516. POINT pt;
  517. pt.x = LOWORD( lp );
  518. pt.y = HIWORD( lp );
  519. HWND hChild = ChildWindowFromPoint( hwnd , pt );
  520. ClientToScreen( hwnd , &pt );
  521. pDlg->OnContextMenu( hChild , pt );
  522. }
  523. break;
  524. case WM_CONTEXTMENU:
  525. {
  526. POINT pt;
  527. pt.x = LOWORD( lp );
  528. pt.y = HIWORD( lp );
  529. pDlg->OnContextMenu( ( HWND )wp , pt );
  530. }
  531. }
  532. return 0;
  533. }
  534. //-------------------------------------------------------------------------------
  535. // Basic control notification handler
  536. //-------------------------------------------------------------------------------
  537. void CEnviroDlg::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtl )
  538. {
  539. switch( wNotifyCode )
  540. {
  541. case BN_CLICKED:
  542. if( wID == IDC_CHECK_USEDEFAULT )
  543. {
  544. //
  545. // Remember if its checked we want to disable the options
  546. //
  547. HWND hwnd = GetParent( hwndCtl );
  548. BOOL bChecked = SendMessage( hwndCtl , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  549. EnableWindow( GetDlgItem( hwnd , IDC_EDIT_WDIR ) , bChecked );
  550. EnableWindow( GetDlgItem( hwnd , IDC_EDIT_CMDLINE ) , bChecked );
  551. EnableWindow( GetDlgItem( hwnd , IDC_STATIC_WD ) , bChecked );
  552. EnableWindow( GetDlgItem( hwnd , IDC_STATIC_CMD ) , bChecked );
  553. } // FALL THROUGH !!!!
  554. case EN_CHANGE:
  555. m_bPersisted = FALSE;
  556. break;
  557. case ALN_APPLY:
  558. SendMessage( GetParent( hwndCtl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  559. break;
  560. }
  561. if( !m_bPersisted )
  562. {
  563. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  564. }
  565. }
  566. //-------------------------------------------------------------------------------
  567. // OnDestroy
  568. //-------------------------------------------------------------------------------
  569. BOOL CEnviroDlg::OnDestroy( )
  570. {
  571. if( !IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  572. {
  573. ODS(TEXT("Releasing from CEnviroDlg\n"));
  574. m_pUSht->Release( );
  575. }
  576. return CDialogBase::OnDestroy( );
  577. }
  578. //-------------------------------------------------------------------------------
  579. // GetPropertySheetPage - each dialog object should be responsible for its own data
  580. //-------------------------------------------------------------------------------
  581. BOOL CEnviroDlg::GetPropertySheetPage( PROPSHEETPAGE& psp)
  582. {
  583. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  584. psp.dwSize = sizeof( PROPSHEETPAGE );
  585. psp.dwFlags = PSP_DEFAULT;
  586. psp.hInstance = _Module.GetModuleInstance( );
  587. psp.pszTemplate = MAKEINTRESOURCE( IDD_PAGE_ENVIRO );
  588. psp.lParam = ( LPARAM )this;
  589. psp.pfnDlgProc = CEnviroDlg::DlgProc;
  590. return TRUE;
  591. }
  592. //-------------------------------------------------------------------------------
  593. // PersistSettings
  594. //-------------------------------------------------------------------------------
  595. BOOL CEnviroDlg::PersistSettings( HWND hDlg )
  596. {
  597. DWORD dwStatus;
  598. if( IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  599. {
  600. return FALSE;
  601. }
  602. USERCONFIG uc;
  603. TCHAR tchBuffer[ DIRECTORY_LENGTH + 1 ];
  604. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  605. //
  606. // if use default is checked -- lets flag it and move on to client devices
  607. //
  608. //
  609. // if the chkbx is unchecked we inherit from client side settings
  610. //
  611. uc.fInheritInitialProgram = SendMessage( GetDlgItem( hDlg , IDC_CHECK_USEDEFAULT ) , BM_GETCHECK ,
  612. 0 , 0 ) == BST_CHECKED ? FALSE : TRUE;
  613. if( !uc.fInheritInitialProgram )
  614. {
  615. //
  616. // Read buffer and commit to USERCONFIG buffer
  617. //
  618. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_WDIR ) , &tchBuffer[ 0 ] , sizeof( tchBuffer ) / sizeof( TCHAR ) );
  619. lstrcpy( uc.WorkDirectory , tchBuffer );
  620. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_CMDLINE ) , &tchBuffer[ 0 ] , sizeof( tchBuffer ) / sizeof( TCHAR ) );
  621. lstrcpy( uc.InitialProgram , tchBuffer );
  622. }
  623. uc.fAutoClientDrives = SendMessage( GetDlgItem( hDlg , IDC_CHECK_CCDL ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  624. uc.fAutoClientLpts = SendMessage( GetDlgItem( hDlg , IDC_CHECK_CCPL ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  625. uc.fForceClientLptDef = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DMCP ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  626. if( !m_pUSht->SetUserConfig( uc , &dwStatus ) )
  627. {
  628. ErrorMessage2( hDlg , dwStatus );
  629. return TRUE;
  630. }
  631. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  632. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  633. return TRUE;
  634. }
  635. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  636. DWORD rgdwTime[] = { 0 , 1 , 5 , 10 , 15 , 30 , 60 , 120 , 180 , 1440 , 2880 , ( DWORD )-1 };
  637. //-------------------------------------------------------------------------------
  638. // CTimeOutDlg::ctor
  639. //-------------------------------------------------------------------------------
  640. CTimeOutDlg::CTimeOutDlg( CTSUserSheet *pUSht )
  641. {
  642. m_pUSht = pUSht;
  643. ZeroMemory( &m_cbxst , sizeof( CBXSTATE ) * 3 );
  644. m_wAction = ( WORD)-1;
  645. m_wCon = ( WORD )-1;
  646. ZeroMemory( &m_tokday , sizeof( TOKTABLE ) * 4 );
  647. ZeroMemory( &m_tokhour , sizeof( TOKTABLE ) * 6 );
  648. ZeroMemory( &m_tokmin , sizeof( TOKTABLE ) * 5 );
  649. }
  650. //-------------------------------------------------------------------------------
  651. void CTimeOutDlg::InitTokTables( )
  652. {
  653. TOKTABLE tday[4] = { { NULL , IDS_D },
  654. { NULL , IDS_DAY },
  655. { NULL , IDS_DAYS },
  656. { NULL , ( DWORD )-1 }
  657. };
  658. TOKTABLE thour[ 6 ] = {
  659. { NULL , IDS_H },
  660. { NULL , IDS_HR },
  661. { NULL , IDS_HRS },
  662. { NULL , IDS_HOUR },
  663. { NULL , IDS_HOURS },
  664. { NULL , ( DWORD )-1 }
  665. };
  666. TOKTABLE tmin[ 5 ] = {
  667. { NULL , IDS_M },
  668. { NULL , IDS_MIN },
  669. { NULL , IDS_MINUTE },
  670. { NULL , IDS_MINUTES },
  671. { NULL , ( DWORD )-1 }
  672. };
  673. CopyMemory( &m_tokday[0] , &tday[0] , sizeof( TOKTABLE ) * 4 );
  674. CopyMemory( &m_tokhour[0] , &thour[0] , sizeof( TOKTABLE ) * 6 );
  675. CopyMemory( &m_tokmin[0] , &tmin[0] , sizeof( TOKTABLE ) * 5 );
  676. }
  677. //-------------------------------------------------------------------------------
  678. // InitDialog for TimeOutDlg
  679. //-------------------------------------------------------------------------------
  680. BOOL CTimeOutDlg::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  681. {
  682. TCHAR tchBuffer[ 80 ];
  683. DWORD dwStatus;
  684. USERCONFIG uc;
  685. if( IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  686. {
  687. return FALSE;
  688. }
  689. m_pUSht->AddRef( );
  690. InitTokTables( );
  691. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  692. if( dwStatus != ERROR_FILE_NOT_FOUND && dwStatus != ERROR_SUCCESS )
  693. {
  694. INT nId[ ] = {
  695. IDC_COMBO_CONNECT,
  696. IDC_COMBO_DISCON,
  697. IDC_COMBO_IDLE,
  698. IDC_RADIO_RESET,
  699. IDC_RADIO_DISCON,
  700. IDC_RADIO_PREVCLIENT,
  701. IDC_RADIO_ANYCLIENT,
  702. -1
  703. };
  704. for( int idx = 0; nId[ idx ] != -1 ; ++idx )
  705. {
  706. EnableWindow( GetDlgItem( hwnd , nId[ idx ] ) , FALSE );
  707. }
  708. ErrorMessage1( hwnd , dwStatus );
  709. return FALSE;
  710. }
  711. //
  712. // First thing is to set the default values for all the controls
  713. //
  714. HWND hCombo[ 3 ] =
  715. {
  716. GetDlgItem( hwnd , IDC_COMBO_CONNECT ),
  717. GetDlgItem( hwnd , IDC_COMBO_DISCON ),
  718. GetDlgItem( hwnd , IDC_COMBO_IDLE )
  719. };
  720. for( int idx = 0; rgdwTime[ idx ] != ( DWORD)-1; ++idx )
  721. {
  722. if( rgdwTime[ idx ] == 0 )
  723. {
  724. LoadString( _Module.GetResourceInstance( ) , IDS_NOTIMEOUT , tchBuffer , sizeof( tchBuffer ) / sizeof( TCHAR ) );
  725. }
  726. else
  727. {
  728. ConvertToDuration( rgdwTime[ idx ] , tchBuffer );
  729. }
  730. for( int inner = 0 ; inner < 3 ; ++inner )
  731. {
  732. SendMessage( hCombo[ inner ] , CB_ADDSTRING , 0 , ( LPARAM )&tchBuffer[0] );
  733. SendMessage( hCombo[ inner ] , CB_SETITEMDATA , idx , rgdwTime[ idx ] );
  734. }
  735. }
  736. ULONG ulTime;
  737. if( uc.MaxConnectionTime > 0 )
  738. {
  739. ulTime = uc.MaxConnectionTime / kMilliMinute;
  740. // hCombo[ 0 ] == IDC_COMBO_CONNECT
  741. InsertSortedAndSetCurSel( hCombo[ 0 ] , ulTime );
  742. }
  743. else
  744. {
  745. SendMessage( hCombo[ 0 ] , CB_SETCURSEL , 0 , 0 );
  746. }
  747. //
  748. // Set the current or default disconnection timeout
  749. //
  750. if( uc.MaxDisconnectionTime > 0 )
  751. {
  752. ulTime = uc.MaxDisconnectionTime / kMilliMinute;
  753. // hCombo[ 1 ] == IDC_COMBO_DISCON
  754. InsertSortedAndSetCurSel( hCombo[ 1 ] , ulTime );
  755. }
  756. else
  757. {
  758. SendMessage( hCombo[ 1] , CB_SETCURSEL , 0 , 0 );
  759. }
  760. //
  761. // Set the current or default idle timeout
  762. //
  763. if( uc.MaxIdleTime > 0 )
  764. {
  765. ulTime = uc.MaxIdleTime / kMilliMinute;
  766. // hCombo[ 2 ] == IDC_COMBO_IDLE
  767. InsertSortedAndSetCurSel( hCombo[ 2 ] , ulTime );
  768. }
  769. else
  770. {
  771. SendMessage( hCombo[ 2 ] , CB_SETCURSEL , 0 , 0 );
  772. }
  773. //
  774. // Set remaining controls to current settings
  775. //
  776. if( uc.fResetBroken )
  777. {
  778. SendMessage( GetDlgItem( hwnd , IDC_RADIO_RESET ) , BM_CLICK , 0 , 0 );
  779. m_wAction = IDC_RADIO_RESET;
  780. }
  781. else
  782. {
  783. SendMessage( GetDlgItem( hwnd , IDC_RADIO_DISCON ) , BM_CLICK , 0 , 0 );
  784. m_wAction = IDC_RADIO_DISCON;
  785. }
  786. if( uc.fReconnectSame )
  787. {
  788. SendMessage( GetDlgItem( hwnd , IDC_RADIO_PREVCLIENT ) , BM_CLICK , 0 ,0 );
  789. m_wCon = IDC_RADIO_PREVCLIENT;
  790. }
  791. else
  792. {
  793. SendMessage( GetDlgItem( hwnd , IDC_RADIO_ANYCLIENT ) , BM_CLICK , 0 , 0 );
  794. m_wCon = IDC_RADIO_ANYCLIENT;
  795. }
  796. LoadAbbreviates( );
  797. m_bPersisted = TRUE;
  798. return CDialogBase::OnInitDialog( hwnd , wp , lp );
  799. }
  800. //-------------------------------------------------------------------------------
  801. // TimeOutDlg Dialog Page
  802. // -- static methods lacks this ptr
  803. //-------------------------------------------------------------------------------
  804. INT_PTR CALLBACK CTimeOutDlg::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  805. {
  806. CTimeOutDlg *pDlg;
  807. if( msg == WM_INITDIALOG )
  808. {
  809. CTimeOutDlg *pDlg = ( CTimeOutDlg * )( ( PROPSHEETPAGE *)lp )->lParam ;
  810. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  811. if( !IsBadReadPtr( pDlg , sizeof( CTimeOutDlg ) ) )
  812. {
  813. pDlg->OnInitDialog( hwnd , wp , lp );
  814. }
  815. return 0;
  816. }
  817. else
  818. {
  819. pDlg = ( CTimeOutDlg * )GetWindowLongPtr( hwnd , DWLP_USER );
  820. if( IsBadReadPtr( pDlg , sizeof( CTimeOutDlg ) ) )
  821. {
  822. return FALSE;
  823. }
  824. }
  825. switch( msg )
  826. {
  827. case WM_NCDESTROY:
  828. pDlg->OnDestroy( );
  829. break;
  830. case WM_COMMAND:
  831. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  832. break;
  833. case WM_NOTIFY:
  834. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  835. case WM_HELP:
  836. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  837. break;
  838. case WM_RBUTTONUP:
  839. {
  840. POINT pt;
  841. pt.x = LOWORD( lp );
  842. pt.y = HIWORD( lp );
  843. HWND hChild = ChildWindowFromPoint( hwnd , pt );
  844. ClientToScreen( hwnd , &pt );
  845. pDlg->OnContextMenu( hChild , pt );
  846. }
  847. break;
  848. case WM_CONTEXTMENU:
  849. {
  850. POINT pt;
  851. pt.x = LOWORD( lp );
  852. pt.y = HIWORD( lp );
  853. pDlg->OnContextMenu( ( HWND )wp , pt );
  854. }
  855. }
  856. return 0;
  857. }
  858. //-------------------------------------------------------------------------------
  859. // release the parent reference
  860. //-------------------------------------------------------------------------------
  861. BOOL CTimeOutDlg::OnDestroy( )
  862. {
  863. xxxUnLoadAbbreviate( &m_tokday[0] );
  864. xxxUnLoadAbbreviate( &m_tokhour[0] );
  865. xxxUnLoadAbbreviate( &m_tokmin[0] );
  866. if( !IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  867. {
  868. ODS(TEXT("Releasing from CTimeOutDlg\n"));
  869. m_pUSht->Release( );
  870. }
  871. return CDialogBase::OnDestroy( );
  872. }
  873. //-------------------------------------------------------------------------------
  874. // GetPropertySheetPage - each dialog object should be responsible for its own data
  875. //-------------------------------------------------------------------------------
  876. BOOL CTimeOutDlg::GetPropertySheetPage( PROPSHEETPAGE& psp)
  877. {
  878. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  879. psp.dwSize = sizeof( PROPSHEETPAGE );
  880. psp.dwFlags = PSP_DEFAULT;
  881. psp.hInstance = _Module.GetModuleInstance( );
  882. psp.pszTemplate = MAKEINTRESOURCE( IDD_PAGE_TIMEOUTS );
  883. psp.lParam = ( LPARAM )this;
  884. psp.pfnDlgProc = CTimeOutDlg::DlgProc;
  885. return TRUE;
  886. }
  887. //-------------------------------------------------------------------------------
  888. // OnCommand
  889. //-------------------------------------------------------------------------------
  890. void CTimeOutDlg::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtl )
  891. {
  892. switch( wNotifyCode )
  893. {
  894. case CBN_EDITCHANGE:
  895. OnCBEditChange( hwndCtl );
  896. m_bPersisted = FALSE;
  897. break;
  898. case CBN_SELCHANGE:
  899. if( SendMessage( hwndCtl , CB_GETDROPPEDSTATE , 0 ,0 ) == TRUE )
  900. {
  901. return;
  902. }
  903. OnCBNSELCHANGE( hwndCtl ); // FALLTHROUGH
  904. // m_bPersisted = FALSE;
  905. break;
  906. case BN_CLICKED:
  907. if( wID == IDC_RADIO_DISCON || wID == IDC_RADIO_RESET )
  908. {
  909. if( m_wAction != wID )
  910. {
  911. m_wAction = wID;
  912. m_bPersisted = FALSE;
  913. }
  914. }
  915. else if( wID == IDC_RADIO_PREVCLIENT || wID == IDC_RADIO_ANYCLIENT )
  916. {
  917. if( m_wCon != wID )
  918. {
  919. m_wCon = wID;
  920. m_bPersisted = FALSE;
  921. }
  922. }
  923. break;
  924. //case CBN_DROPDOWN: // FALLTHROUGH
  925. case CBN_KILLFOCUS:
  926. ODS( L"CBN_KILLFOCUS\n");
  927. if( !OnCBDropDown( hwndCtl ) )
  928. {
  929. return;
  930. }
  931. m_bPersisted = FALSE;
  932. break;
  933. case ALN_APPLY:
  934. SendMessage( GetParent( hwndCtl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  935. return;
  936. }
  937. if( !m_bPersisted )
  938. {
  939. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  940. }
  941. }
  942. //-------------------------------------------------------------------------------
  943. // Update the entry if it has been modified by user
  944. //-------------------------------------------------------------------------------
  945. BOOL CTimeOutDlg::OnCBDropDown( HWND hCombo )
  946. {
  947. TCHAR tchBuffer[ 80 ];
  948. ULONG ulTime = 0;
  949. int i = GetCBXSTATEindex( hCombo );
  950. if( i < 0 )
  951. {
  952. return FALSE;
  953. }
  954. if( m_cbxst[ i ].bEdit )
  955. {
  956. GetWindowText( hCombo , tchBuffer , sizeof( tchBuffer ) / sizeof( TCHAR ) );
  957. if( ParseDurationEntry( tchBuffer , &ulTime ) == E_SUCCESS )
  958. {
  959. InsertSortedAndSetCurSel( hCombo , ulTime );
  960. }
  961. }
  962. return m_cbxst[ i ].bEdit;
  963. }
  964. //-------------------------------------------------------------------------------
  965. // Use this flag to distinguish between hand entry or listbox selection
  966. // setting it to true implies that the use has edit the cbx via typing
  967. //-------------------------------------------------------------------------------
  968. void CTimeOutDlg::OnCBEditChange( HWND hCombo )
  969. {
  970. int i = GetCBXSTATEindex( hCombo );
  971. if( i > -1 )
  972. {
  973. m_cbxst[ i ].bEdit = TRUE;
  974. }
  975. }
  976. //-------------------------------------------------------------------------------
  977. // Determine if user wants to enter a custom time
  978. //-------------------------------------------------------------------------------
  979. void CTimeOutDlg::OnCBNSELCHANGE( HWND hwnd )
  980. {
  981. if( SaveChangedSelection( hwnd ) )
  982. {
  983. m_bPersisted = FALSE;
  984. }
  985. }
  986. //-------------------------------------------------------------------------------
  987. // Saves selected item.
  988. //-------------------------------------------------------------------------------
  989. BOOL CTimeOutDlg::SaveChangedSelection( HWND hCombo )
  990. {
  991. LRESULT idx = SendMessage( hCombo , CB_GETCURSEL , 0 , 0 );
  992. int i = GetCBXSTATEindex( hCombo );
  993. if( i > -1 )
  994. {
  995. if( idx != ( LRESULT )m_cbxst[ i ].icbxSel )
  996. {
  997. m_cbxst[ i ].icbxSel = (int)idx;
  998. m_cbxst[ i ].bEdit = FALSE;
  999. return TRUE;
  1000. }
  1001. }
  1002. return FALSE;
  1003. }
  1004. //-------------------------------------------------------------------------------
  1005. // Restore previous setting
  1006. //-------------------------------------------------------------------------------
  1007. BOOL CTimeOutDlg::RestorePreviousValue( HWND hwnd )
  1008. {
  1009. int iSel;
  1010. if( ( iSel = GetCBXSTATEindex( hwnd ) ) > -1 )
  1011. {
  1012. SendMessage( hwnd , CB_SETCURSEL , m_cbxst[ iSel ].icbxSel , 0 );
  1013. return TRUE;
  1014. }
  1015. return FALSE;
  1016. }
  1017. //-------------------------------------------------------------------------------
  1018. // returns the indx in m_cbxst of which hcombo is assoc. with
  1019. //-------------------------------------------------------------------------------
  1020. int CTimeOutDlg::GetCBXSTATEindex( HWND hCombo )
  1021. {
  1022. int idx = -1;
  1023. switch( GetDlgCtrlID( hCombo ) )
  1024. {
  1025. case IDC_COMBO_CONNECT:
  1026. idx = 0;
  1027. break;
  1028. case IDC_COMBO_DISCON:
  1029. idx = 1;
  1030. break;
  1031. case IDC_COMBO_IDLE:
  1032. idx = 2;
  1033. break;
  1034. }
  1035. return idx;
  1036. }
  1037. //-------------------------------------------------------------------------------
  1038. // ConvertToMinutes -- helper for CTimeOutDlg::OnNotify
  1039. //-------------------------------------------------------------------------------
  1040. BOOL CTimeOutDlg::ConvertToMinutes( HWND hwndCtl , PULONG pulMinutes )
  1041. {
  1042. TCHAR tchBuffer[ 80 ];
  1043. TCHAR tchErrTitle[ 80 ];
  1044. TCHAR tchErrMsg[ 256 ];
  1045. TCHAR tchErrItem[ 80 ];
  1046. TCHAR tchErrTot[ 336 ];
  1047. int nComboResID[] = { IDS_COMBO_CONNECTION , IDS_COMBO_DISCONNECTION , IDS_COMBO_IDLECONNECTION };
  1048. int idx = GetCBXSTATEindex( hwndCtl );
  1049. if( idx < 0 )
  1050. {
  1051. return FALSE;
  1052. }
  1053. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErrTitle , sizeof( tchErrTitle ) / sizeof( TCHAR ) );
  1054. if( m_cbxst[ idx ].bEdit )
  1055. {
  1056. ODS( TEXT( "Manual Entry parsing\n") );
  1057. if( GetWindowText( hwndCtl , tchBuffer , sizeof( tchBuffer ) / sizeof( TCHAR ) ) < 1 )
  1058. {
  1059. *pulMinutes = 0;
  1060. return TRUE;
  1061. }
  1062. LRESULT lr = ParseDurationEntry( tchBuffer , pulMinutes );
  1063. if( lr != E_SUCCESS )
  1064. {
  1065. LoadString( _Module.GetResourceInstance( ) , nComboResID[ idx ] , tchErrItem , sizeof( tchErrItem ) / sizeof( TCHAR ) );
  1066. if( lr == E_PARSE_VALUEOVERFLOW )
  1067. {
  1068. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TOOMANYDIGITS , tchErrMsg , sizeof( tchErrMsg ) / sizeof( TCHAR ) );
  1069. wsprintf( tchErrTot , tchErrMsg , tchErrItem );
  1070. MessageBox( hwndCtl , tchErrTot , tchErrTitle , MB_OK | MB_ICONERROR );
  1071. SetFocus( hwndCtl );
  1072. }
  1073. else if( lr == E_PARSE_MISSING_DIGITS || lr == E_PARSE_INVALID )
  1074. {
  1075. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_PARSEINVALID , tchErrMsg , sizeof( tchErrMsg ) / sizeof( TCHAR ) );
  1076. wsprintf( tchErrTot , tchErrMsg , tchErrItem );
  1077. MessageBox( hwndCtl , tchErrTot , tchErrTitle , MB_OK | MB_ICONERROR );
  1078. SetFocus( hwndCtl );
  1079. }
  1080. return FALSE;
  1081. }
  1082. }
  1083. else
  1084. {
  1085. ODS( L"Getting current selection\n" );
  1086. LONG_PTR iCurSel = SendMessage( hwndCtl , CB_GETCURSEL , 0 , 0 );
  1087. LONG_PTR lData;
  1088. // See if user wants "No Timeout"
  1089. if( iCurSel == 0 )
  1090. {
  1091. *pulMinutes = 0;
  1092. return TRUE;
  1093. }
  1094. if( ( lData = SendMessage( hwndCtl , CB_GETITEMDATA , iCurSel , 0 ) ) == CB_ERR )
  1095. {
  1096. *pulMinutes = 0;
  1097. } else {
  1098. *pulMinutes = (ULONG)lData;
  1099. }
  1100. }
  1101. if( *pulMinutes > kMaxTimeoutMinute )
  1102. {
  1103. LoadString( _Module.GetResourceInstance( ) , nComboResID[ idx ] , tchErrItem , sizeof( tchErrItem ) / sizeof( TCHAR ) );
  1104. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_MAXVALEXCEEDED , tchErrMsg , sizeof( tchErrMsg ) / sizeof( TCHAR ) );
  1105. wsprintf( tchErrTot , tchErrMsg , tchErrItem );
  1106. MessageBox( hwndCtl , tchErrTot , tchErrTitle , MB_OK | MB_ICONERROR );
  1107. SetFocus( hwndCtl );
  1108. return FALSE;
  1109. }
  1110. *pulMinutes *= kMilliMinute;
  1111. return TRUE;
  1112. }
  1113. //-------------------------------------------------------------------------------
  1114. // PersistSettings
  1115. //-------------------------------------------------------------------------------
  1116. BOOL CTimeOutDlg::PersistSettings( HWND hDlg )
  1117. {
  1118. DWORD dwStatus;
  1119. if( IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  1120. {
  1121. return FALSE;
  1122. }
  1123. USERCONFIG uc;
  1124. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  1125. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_CONNECT ) , &uc.MaxConnectionTime ) )
  1126. {
  1127. return FALSE;
  1128. }
  1129. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_DISCON ) , &uc.MaxDisconnectionTime ) )
  1130. {
  1131. return FALSE;
  1132. }
  1133. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_IDLE ) , &uc.MaxIdleTime ) )
  1134. {
  1135. return FALSE;
  1136. }
  1137. uc.fResetBroken = SendMessage( GetDlgItem( hDlg , IDC_RADIO_RESET ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  1138. uc.fReconnectSame = SendMessage( GetDlgItem( hDlg , IDC_RADIO_PREVCLIENT ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  1139. if( !m_pUSht->SetUserConfig( uc , &dwStatus ) )
  1140. {
  1141. ErrorMessage2( hDlg , dwStatus );
  1142. return TRUE;
  1143. }
  1144. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  1145. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  1146. return TRUE;
  1147. }
  1148. //-------------------------------------------------------------------------------
  1149. // Making sure the user has entered valid info
  1150. //-------------------------------------------------------------------------------
  1151. BOOL CTimeOutDlg::IsValidSettings( HWND hDlg )
  1152. {
  1153. DWORD dwDummy;
  1154. if( IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  1155. {
  1156. return FALSE;
  1157. }
  1158. USERCONFIG uc;
  1159. uc = m_pUSht->GetCurrentUserConfig( &dwDummy );
  1160. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_CONNECT ) , &uc.MaxConnectionTime ) )
  1161. {
  1162. return FALSE;
  1163. }
  1164. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_DISCON ) , &uc.MaxDisconnectionTime ) )
  1165. {
  1166. return FALSE;
  1167. }
  1168. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_IDLE ) , &uc.MaxIdleTime ) )
  1169. {
  1170. return FALSE;
  1171. }
  1172. return TRUE;
  1173. }
  1174. #if 0
  1175. //-------------------------------------------------------------------------------
  1176. // Lets cut to the chase and find out if this is even worth parsing
  1177. //-------------------------------------------------------------------------------
  1178. BOOL CTimeOutDlg::DoesContainDigits( LPTSTR pszString )
  1179. {
  1180. while( *pszString )
  1181. {
  1182. if( iswdigit( *pszString ) )
  1183. {
  1184. return TRUE;
  1185. }
  1186. pszString++;
  1187. }
  1188. return FALSE;
  1189. }
  1190. //-------------------------------------------------------------------------------
  1191. LRESULT CTimeOutDlg::ParseDurationEntry( LPTSTR pszTime , PULONG pTime )
  1192. {
  1193. TCHAR tchNoTimeout[ 80 ];
  1194. LPTSTR pszTemp = pszTime;
  1195. UINT uDec = 0;
  1196. float fFrac = 0.0f;
  1197. float fT;
  1198. UINT uPos = 1;
  1199. LoadString( _Module.GetResourceInstance( ) , IDS_NOTIMEOUT , tchNoTimeout , sizeof( tchNoTimeout ) / sizeof( TCHAR ) );
  1200. if( lstrcmpi( pszTime , tchNoTimeout ) == 0 )
  1201. {
  1202. *pTime = 0;
  1203. return E_SUCCESS;
  1204. }
  1205. if( !DoesContainDigits( pszTime ) )
  1206. {
  1207. return E_PARSE_MISSING_DIGITS;
  1208. }
  1209. while( *pszTemp )
  1210. {
  1211. if( !iswdigit( *pszTemp ) )
  1212. {
  1213. break;
  1214. }
  1215. // check for overflow
  1216. if( uDec >= 1000000000 )
  1217. {
  1218. return E_PARSE_VALUEOVERFLOW ;
  1219. }
  1220. uDec *= 10;
  1221. uDec += ( *pszTemp - '0' );
  1222. pszTemp++;
  1223. }
  1224. TCHAR tchSDecimal[ 5 ];
  1225. GetLocaleInfo( LOCALE_USER_DEFAULT , LOCALE_SDECIMAL , tchSDecimal , sizeof( tchSDecimal ) / sizeof( TCHAR ) );
  1226. if( *pszTemp == *tchSDecimal )
  1227. {
  1228. pszTemp++;
  1229. while( *pszTemp )
  1230. {
  1231. if( !iswdigit( *pszTemp ) )
  1232. {
  1233. break;
  1234. }
  1235. // check for overflow
  1236. if( uDec >= 1000000000 )
  1237. {
  1238. return E_PARSE_VALUEOVERFLOW;
  1239. }
  1240. uPos *= 10;
  1241. fFrac += ( ( float )( *pszTemp - '0' ) ) / ( float )uPos; //+ 0.05f;
  1242. pszTemp++;
  1243. }
  1244. }
  1245. // remove white space
  1246. while( *pszTemp == L' ' )
  1247. {
  1248. pszTemp++;
  1249. }
  1250. if( *pszTemp != NULL )
  1251. {
  1252. if( IsToken( pszTemp , TOKEN_DAY ) )
  1253. {
  1254. *pTime = uDec * 24 * 60;
  1255. fT = ( fFrac * 1440.0f + 0.5f );
  1256. *pTime += ( ULONG )fT;
  1257. return E_SUCCESS;
  1258. }
  1259. else if( IsToken( pszTemp , TOKEN_HOUR ) )
  1260. {
  1261. *pTime = uDec * 60;
  1262. fT = ( fFrac * 60.0f + 0.5f );
  1263. *pTime += ( ULONG )fT;
  1264. return E_SUCCESS;
  1265. }
  1266. else if( IsToken( pszTemp , TOKEN_MINUTE ) )
  1267. {
  1268. // minutes are rounded up in the 1/10 place
  1269. fT = fFrac + 0.5f;
  1270. *pTime = uDec;
  1271. *pTime += ( ULONG )( fT );
  1272. return E_SUCCESS;
  1273. }
  1274. }
  1275. if( *pszTemp == NULL )
  1276. {
  1277. // if no text is defined considered the entry in hours
  1278. *pTime = uDec * 60;
  1279. fT = ( fFrac * 60.0f + 0.5f );
  1280. *pTime += ( ULONG )fT ;
  1281. return E_SUCCESS;
  1282. }
  1283. return E_PARSE_INVALID;
  1284. }
  1285. #endif
  1286. //-------------------------------------------------------------------------------
  1287. // Adds strings to table from resource
  1288. //-------------------------------------------------------------------------------
  1289. BOOL CTimeOutDlg::LoadAbbreviates( )
  1290. {
  1291. xxxLoadAbbreviate( &m_tokday[0] );
  1292. xxxLoadAbbreviate( &m_tokhour[0] );
  1293. xxxLoadAbbreviate( &m_tokmin[0] );
  1294. return TRUE;
  1295. }
  1296. //-------------------------------------------------------------------------------
  1297. // Take cares some repetitive work for us
  1298. //-------------------------------------------------------------------------------
  1299. BOOL CTimeOutDlg::xxxLoadAbbreviate( PTOKTABLE ptoktbl )
  1300. {
  1301. int idx;
  1302. int nSize;
  1303. TCHAR tchbuffer[ 80 ];
  1304. if( ptoktbl == NULL )
  1305. {
  1306. return FALSE;
  1307. }
  1308. for( idx = 0; ptoktbl[ idx ].dwresourceid != ( DWORD )-1 ; ++idx )
  1309. {
  1310. nSize = LoadString( _Module.GetResourceInstance( ) , ptoktbl[ idx ].dwresourceid , tchbuffer , sizeof( tchbuffer ) / sizeof( TCHAR ) );
  1311. if( nSize > 0 )
  1312. {
  1313. ptoktbl[ idx ].pszAbbrv = ( TCHAR *)new TCHAR[ nSize + 1 ];
  1314. if( ptoktbl[ idx ].pszAbbrv != NULL )
  1315. {
  1316. lstrcpy( ptoktbl[ idx ].pszAbbrv , tchbuffer );
  1317. }
  1318. }
  1319. }
  1320. return TRUE;
  1321. }
  1322. //-------------------------------------------------------------------------------
  1323. // Frees up allocated resources
  1324. //-------------------------------------------------------------------------------
  1325. BOOL CTimeOutDlg::xxxUnLoadAbbreviate( PTOKTABLE ptoktbl )
  1326. {
  1327. if( ptoktbl == NULL )
  1328. {
  1329. return FALSE;
  1330. }
  1331. for( int idx = 0; ptoktbl[ idx ].dwresourceid != ( DWORD )-1 ; ++idx )
  1332. {
  1333. if( ptoktbl[ idx ].pszAbbrv != NULL )
  1334. {
  1335. delete[] ptoktbl[ idx ].pszAbbrv;
  1336. }
  1337. }
  1338. return TRUE;
  1339. }
  1340. //-------------------------------------------------------------------------------
  1341. // tear-off token tables
  1342. //-------------------------------------------------------------------------------
  1343. BOOL CTimeOutDlg::IsToken( LPTSTR pszString , TOKEN tok )
  1344. {
  1345. TOKTABLE *ptoktable;
  1346. if( tok == TOKEN_DAY )
  1347. {
  1348. ptoktable = &m_tokday[0];
  1349. }
  1350. else if( tok == TOKEN_HOUR )
  1351. {
  1352. ptoktable = &m_tokhour[0];
  1353. }
  1354. else if( tok == TOKEN_MINUTE )
  1355. {
  1356. ptoktable = &m_tokmin[0];
  1357. }
  1358. else
  1359. {
  1360. return FALSE;
  1361. }
  1362. for( int idx = 0 ; ptoktable[ idx ].dwresourceid != -1 ; ++idx )
  1363. {
  1364. if( lstrcmpi( pszString , ptoktable[ idx ].pszAbbrv ) == 0 )
  1365. {
  1366. return TRUE;
  1367. }
  1368. }
  1369. return FALSE;
  1370. }
  1371. #if 0
  1372. //-------------------------------------------------------------------------------
  1373. // Converts the number minutes into a formated string
  1374. //-------------------------------------------------------------------------------
  1375. BOOL CTimeOutDlg::ConvertToDuration( ULONG ulTime , LPTSTR pszDuration )
  1376. {
  1377. INT_PTR dw[3];
  1378. TCHAR tchTimeUnit[ 40 ];
  1379. TCHAR tchTimeFormat[ 40 ];
  1380. TCHAR tchOutput[ 80 ];
  1381. ASSERT_( ulTime != 0 );
  1382. int iHour= ( int ) ( ( float )ulTime / 60.0f );
  1383. int iDays = iHour / 24;
  1384. dw[ 2 ] = ( INT_PTR )&tchTimeUnit[ 0 ];
  1385. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_DOT_DIGIT_TU , tchTimeFormat , sizeof( tchTimeFormat ) / sizeof( TCHAR ) );
  1386. if( iDays != 0 )
  1387. {
  1388. int iRemainingHours = iHour % 24;
  1389. float fx = ( float )iRemainingHours / 24.0f + 0.05f;
  1390. int iRemainingMinutes = ulTime % 60;
  1391. float mfx = ( float )iRemainingMinutes / 60.0f + 0.05f;
  1392. //if( ( iRemainingHours != 0 || iRemainingMinutes != 0 ) && iDays < 2 )
  1393. if( mfx > 0.05f || ( fx > 0.05f && fx < 0.10f && iDays < 2 ) )//
  1394. {
  1395. iRemainingMinutes = ( int ) ( mfx * 10 );
  1396. dw[ 0 ] = iHour;
  1397. dw[ 1 ] = iRemainingMinutes;
  1398. iDays = 0;
  1399. LoadString( _Module.GetResourceInstance( ) , IDS_HOURS , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1400. }
  1401. else
  1402. {
  1403. iRemainingHours = ( int )( fx * 10 );
  1404. LoadString( _Module.GetResourceInstance( ) , IDS_DAYS , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1405. dw[ 0 ] = iDays;
  1406. dw[ 1 ] = iRemainingHours;
  1407. }
  1408. if( dw[ 1 ] == 0 )
  1409. {
  1410. // formatted string requires two arguments
  1411. dw[ 1 ] = ( INT_PTR )&tchTimeUnit[ 0 ];
  1412. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , sizeof( tchTimeFormat ) / sizeof( TCHAR ) );
  1413. if( iDays == 1 )
  1414. {
  1415. LoadString( _Module.GetResourceInstance( ) , IDS_DAY , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1416. }
  1417. }
  1418. }
  1419. else if( iHour != 0 )
  1420. {
  1421. int iRemainingMinutes = ulTime % 60;
  1422. float fx = ( float )iRemainingMinutes / 60.0f ;//+ 0.05f;
  1423. if( fx > 0.0f && fx < 0.10f && iHour < 2 )//
  1424. {
  1425. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1426. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , sizeof( tchTimeFormat ) / sizeof( TCHAR ) );
  1427. dw[ 0 ] = ulTime ;
  1428. dw[ 1 ] = ( INT_PTR )&tchTimeUnit[ 0 ];
  1429. if( ulTime > 1 )
  1430. {
  1431. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1432. }
  1433. else
  1434. {
  1435. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTE , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1436. }
  1437. }//
  1438. else
  1439. {
  1440. fx += 0.05f;
  1441. iRemainingMinutes = ( int ) ( fx * 10 );
  1442. dw[ 0 ] = iHour;
  1443. dw[ 1 ] = iRemainingMinutes;
  1444. LoadString( _Module.GetResourceInstance( ) , IDS_HOURS , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1445. if( iRemainingMinutes == 0 )
  1446. {
  1447. dw[ 1 ] = ( INT_PTR )&tchTimeUnit[ 0 ];
  1448. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , sizeof( tchTimeFormat ) / sizeof( TCHAR ) );
  1449. if( iHour == 1 )
  1450. {
  1451. LoadString( _Module.GetResourceInstance( ) , IDS_HOUR , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1452. }
  1453. }
  1454. }
  1455. }
  1456. else
  1457. {
  1458. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1459. LoadString( _Module.GetResourceInstance( ) , IDS_DIGIT_TU , tchTimeFormat , sizeof( tchTimeFormat ) / sizeof( TCHAR ) );
  1460. dw[ 0 ] = ulTime ;
  1461. dw[ 1 ] = ( INT_PTR )&tchTimeUnit[ 0 ];
  1462. if( ulTime > 1 )
  1463. {
  1464. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1465. }
  1466. else
  1467. {
  1468. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTE , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  1469. }
  1470. }
  1471. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchTimeFormat , 0 , 0 , tchOutput , sizeof( tchOutput )/sizeof( TCHAR ) , ( va_list * )&dw );
  1472. lstrcpy( pszDuration , tchOutput );
  1473. return TRUE;
  1474. }
  1475. #endif
  1476. //-------------------------------------------------------------------------------
  1477. // Place entry in listbox and set as current selection
  1478. //-------------------------------------------------------------------------------
  1479. BOOL CTimeOutDlg::InsertSortedAndSetCurSel( HWND hCombo , DWORD dwMinutes )
  1480. {
  1481. ASSERT_( dwMinutes != ( DWORD )-1 );
  1482. TCHAR tchBuffer[ 80 ];
  1483. LRESULT iCount = SendMessage( hCombo , CB_GETCOUNT , 0 , 0 );
  1484. for( INT_PTR idx = 0 ; idx < iCount ; ++idx )
  1485. {
  1486. // Don't insert an item that's already in the list
  1487. if( dwMinutes == ( DWORD )SendMessage( hCombo , CB_GETITEMDATA , idx , 0 ) )
  1488. {
  1489. SendMessage( hCombo , CB_SETCURSEL , idx , 0 ) ;
  1490. SaveChangedSelection( hCombo );
  1491. return TRUE;
  1492. }
  1493. if( dwMinutes < ( DWORD )SendMessage( hCombo , CB_GETITEMDATA , idx , 0 ) )
  1494. {
  1495. break;
  1496. }
  1497. }
  1498. // hey if the value has exceeded the max timeout don't bother entering it in our list
  1499. if( dwMinutes > kMaxTimeoutMinute )
  1500. {
  1501. return FALSE;
  1502. }
  1503. if( ConvertToDuration ( dwMinutes , tchBuffer ) )
  1504. {
  1505. idx = SendMessage( hCombo , CB_INSERTSTRING , idx , ( LPARAM )&tchBuffer[ 0 ] );
  1506. if( idx != CB_ERR )
  1507. {
  1508. SendMessage( hCombo , CB_SETITEMDATA , idx , dwMinutes );
  1509. }
  1510. SendMessage( hCombo , CB_SETCURSEL , idx , 0 ) ;
  1511. }
  1512. // must call this here because CB_SETCURSEL does not send CBN_SELCHANGE
  1513. SaveChangedSelection( hCombo );
  1514. return TRUE;
  1515. }
  1516. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  1517. //-------------------------------------------------------------------------------
  1518. // CShadowDlg::ctor
  1519. //-------------------------------------------------------------------------------
  1520. CShadowDlg::CShadowDlg( CTSUserSheet *pUSht )
  1521. {
  1522. m_pUSht = pUSht;
  1523. m_wOldRad = ( WORD )-1;
  1524. }
  1525. //-------------------------------------------------------------------------------
  1526. // CShadowDlg Dialog Page
  1527. // -- static methods lacks this ptr
  1528. //-------------------------------------------------------------------------------
  1529. INT_PTR CALLBACK CShadowDlg::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  1530. {
  1531. CShadowDlg *pDlg;
  1532. if( msg == WM_INITDIALOG )
  1533. {
  1534. CShadowDlg *pDlg = ( CShadowDlg * )( ( PROPSHEETPAGE *)lp )->lParam ;
  1535. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  1536. if( !IsBadReadPtr( pDlg , sizeof( CShadowDlg ) ) )
  1537. {
  1538. pDlg->OnInitDialog( hwnd , wp , lp );
  1539. }
  1540. return 0;
  1541. }
  1542. else
  1543. {
  1544. pDlg = ( CShadowDlg * )GetWindowLongPtr( hwnd , DWLP_USER );
  1545. if( IsBadReadPtr( pDlg , sizeof( CShadowDlg ) ) )
  1546. {
  1547. return FALSE;
  1548. }
  1549. }
  1550. switch( msg )
  1551. {
  1552. case WM_NCDESTROY:
  1553. pDlg->OnDestroy( );
  1554. break;
  1555. case WM_COMMAND:
  1556. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  1557. break;
  1558. case WM_NOTIFY:
  1559. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  1560. case WM_HELP:
  1561. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  1562. break;
  1563. case WM_RBUTTONUP:
  1564. {
  1565. POINT pt;
  1566. pt.x = LOWORD( lp );
  1567. pt.y = HIWORD( lp );
  1568. HWND hChild = ChildWindowFromPoint( hwnd , pt );
  1569. ClientToScreen( hwnd , &pt );
  1570. pDlg->OnContextMenu( hChild , pt );
  1571. }
  1572. break;
  1573. case WM_CONTEXTMENU:
  1574. {
  1575. POINT pt;
  1576. pt.x = LOWORD( lp );
  1577. pt.y = HIWORD( lp );
  1578. pDlg->OnContextMenu( ( HWND )wp , pt );
  1579. }
  1580. }
  1581. return 0;
  1582. }
  1583. //-------------------------------------------------------------------------------
  1584. // InitDialog for CShadowDlg
  1585. //-------------------------------------------------------------------------------
  1586. BOOL CShadowDlg::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  1587. {
  1588. DWORD dwStatus;
  1589. if( IsBadReadPtr( m_pUSht ,sizeof( CTSUserSheet ) ) )
  1590. {
  1591. return FALSE;
  1592. }
  1593. USERCONFIG uc;
  1594. m_pUSht->AddRef( );
  1595. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  1596. // No userconfig loaded most likey access denied donot allow users to modify anything
  1597. if( dwStatus != ERROR_FILE_NOT_FOUND && dwStatus != ERROR_SUCCESS )
  1598. {
  1599. INT nId[ ] = {
  1600. IDC_CHECK_SHADOW,
  1601. IDC_RADIO_WATCH,
  1602. IDC_RADIO_CONTROL,
  1603. IDC_CHECK_NOTIFY,
  1604. -1
  1605. };
  1606. for( int idx = 0; nId[ idx ] != -1 ; ++idx )
  1607. {
  1608. EnableWindow( GetDlgItem( hwnd , nId[ idx ] ) , FALSE );
  1609. }
  1610. ErrorMessage1( hwnd , dwStatus );
  1611. return FALSE;
  1612. }
  1613. if( uc.Shadow == Shadow_Disable )
  1614. {
  1615. SendMessage( GetDlgItem( hwnd , IDC_CHECK_SHADOW ) , BM_SETCHECK , ( WPARAM )FALSE , 0 );
  1616. EnableWindow( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , FALSE );
  1617. EnableWindow( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , FALSE );
  1618. EnableWindow( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , FALSE );
  1619. EnableWindow( GetDlgItem( hwnd , IDC_STATIC_LEVELOFCTRL ) , FALSE );
  1620. }
  1621. else
  1622. {
  1623. //
  1624. // Controls are initially enabled, set current status
  1625. //
  1626. SendMessage( GetDlgItem( hwnd , IDC_CHECK_SHADOW ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  1627. switch( uc.Shadow )
  1628. {
  1629. case Shadow_EnableInputNotify:
  1630. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  1631. SendMessage( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , BM_CLICK , 0 , 0 );
  1632. break;
  1633. case Shadow_EnableInputNoNotify:
  1634. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )FALSE , 0 );
  1635. SendMessage( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , BM_CLICK , 0 , 0 );
  1636. break;
  1637. case Shadow_EnableNoInputNotify:
  1638. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  1639. SendMessage( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , BM_CLICK , 0 , 0 );
  1640. break;
  1641. case Shadow_EnableNoInputNoNotify:
  1642. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )FALSE , 0 );
  1643. SendMessage( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , BM_CLICK , 0 , 0 );
  1644. break;
  1645. }
  1646. m_wOldRad = ( WORD )( IsDlgButtonChecked( hwnd , IDC_RADIO_WATCH ) ? IDC_RADIO_WATCH : IDC_RADIO_CONTROL ) ;
  1647. }
  1648. m_bPersisted = TRUE;
  1649. return CDialogBase::OnInitDialog( hwnd , wp , lp );
  1650. }
  1651. //-------------------------------------------------------------------------------
  1652. // release the parent reference
  1653. //-------------------------------------------------------------------------------
  1654. BOOL CShadowDlg::OnDestroy( )
  1655. {
  1656. if( !IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  1657. {
  1658. ODS(TEXT("Releasing from CShadowDlg\n"));
  1659. m_pUSht->Release( );
  1660. }
  1661. return CDialogBase::OnDestroy( );
  1662. }
  1663. //-------------------------------------------------------------------------------
  1664. // GetPropertySheetPage - each dialog object should be responsible for its own data
  1665. //-------------------------------------------------------------------------------
  1666. BOOL CShadowDlg::GetPropertySheetPage( PROPSHEETPAGE& psp )
  1667. {
  1668. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  1669. psp.dwSize = sizeof( PROPSHEETPAGE );
  1670. psp.dwFlags = PSP_DEFAULT;
  1671. psp.hInstance = _Module.GetModuleInstance( );
  1672. psp.pszTemplate = MAKEINTRESOURCE( IDD_PAGE_SHADOW );
  1673. psp.lParam = ( LPARAM )this;
  1674. psp.pfnDlgProc = CShadowDlg::DlgProc;
  1675. return TRUE;
  1676. }
  1677. //-------------------------------------------------------------------------------
  1678. // Basic control notification handler
  1679. //-------------------------------------------------------------------------------
  1680. void CShadowDlg::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtl )
  1681. {
  1682. switch( wNotifyCode )
  1683. {
  1684. case BN_CLICKED:
  1685. if( wID == IDC_CHECK_SHADOW )
  1686. {
  1687. HWND hwnd = GetParent( hwndCtl );
  1688. BOOL bChecked = SendMessage( hwndCtl , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  1689. SendMessage( GetDlgItem( hwnd , IDC_CHECK_SHADOW ) , BM_SETCHECK , ( WPARAM )bChecked , 0 );
  1690. EnableWindow( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , bChecked );
  1691. EnableWindow( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , bChecked );
  1692. EnableWindow( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , bChecked );
  1693. EnableWindow( GetDlgItem( hwnd , IDC_STATIC_LEVELOFCTRL ) , bChecked );
  1694. //
  1695. // if neither radio buttons are selected force IDC_RADIO_CONTROL to be selected
  1696. //
  1697. if(
  1698. ( SendMessage( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , BM_GETSTATE , 0 , 0 ) == BST_UNCHECKED )
  1699. &&
  1700. ( SendMessage( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , BM_GETSTATE , 0 , 0 ) == BST_UNCHECKED )
  1701. )
  1702. {
  1703. SendMessage( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , BM_SETCHECK , ( WPARAM )BST_CHECKED , 0 );
  1704. m_wOldRad = IDC_RADIO_CONTROL;
  1705. }
  1706. m_bPersisted = FALSE;
  1707. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  1708. }
  1709. else if( wID == IDC_RADIO_WATCH || wID == IDC_RADIO_CONTROL )
  1710. {
  1711. if( wID != m_wOldRad )
  1712. {
  1713. m_wOldRad = wID;
  1714. m_bPersisted = FALSE;
  1715. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  1716. }
  1717. }
  1718. else if( wID == IDC_CHECK_NOTIFY )
  1719. {
  1720. m_bPersisted = FALSE;
  1721. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  1722. }
  1723. break;
  1724. case ALN_APPLY:
  1725. SendMessage( GetParent( hwndCtl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  1726. break;
  1727. }
  1728. }
  1729. //-------------------------------------------------------------------------------
  1730. // PersisitSettings
  1731. //-------------------------------------------------------------------------------
  1732. BOOL CShadowDlg::PersistSettings( HWND hDlg )
  1733. {
  1734. DWORD dwStatus;
  1735. if( IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  1736. {
  1737. return FALSE;
  1738. }
  1739. USERCONFIG uc;
  1740. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  1741. //
  1742. // Record all changes
  1743. //
  1744. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_SHADOW ) , BM_GETCHECK , 0 , 0 ) != BST_CHECKED )
  1745. {
  1746. uc.Shadow = Shadow_Disable;
  1747. }
  1748. else
  1749. {
  1750. BOOL bCheckNotify = (BOOL)SendMessage( GetDlgItem( hDlg , IDC_CHECK_NOTIFY ) , BM_GETCHECK , 0 , 0 );
  1751. BOOL bRadioControl = (BOOL)SendMessage( GetDlgItem( hDlg , IDC_RADIO_CONTROL ) , BM_GETCHECK , 0 , 0 );
  1752. if( bCheckNotify )
  1753. {
  1754. if( bRadioControl )
  1755. {
  1756. uc.Shadow = Shadow_EnableInputNotify;
  1757. }
  1758. else
  1759. {
  1760. uc.Shadow = Shadow_EnableNoInputNotify;
  1761. }
  1762. }
  1763. else
  1764. {
  1765. if( bRadioControl )
  1766. {
  1767. uc.Shadow = Shadow_EnableInputNoNotify;
  1768. }
  1769. else
  1770. {
  1771. uc.Shadow = Shadow_EnableNoInputNoNotify;
  1772. }
  1773. }
  1774. }
  1775. if( !m_pUSht->SetUserConfig( uc , &dwStatus ) )
  1776. {
  1777. ErrorMessage2( hDlg , dwStatus );
  1778. return TRUE;
  1779. }
  1780. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  1781. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  1782. return TRUE;
  1783. }
  1784. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  1785. CProfileDlg::CProfileDlg( CTSUserSheet *pUsh )
  1786. {
  1787. m_pUSht = pUsh;
  1788. m_wOldRadio = ( WORD )-1;
  1789. m_ncbxOld = -1;
  1790. }
  1791. //-------------------------------------------------------------------------------
  1792. // GetPropertySheetPage - each dialog object should be responsible for its own data
  1793. //-------------------------------------------------------------------------------
  1794. BOOL CProfileDlg::GetPropertySheetPage( PROPSHEETPAGE& psp )
  1795. {
  1796. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  1797. psp.dwSize = sizeof( PROPSHEETPAGE );
  1798. psp.dwFlags = PSP_DEFAULT;
  1799. psp.hInstance = _Module.GetModuleInstance( );
  1800. psp.pszTemplate = MAKEINTRESOURCE( IDD_PAGE_PROFILE );
  1801. psp.lParam = ( LPARAM )this;
  1802. psp.pfnDlgProc = CProfileDlg::DlgProc;
  1803. return TRUE;
  1804. }
  1805. //-------------------------------------------------------------------------------
  1806. // CProfileDlg Dialog Page
  1807. // -- static methods lacks this ptr
  1808. //-------------------------------------------------------------------------------
  1809. INT_PTR CALLBACK CProfileDlg::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  1810. {
  1811. CProfileDlg *pDlg;
  1812. if( msg == WM_INITDIALOG )
  1813. {
  1814. CProfileDlg *pDlg = ( CProfileDlg * )( ( PROPSHEETPAGE *)lp )->lParam ;
  1815. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  1816. if( !IsBadReadPtr( pDlg , sizeof( CProfileDlg ) ) )
  1817. {
  1818. pDlg->OnInitDialog( hwnd , wp , lp );
  1819. }
  1820. return 0;
  1821. }
  1822. else
  1823. {
  1824. pDlg = ( CProfileDlg * )GetWindowLongPtr( hwnd , DWLP_USER );
  1825. if( IsBadReadPtr( pDlg , sizeof( CProfileDlg ) ) )
  1826. {
  1827. return FALSE;
  1828. }
  1829. }
  1830. switch( msg )
  1831. {
  1832. case WM_NCDESTROY:
  1833. pDlg->OnDestroy( );
  1834. break;
  1835. case WM_COMMAND:
  1836. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  1837. break;
  1838. case WM_NOTIFY:
  1839. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  1840. case WM_HELP:
  1841. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  1842. break;
  1843. case WM_RBUTTONUP:
  1844. {
  1845. POINT pt;
  1846. pt.x = LOWORD( lp );
  1847. pt.y = HIWORD( lp );
  1848. HWND hChild = ChildWindowFromPoint( hwnd , pt );
  1849. ClientToScreen( hwnd , &pt );
  1850. pDlg->OnContextMenu( hChild , pt );
  1851. }
  1852. break;
  1853. case WM_CONTEXTMENU:
  1854. {
  1855. POINT pt;
  1856. pt.x = LOWORD( lp );
  1857. pt.y = HIWORD( lp );
  1858. pDlg->OnContextMenu( ( HWND )wp , pt );
  1859. }
  1860. }
  1861. return 0;
  1862. }
  1863. //-------------------------------------------------------------------------------
  1864. // InitDialog for CProfileDlg
  1865. //-------------------------------------------------------------------------------
  1866. BOOL CProfileDlg::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  1867. {
  1868. TCHAR tchDrv[3];
  1869. DWORD dwStatus;
  1870. if( IsBadReadPtr( m_pUSht ,sizeof( CTSUserSheet ) ) )
  1871. {
  1872. return FALSE;
  1873. }
  1874. USERCONFIG uc;
  1875. m_pUSht->AddRef( );
  1876. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  1877. if( dwStatus != ERROR_FILE_NOT_FOUND && dwStatus != ERROR_SUCCESS )
  1878. {
  1879. INT nId[ ] = {
  1880. IDC_CHECK_ALLOWLOGON,
  1881. IDC_COMBO_DRIVES,
  1882. IDC_EDIT_REMOTEPATH,
  1883. IDC_RADIO_REMOTE,
  1884. IDC_EDIT_LOCALPATH,
  1885. IDC_RADIO_LOCAL,
  1886. IDC_EDIT_USRPROFILE,
  1887. -1
  1888. };
  1889. for( int idx = 0; nId[ idx ] != -1 ; ++idx )
  1890. {
  1891. EnableWindow( GetDlgItem( hwnd , nId[ idx ] ) , FALSE );
  1892. }
  1893. ErrorMessage1( hwnd , dwStatus );
  1894. return FALSE;
  1895. }
  1896. SendMessage( GetDlgItem( hwnd , IDC_CHECK_ALLOWLOGON ) , BM_SETCHECK , ( WPARAM )( !uc.fLogonDisabled ) , 0 );
  1897. SendMessage( GetDlgItem( hwnd , IDC_EDIT_LOCALPATH ) , EM_SETLIMITTEXT , ( WPARAM )DIRECTORY_LENGTH , 0 );
  1898. SendMessage( GetDlgItem( hwnd , IDC_EDIT_REMOTEPATH ) , EM_SETLIMITTEXT , ( WPARAM )DIRECTORY_LENGTH , 0 );
  1899. SendMessage( GetDlgItem( hwnd , IDC_EDIT_USRPROFILE ) , EM_SETLIMITTEXT , ( WPARAM )DIRECTORY_LENGTH , 0 );
  1900. for( TCHAR DrvLetter = 'C'; DrvLetter <= 'Z'; DrvLetter++ )
  1901. {
  1902. tchDrv[0] = DrvLetter;
  1903. tchDrv[1] = ':';
  1904. tchDrv[2] = 0;
  1905. SendMessage( GetDlgItem( hwnd , IDC_COMBO_DRIVES ) , CB_ADDSTRING , 0 , ( LPARAM )&tchDrv[ 0 ] );
  1906. }
  1907. if( PathIsUNC( uc.WFHomeDir ) )
  1908. {
  1909. ODS( L"TSUSEREX: Path is UNC\n" );
  1910. CharUpper( &uc.WFHomeDirDrive[0] );
  1911. if( uc.WFHomeDirDrive[ 0 ] >= 'C' && uc.WFHomeDirDrive[ 0 ] <= 'Z' )
  1912. {
  1913. m_ncbxOld = (int)SendMessage( GetDlgItem( hwnd , IDC_COMBO_DRIVES ) , CB_SETCURSEL , ( WPARAM )( uc.WFHomeDirDrive[ 0 ] - 'C' ) , 0 );
  1914. }
  1915. else
  1916. {
  1917. // default it to Z drive
  1918. m_ncbxOld = (int)SendMessage( GetDlgItem( hwnd , IDC_COMBO_DRIVES ) , CB_SETCURSEL , ( WPARAM )( 'Z' - 'C' ) , 0 );
  1919. }
  1920. SetWindowText( GetDlgItem( hwnd , IDC_EDIT_REMOTEPATH ) , uc.WFHomeDir );
  1921. //SendMessage( GetDlgItem( hwnd , IDC_RADIO_REMOTE ) , BM_CLICK , 0 , 0 );
  1922. SendMessage( GetDlgItem( hwnd , IDC_RADIO_REMOTE ) , BM_SETCHECK , ( WPARAM )BST_CHECKED , 0 );
  1923. SendMessage( GetDlgItem( hwnd , IDC_RADIO_LOCAL ) , BM_SETCHECK , ( WPARAM )BST_UNCHECKED , 0 );
  1924. m_wOldRadio = IDC_RADIO_REMOTE;
  1925. }
  1926. else
  1927. {
  1928. ODS( L"TSUSEREX: Path is Local\n" );
  1929. SendMessage( GetDlgItem( hwnd , IDC_EDIT_LOCALPATH ) , WM_SETTEXT , 0 , ( LPARAM )&uc.WFHomeDir[ 0 ] );
  1930. // SendMessage( GetDlgItem( hwnd , IDC_RADIO_LOCAL ) , BM_CLICK , 0 , 0 );
  1931. SendMessage( GetDlgItem( hwnd , IDC_RADIO_LOCAL ) , BM_SETCHECK , ( WPARAM )BST_CHECKED , 0 );
  1932. SendMessage( GetDlgItem( hwnd , IDC_RADIO_REMOTE ) , BM_SETCHECK , ( WPARAM )BST_UNCHECKED , 0 );
  1933. m_wOldRadio = IDC_RADIO_LOCAL;
  1934. }
  1935. EnableRemoteHomeDirectory( hwnd , ( BOOL )( m_wOldRadio == IDC_RADIO_REMOTE ) );
  1936. SendMessage( GetDlgItem( hwnd , IDC_EDIT_USRPROFILE ) , WM_SETTEXT , 0 , ( LPARAM )&uc.WFProfilePath[ 0 ] );
  1937. m_bPersisted = TRUE;
  1938. m_bTSHomeFolderChanged = FALSE;
  1939. return CDialogBase::OnInitDialog( hwnd , wp , lp );
  1940. }
  1941. //-------------------------------------------------------------------------------
  1942. // EnableRemoteHomeDirectory -- basically enables or disables dlg controls
  1943. //-------------------------------------------------------------------------------
  1944. BOOL CProfileDlg::EnableRemoteHomeDirectory( HWND hwnd , BOOL bHDMR )
  1945. {
  1946. //
  1947. // Local home directory
  1948. //
  1949. EnableWindow( GetDlgItem( hwnd , IDC_EDIT_LOCALPATH ) , !bHDMR );
  1950. //
  1951. // Network'd home directory
  1952. //
  1953. EnableWindow( GetDlgItem( hwnd , IDC_COMBO_DRIVES ) , bHDMR );
  1954. EnableWindow( GetDlgItem( hwnd , IDC_EDIT_REMOTEPATH ) , bHDMR );
  1955. return TRUE;
  1956. }
  1957. //-------------------------------------------------------------------------------
  1958. // release the parent reference
  1959. //-------------------------------------------------------------------------------
  1960. BOOL CProfileDlg::OnDestroy( )
  1961. {
  1962. if( !IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  1963. {
  1964. ODS(TEXT("Releasing from CProfileDlg\n"));
  1965. m_pUSht->Release( );
  1966. }
  1967. return CDialogBase::OnDestroy( );
  1968. }
  1969. //-------------------------------------------------------------------------------
  1970. // Basic control notification handler
  1971. //-------------------------------------------------------------------------------
  1972. void CProfileDlg::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtl )
  1973. {
  1974. switch( wNotifyCode )
  1975. {
  1976. case EN_CHANGE:
  1977. m_bPersisted = FALSE;
  1978. if( wID == IDC_EDIT_REMOTEPATH || wID == IDC_EDIT_LOCALPATH )
  1979. {
  1980. ODS( L"EN_CHANGE m_bTSHomeFolderChanged = TRUE;\n" );
  1981. m_bTSHomeFolderChanged = TRUE;
  1982. }
  1983. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  1984. break;
  1985. //case CBN_DROPDOWN:
  1986. case CBN_SELCHANGE:
  1987. {
  1988. int nCurSel = (int)SendMessage( hwndCtl , CB_GETCURSEL , 0 , 0 );
  1989. if( m_ncbxOld != nCurSel )
  1990. {
  1991. m_ncbxOld = nCurSel;
  1992. ODS( L"CBN_SELCHANGE m_bTSHomeFolderChanged = TRUE;\n" );
  1993. m_bTSHomeFolderChanged = TRUE;
  1994. m_bPersisted = FALSE;
  1995. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  1996. }
  1997. }
  1998. break;
  1999. case BN_CLICKED:
  2000. if( wID == IDC_RADIO_REMOTE || wID == IDC_RADIO_LOCAL )
  2001. {
  2002. if( wID != m_wOldRadio )
  2003. {
  2004. EnableRemoteHomeDirectory( GetParent( hwndCtl ) , ( BOOL )( wID == IDC_RADIO_REMOTE ) );
  2005. m_wOldRadio = wID;
  2006. m_bPersisted = FALSE;
  2007. ODS( L"Setting m_bTSHomeFolderChanged to true\n" );
  2008. m_bTSHomeFolderChanged = TRUE;
  2009. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  2010. }
  2011. if( wID == IDC_RADIO_LOCAL )
  2012. {
  2013. SetFocus( GetDlgItem( GetParent( hwndCtl ) , IDC_EDIT_LOCALPATH ) );
  2014. SendMessage( GetDlgItem( GetParent( hwndCtl ) , IDC_EDIT_LOCALPATH ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  2015. }
  2016. else if( wID == IDC_RADIO_REMOTE )
  2017. {
  2018. if( SendMessage( GetDlgItem( GetParent( hwndCtl ) , IDC_COMBO_DRIVES ) ,
  2019. CB_GETCURSEL,
  2020. 0,
  2021. 0 ) == CB_ERR )
  2022. {
  2023. SendMessage( GetDlgItem( GetParent( hwndCtl ) , IDC_COMBO_DRIVES ) ,
  2024. CB_SETCURSEL,
  2025. ( WPARAM )( 'Z' - 'C' ),
  2026. 0 );
  2027. }
  2028. SetFocus( GetDlgItem( GetParent( hwndCtl ) , IDC_COMBO_DRIVES ) );
  2029. }
  2030. }
  2031. else if( wID == IDC_CHECK_ALLOWLOGON )
  2032. {
  2033. m_bPersisted = FALSE;
  2034. SendMessage( GetParent( GetParent( hwndCtl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtl ) , 0 );
  2035. }
  2036. break;
  2037. case ALN_APPLY:
  2038. SendMessage( GetParent( hwndCtl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  2039. break;
  2040. }
  2041. }
  2042. //-------------------------------------------------------------------------------
  2043. // PersistSettings -- remember TRUE is bad FALSE is good
  2044. //-------------------------------------------------------------------------------
  2045. BOOL CProfileDlg::PersistSettings( HWND hDlg )
  2046. {
  2047. BOOL bRet = TRUE;;
  2048. DWORD dwStatus;
  2049. if( IsBadReadPtr( m_pUSht , sizeof( CTSUserSheet ) ) )
  2050. {
  2051. return TRUE;
  2052. }
  2053. USERCONFIG uc;
  2054. uc = m_pUSht->GetCurrentUserConfig( &dwStatus );
  2055. //
  2056. // expensive but necessary id34393
  2057. //
  2058. if( !m_pUSht->SetUserConfig( uc , &dwStatus ) )
  2059. {
  2060. ErrorMessage2( hDlg , dwStatus );
  2061. m_bTSHomeFolderChanged = FALSE;
  2062. return TRUE;
  2063. }
  2064. //
  2065. // Determine whether to enable user to logon to a terminal server
  2066. //
  2067. uc.fLogonDisabled = SendMessage( GetDlgItem( hDlg , IDC_CHECK_ALLOWLOGON ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? FALSE : TRUE;
  2068. //
  2069. // Profile path is under the admin discretion
  2070. //
  2071. SetWTSProfilePath( hDlg , uc );
  2072. //
  2073. // Parse and flag corrupt data
  2074. //
  2075. if( m_bTSHomeFolderChanged )
  2076. {
  2077. ODS( L"Persisting home folder settings\n" );
  2078. if( SendMessage( GetDlgItem( hDlg , IDC_RADIO_LOCAL ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED )
  2079. {
  2080. bRet = SetWTSLocalPath( hDlg , uc );
  2081. // Set WFHomeDirDrive to NULL because Home folder is a Local folder
  2082. wcscpy(uc.WFHomeDirDrive, L"\0");
  2083. }
  2084. else
  2085. {
  2086. bRet = SetWTSRemotePath( hDlg , uc );
  2087. }
  2088. m_bTSHomeFolderChanged = FALSE;
  2089. }
  2090. if( bRet )
  2091. {
  2092. if( !m_pUSht->SetUserConfig( uc , &dwStatus ) )
  2093. {
  2094. ErrorMessage2( hDlg , dwStatus );
  2095. return TRUE;
  2096. }
  2097. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  2098. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  2099. }
  2100. return bRet;
  2101. }
  2102. //-------------------------------------------------------------------------------
  2103. // IsValidSettings doesnot persist the information
  2104. //-------------------------------------------------------------------------------
  2105. BOOL CProfileDlg::IsValidSettings( HWND hDlg )
  2106. {
  2107. BOOL bRet = TRUE;
  2108. //
  2109. // Parse and flag corrupt data
  2110. //
  2111. if( m_bTSHomeFolderChanged )
  2112. {
  2113. ODS( L"Checking validity of home folders\n" );
  2114. if( SendMessage( GetDlgItem( hDlg , IDC_RADIO_LOCAL ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED )
  2115. {
  2116. bRet = IsLocalPathValid( hDlg );
  2117. }
  2118. else
  2119. {
  2120. bRet = IsRemotePathValid( hDlg );
  2121. }
  2122. }
  2123. return bRet;
  2124. }
  2125. //-------------------------------------------------------------------------------
  2126. // SetWTSProfilePath
  2127. //-------------------------------------------------------------------------------
  2128. BOOL CProfileDlg::SetWTSProfilePath( HWND hDlg , USERCONFIG& uc )
  2129. {
  2130. //
  2131. // It looks like we don't care what the user enters
  2132. // I'm borrowing the behavior from the current usrmgr profile page
  2133. //
  2134. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_USRPROFILE ) , uc.WFProfilePath , sizeof( uc.WFProfilePath ) / sizeof( TCHAR ) );
  2135. ExpandUserName( uc.WFProfilePath );
  2136. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_USRPROFILE ) , uc.WFProfilePath );
  2137. return TRUE;
  2138. }
  2139. //-------------------------------------------------------------------------------
  2140. // IsLocalPathValid
  2141. //-------------------------------------------------------------------------------
  2142. BOOL CProfileDlg::IsLocalPathValid( HWND hDlg )
  2143. {
  2144. TCHAR tchBuf[ MAX_PATH ] = { 0 };
  2145. TCHAR tchErr[ MAX_PATH ] = { 0 };
  2146. TCHAR tchErrTitle[ 80 ]= { 0 };
  2147. TCHAR tchPath[ MAX_PATH ]= { 0 };
  2148. INT_PTR dw = ( INT_PTR )&tchPath[0];
  2149. if( SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOCALPATH ) , WM_GETTEXT , sizeof( tchPath ) / sizeof( TCHAR ) , ( LPARAM )&tchPath[ 0 ] ) > 0 )
  2150. {
  2151. ExpandUserName( tchPath );
  2152. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOCALPATH ) , tchPath );
  2153. if( !IsPathValid( tchPath , FALSE ) )
  2154. {
  2155. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_PATH , tchErr , sizeof( tchErr ) / sizeof( TCHAR ) );
  2156. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErrTitle , sizeof( tchErrTitle ) / sizeof( TCHAR ) );
  2157. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchErr , 0 , 0 , tchBuf , sizeof( tchBuf ) / sizeof( TCHAR ) , ( va_list * )&dw );
  2158. MessageBox( hDlg , tchBuf , tchErrTitle , MB_OK | MB_ICONERROR );
  2159. return FALSE;
  2160. }
  2161. // test if path exists or not
  2162. if( GetFileAttributes( tchPath ) != FILE_ATTRIBUTE_DIRECTORY )
  2163. {
  2164. DWORD dwErr;
  2165. if( !m_pUSht->GetDSAType( ) && !createdir( tchPath , FALSE , &dwErr ) )
  2166. {
  2167. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_PATH , tchErr , sizeof( tchErr ) / sizeof( TCHAR ) );
  2168. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchErr , 0 , 0 , tchBuf , sizeof( tchBuf ) / sizeof( TCHAR ) , ( va_list * )&dw );
  2169. LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchErrTitle , sizeof( tchErrTitle ) / sizeof( TCHAR ) );
  2170. MessageBox( hDlg , tchBuf , tchErrTitle , MB_OK | MB_ICONWARNING );
  2171. }
  2172. }
  2173. }
  2174. return TRUE;
  2175. }
  2176. //-------------------------------------------------------------------------------
  2177. // SetWTSLocalPath - copies the contents over - IsPathValid would have return
  2178. // true inorder for us to get here!
  2179. //-------------------------------------------------------------------------------
  2180. BOOL CProfileDlg::SetWTSLocalPath( HWND hDlg , USERCONFIG& uc )
  2181. {
  2182. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOCALPATH ) , WM_GETTEXT , sizeof( uc.WFHomeDir ) / sizeof( TCHAR ) , ( LPARAM )&uc.WFHomeDir[ 0 ] );
  2183. // uc.fHomeDirectoryMapRoot = FALSE;
  2184. return TRUE;
  2185. }
  2186. //-------------------------------------------------------------------------------
  2187. // IsRemotePathValid - verifies UNC is correct
  2188. //-------------------------------------------------------------------------------
  2189. BOOL CProfileDlg::IsRemotePathValid( HWND hDlg )
  2190. {
  2191. TCHAR tchErr1[ 768 ] = { 0 };
  2192. TCHAR tchError[ 768 ] = { 0 };
  2193. TCHAR tchHomeDir[ MAX_PATH ] = { 0 };
  2194. if( GetWindowText( GetDlgItem( hDlg , IDC_EDIT_REMOTEPATH ) , tchHomeDir , sizeof( tchHomeDir ) / sizeof( TCHAR ) ) > 0 )
  2195. {
  2196. ExpandUserName( tchHomeDir );
  2197. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_REMOTEPATH ) , tchHomeDir );
  2198. if( !IsPathValid( tchHomeDir , TRUE ) )
  2199. {
  2200. if( LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_REMOTEPATH , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) ) > 0 )
  2201. {
  2202. INT_PTR dw = ( INT_PTR )&tchHomeDir[ 0 ];
  2203. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, tchErr1 , 0 , 0 , tchError , sizeof( tchError ) / sizeof( TCHAR ) , ( va_list * )&dw );
  2204. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) );
  2205. MessageBox( hDlg , tchError , tchErr1 , MB_OK | MB_ICONERROR );
  2206. }
  2207. return FALSE;
  2208. }
  2209. /*
  2210. DWORD dwErr = 0;
  2211. if( !createdir( tchHomeDir , TRUE , &dwErr ) )
  2212. {
  2213. if( dwErr != 0 )
  2214. {
  2215. UINT rId;
  2216. switch( dwErr )
  2217. {
  2218. case ERROR_ALREADY_EXISTS:
  2219. case ERROR_LOGON_FAILURE:
  2220. case ERROR_PATH_NOT_FOUND:
  2221. {
  2222. rId = ( ERROR_ALREADY_EXISTS == dwErr) ?
  2223. IDS_HOME_DIR_EXISTS :
  2224. ( ERROR_PATH_NOT_FOUND == dwErr ) ?
  2225. IDS_HOME_DIR_CREATE_FAILED :
  2226. IDS_HOME_DIR_CREATE_NO_ACCESS;
  2227. LoadString( _Module.GetResourceInstance( ) , rId , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) );
  2228. wsprintf( tchError , tchErr1 , tchHomeDir );
  2229. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) );
  2230. MessageBox( hDlg , tchError , tchErr1 , MB_OK | MB_ICONERROR );
  2231. }
  2232. break;
  2233. default:
  2234. xxErrorMessage( hDlg , dwErr , IDS_ERR_CREATE_DIR );
  2235. }
  2236. }
  2237. }
  2238. */
  2239. }
  2240. else
  2241. {
  2242. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_NETPATH , tchError , sizeof( tchError ) / sizeof( TCHAR ) );
  2243. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) );
  2244. MessageBox( hDlg , tchError , tchErr1 , MB_OK | MB_ICONERROR );
  2245. return FALSE;
  2246. }
  2247. return TRUE;
  2248. }
  2249. //-------------------------------------------------------------------------------
  2250. // SetWTSRemotePath - IsRemotePathValid must return TRUE in order to get here
  2251. //-------------------------------------------------------------------------------
  2252. BOOL CProfileDlg::SetWTSRemotePath( HWND hDlg , USERCONFIG& uc )
  2253. {
  2254. TCHAR tchErr1[ 768 ] = { 0 };
  2255. TCHAR tchError[ 768 ] = { 0 };
  2256. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_REMOTEPATH ) , uc.WFHomeDir , sizeof( uc.WFHomeDir ) / sizeof( TCHAR ) );
  2257. if( GetWindowText( GetDlgItem( hDlg , IDC_COMBO_DRIVES ) , uc.WFHomeDirDrive , sizeof( uc.WFHomeDirDrive ) / sizeof( TCHAR ) ) == 0 )
  2258. {
  2259. SendMessage( GetDlgItem( hDlg , IDC_COMBO_DRIVES ) , CB_GETLBTEXT , 0 , ( LPARAM )&uc.WFHomeDirDrive );
  2260. }
  2261. DWORD dwErr = 0;
  2262. if( !createdir( uc.WFHomeDir , TRUE , &dwErr ) )
  2263. {
  2264. if( dwErr != 0 )
  2265. {
  2266. UINT rId;
  2267. switch( dwErr )
  2268. {
  2269. case ERROR_ALREADY_EXISTS:
  2270. case ERROR_LOGON_FAILURE:
  2271. case ERROR_PATH_NOT_FOUND:
  2272. {
  2273. rId = ( ERROR_ALREADY_EXISTS == dwErr) ?
  2274. IDS_HOME_DIR_EXISTS :
  2275. ( ERROR_PATH_NOT_FOUND == dwErr ) ?
  2276. IDS_HOME_DIR_CREATE_FAILED :
  2277. IDS_HOME_DIR_CREATE_NO_ACCESS;
  2278. LoadString( _Module.GetResourceInstance( ) , rId , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) );
  2279. wsprintf( tchError , tchErr1 , uc.WFHomeDir );
  2280. LoadString( _Module.GetResourceInstance( ) , IDS_ERROR_TITLE , tchErr1 , sizeof( tchErr1 ) / sizeof( TCHAR ) );
  2281. MessageBox( hDlg , tchError , tchErr1 , MB_OK | MB_ICONERROR );
  2282. }
  2283. break;
  2284. default:
  2285. xxErrorMessage( hDlg , dwErr , IDS_ERR_CREATE_DIR );
  2286. }
  2287. }
  2288. }
  2289. // uc.fHomeDirectoryMapRoot = TRUE;
  2290. return TRUE;
  2291. }
  2292. //-------------------------------------------------------------------------------
  2293. // This is cool - I_NetPathType really does a lot of work for us
  2294. //-------------------------------------------------------------------------------
  2295. BOOL CProfileDlg::IsPathValid( LPTSTR pszPath , BOOL bUnc )
  2296. {
  2297. DWORD dwRetflags;
  2298. if( I_NetPathType( NULL, pszPath, &dwRetflags, 0) != NERR_Success )
  2299. {
  2300. return FALSE;
  2301. }
  2302. if( !bUnc )
  2303. {
  2304. return ( dwRetflags & ITYPE_PATH_ABSD ? TRUE : FALSE );
  2305. }
  2306. return ( dwRetflags & ITYPE_UNC ? TRUE : FALSE );
  2307. }
  2308. //-------------------------------------------------------------------------------
  2309. // If the string contains %username% expand it to the current user.
  2310. //-------------------------------------------------------------------------------
  2311. void CProfileDlg::ExpandUserName( LPTSTR szPath )
  2312. {
  2313. TCHAR tchSubPath[ MAX_PATH];
  2314. TCHAR szUserName[ 40 ];
  2315. if( szPath == NULL )
  2316. {
  2317. return;
  2318. }
  2319. // remove any leading or trailing spaces
  2320. TCHAR tchTrim[] = TEXT( " " );
  2321. StrTrim( szPath , tchTrim );
  2322. int nSz = LoadString( _Module.GetResourceInstance( ) , IDS_USERNAME , szUserName , sizeof( szUserName ) / sizeof( TCHAR ) );
  2323. //CharLowerBuff( szPath , lstrlen( szPath ) );
  2324. // Find %username%
  2325. LPTSTR pFound = StrStrI( szPath , szUserName ); //_tcsstr( szPath , szUserName );
  2326. if( pFound != NULL )
  2327. {
  2328. INT_PTR nPos = ( INT_PTR )( pFound - szPath );
  2329. lstrcpy( tchSubPath , ( szPath + nPos + nSz ) );
  2330. szPath[ nPos ] = 0;
  2331. lstrcat( szPath , m_pUSht->GetUserName() );
  2332. lstrcat( szPath , tchSubPath );
  2333. }
  2334. }
  2335. //-------------------------------------------------------------------------------
  2336. // Removing decimal entries
  2337. //-------------------------------------------------------------------------------
  2338. LRESULT CTimeOutDlg::ParseDurationEntry( LPTSTR pszTime , PULONG pTime )
  2339. {
  2340. TCHAR tchNoTimeout[ 80 ];
  2341. LPTSTR pszTemp = pszTime;
  2342. UINT uDec = 0;
  2343. BOOL bSetDay = FALSE;
  2344. BOOL bSetHour = FALSE;
  2345. BOOL bSetMin = FALSE;
  2346. BOOL bEOL = FALSE;
  2347. BOOL bHasDigit= FALSE;
  2348. *pTime = 0;
  2349. LoadString( _Module.GetResourceInstance( ) , IDS_NOTIMEOUT , tchNoTimeout , sizeof( tchNoTimeout ) / sizeof( TCHAR ) );
  2350. if( lstrcmpi( pszTime , tchNoTimeout ) == 0 )
  2351. {
  2352. // *pTime = 0;
  2353. return E_SUCCESS;
  2354. }
  2355. while( !bEOL )
  2356. {
  2357. // remove leading white spaces
  2358. while( *pszTemp == L' ' )
  2359. {
  2360. pszTemp++;
  2361. }
  2362. while( *pszTemp )
  2363. {
  2364. if( !iswdigit( *pszTemp ) )
  2365. {
  2366. if( !bHasDigit )
  2367. {
  2368. return E_PARSE_MISSING_DIGITS;
  2369. }
  2370. break;
  2371. }
  2372. // check for overflow
  2373. if( uDec >= 1000000000 )
  2374. {
  2375. return E_PARSE_VALUEOVERFLOW ;
  2376. }
  2377. uDec *= 10;
  2378. uDec += ( *pszTemp - '0' );
  2379. if( !bHasDigit )
  2380. {
  2381. bHasDigit = TRUE;
  2382. }
  2383. pszTemp++;
  2384. }
  2385. // remove intermediate white spaces
  2386. while( *pszTemp == L' ' )
  2387. {
  2388. pszTemp++;
  2389. }
  2390. if( *pszTemp != NULL )
  2391. {
  2392. // Get next token
  2393. TCHAR tchToken[ 80 ];
  2394. pszTemp = GetNextToken( pszTemp , tchToken );
  2395. if( IsToken( tchToken , TOKEN_DAY ) )
  2396. {
  2397. if( !bSetDay )
  2398. {
  2399. *pTime += uDec * 1440;
  2400. bSetDay = TRUE;
  2401. }
  2402. }
  2403. else if( IsToken( tchToken , TOKEN_HOUR ) )
  2404. {
  2405. if( !bSetHour )
  2406. {
  2407. *pTime += uDec * 60;
  2408. bSetHour = TRUE;
  2409. }
  2410. }
  2411. else if( IsToken( tchToken , TOKEN_MINUTE ) )
  2412. {
  2413. if( !bSetMin )
  2414. {
  2415. *pTime += uDec;
  2416. bSetMin = TRUE;
  2417. }
  2418. }
  2419. else
  2420. {
  2421. return E_PARSE_INVALID;
  2422. }
  2423. }
  2424. else
  2425. {
  2426. if( !bSetHour )
  2427. {
  2428. *pTime += uDec * 60;
  2429. }
  2430. bEOL = TRUE;
  2431. }
  2432. uDec = 0;
  2433. bHasDigit = FALSE;
  2434. }
  2435. return E_SUCCESS;
  2436. }
  2437. //-------------------------------------------------------------------------------
  2438. // replacing older api
  2439. //-------------------------------------------------------------------------------
  2440. BOOL CTimeOutDlg::ConvertToDuration( ULONG ulTime , LPTSTR pszDuration )
  2441. {
  2442. // TCHAR dw[] = L"dhm";
  2443. TCHAR tchTimeUnit[ 40 ];
  2444. TCHAR tchTimeFormat[ 40 ];
  2445. TCHAR tchOutput[ 80 ];
  2446. ASSERT_( ulTime != 0 );
  2447. int iHour = ( ulTime / 60 );
  2448. int iDays = iHour / 24;
  2449. int iMinute = ulTime % 60;
  2450. // Resolve format
  2451. tchOutput[0] = 0;
  2452. if( iDays > 0 )
  2453. {
  2454. if( iDays == 1 )
  2455. {
  2456. LoadString( _Module.GetResourceInstance( ) , IDS_DAY , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  2457. }
  2458. else
  2459. {
  2460. LoadString( _Module.GetResourceInstance( ) , IDS_DAYS , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  2461. }
  2462. iHour = iHour % 24;
  2463. wsprintf( tchTimeFormat , L"%d %s", iDays , tchTimeUnit );
  2464. lstrcat( tchOutput , tchTimeFormat );
  2465. lstrcat( tchOutput , L" " );
  2466. }
  2467. if( iHour > 0 )
  2468. {
  2469. if( iHour == 1 )
  2470. {
  2471. LoadString( _Module.GetResourceInstance( ) , IDS_HOUR , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  2472. }
  2473. else
  2474. {
  2475. LoadString( _Module.GetResourceInstance( ) , IDS_HOURS , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  2476. }
  2477. wsprintf( tchTimeFormat , L"%d %s", iHour , tchTimeUnit );
  2478. lstrcat( tchOutput , tchTimeFormat );
  2479. lstrcat( tchOutput , L" " );
  2480. }
  2481. if( iMinute > 0 )
  2482. {
  2483. if( iMinute == 1 )
  2484. {
  2485. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTE , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  2486. }
  2487. else
  2488. {
  2489. LoadString( _Module.GetResourceInstance( ) , IDS_MINUTES , tchTimeUnit , sizeof( tchTimeUnit ) / sizeof( TCHAR ) );
  2490. }
  2491. wsprintf( tchTimeFormat , L"%d %s", iMinute , tchTimeUnit );
  2492. lstrcat( tchOutput , tchTimeFormat );
  2493. lstrcat( tchOutput , L" " );
  2494. }
  2495. lstrcpy( pszDuration , tchOutput );
  2496. return TRUE;
  2497. }
  2498. //-------------------------------------------------------------------------------
  2499. BOOL CTimeOutDlg::DoesContainDigits( LPTSTR pszString )
  2500. {
  2501. while( *pszString )
  2502. {
  2503. if( *pszString != L' ')
  2504. {
  2505. if( iswdigit( *pszString ) )
  2506. {
  2507. return TRUE;
  2508. }
  2509. else
  2510. {
  2511. return FALSE;
  2512. }
  2513. pszString++;
  2514. }
  2515. }
  2516. return FALSE;
  2517. }
  2518. //-------------------------------------------------------------------------------
  2519. TCHAR * GetNextToken( TCHAR *pszString , TCHAR *tchToken )
  2520. {
  2521. while( *pszString )
  2522. {
  2523. if( IsCharAlpha( *pszString ) )
  2524. {
  2525. *tchToken = *pszString;
  2526. }
  2527. else
  2528. {
  2529. break;
  2530. }
  2531. tchToken++;
  2532. pszString++;
  2533. }
  2534. *tchToken = '\0';
  2535. return pszString;
  2536. }
  2537. //-------------------------------------------------------------------------------
  2538. void ErrorMessage1( HWND hParent , DWORD dwStatus )
  2539. {
  2540. xxErrorMessage( hParent , dwStatus , IDS_TSGETPROPSFAILED );
  2541. }
  2542. //-------------------------------------------------------------------------------
  2543. void ErrorMessage2( HWND hParent , DWORD dwStatus )
  2544. {
  2545. xxErrorMessage( hParent , dwStatus , IDS_TSOPSFAILED );
  2546. }
  2547. //-------------------------------------------------------------------------------
  2548. void xxErrorMessage( HWND hParent , DWORD dwStatus , UINT nResID )
  2549. {
  2550. LPTSTR pBuffer = NULL;
  2551. TCHAR tchBuffer[ 256 ];
  2552. TCHAR tchErr[ 128 ];
  2553. TCHAR tchTitle[ 80 ];
  2554. LoadString( _Module.GetModuleInstance( ) , nResID , tchErr , sizeof( tchErr ) / sizeof( TCHAR ) );
  2555. LoadString( _Module.GetModuleInstance( ) , IDS_TSGETPROPTITLE , tchTitle , sizeof( tchTitle ) / sizeof( TCHAR ) );
  2556. FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2557. FORMAT_MESSAGE_FROM_SYSTEM,
  2558. NULL, //ignored
  2559. dwStatus , //message ID
  2560. MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ), //message language
  2561. (LPTSTR)&pBuffer, //address of buffer pointer
  2562. 0, //minimum buffer size
  2563. NULL); //no other arguments
  2564. wsprintf( tchBuffer , tchErr , pBuffer );
  2565. ::MessageBox( hParent , tchBuffer , tchTitle , MB_OK | MB_ICONERROR );
  2566. if( pBuffer != NULL )
  2567. {
  2568. LocalFree( pBuffer );
  2569. }
  2570. }
  2571. #if 0
  2572. //-------------------------------------------------------------------------------
  2573. NTSTATUS GetDomainName( PWCHAR ServerNamePtr, // name of server to get domain of
  2574. LPTSTR DomainNamePtr // alloc and set ptr (free with NetApiBufferFree)
  2575. )
  2576. /*++
  2577. Routine Description:
  2578. Returns the name of the domain or workgroup this machine belongs to.
  2579. Arguments:
  2580. DomainNamePtr - The name of the domain or workgroup
  2581. IsWorkgroupName - Returns TRUE if the name is a workgroup name.
  2582. Returns FALSE if the name is a domain name.
  2583. Return Value:
  2584. NERR_Success - Success.
  2585. NERR_CfgCompNotFound - There was an error determining the domain name
  2586. --*/
  2587. {
  2588. NTSTATUS status;
  2589. LSA_HANDLE PolicyHandle;
  2590. PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo;
  2591. OBJECT_ATTRIBUTES ObjAttributes;
  2592. UNICODE_STRING UniServerName;
  2593. //
  2594. // Check for caller's errors.
  2595. //
  2596. if ( DomainNamePtr == NULL ) {
  2597. return STATUS_INVALID_PARAMETER;
  2598. }
  2599. //
  2600. // Open a handle to the local security policy. Initialize the
  2601. // objects attributes structure first.
  2602. //
  2603. InitializeObjectAttributes(
  2604. &ObjAttributes,
  2605. NULL,
  2606. 0L,
  2607. NULL,
  2608. NULL
  2609. );
  2610. RtlInitUnicodeString( &UniServerName, ServerNamePtr );
  2611. status = LsaOpenPolicy(
  2612. &UniServerName,
  2613. &ObjAttributes,
  2614. POLICY_VIEW_LOCAL_INFORMATION,
  2615. &PolicyHandle
  2616. );
  2617. KdPrint( ( "TSUSEREX - GetDomainName: LsaOpenPolicy returned NTSTATUS = 0x%x\n", status ) );
  2618. if (! NT_SUCCESS(status)) {
  2619. return( status );
  2620. }
  2621. //
  2622. // Get the name of the primary domain from LSA
  2623. //
  2624. status = LsaQueryInformationPolicy(
  2625. PolicyHandle,
  2626. PolicyAccountDomainInformation,
  2627. (PVOID *)&DomainInfo
  2628. );
  2629. KdPrint( ( "TSUSEREX - GetDomainName: LsaQueryInformationPolicy returned NTSTATUS = 0x%x\n", status ) );
  2630. if (! NT_SUCCESS(status)) {
  2631. (void) LsaClose(PolicyHandle);
  2632. return( status );
  2633. }
  2634. (void) LsaClose(PolicyHandle);
  2635. lstrcpy( DomainNamePtr , DomainInfo->DomainName.Buffer );
  2636. (void) LsaFreeMemory((PVOID) DomainInfo);
  2637. return( STATUS_SUCCESS );
  2638. }
  2639. #endif
  2640. BOOL CProfileDlg::createdir( LPTSTR szPath , BOOL bIsRemote , PDWORD pdwErr )
  2641. {
  2642. int npos = 0;
  2643. *pdwErr = ERROR_INVALID_NAME;
  2644. if( bIsRemote )
  2645. {
  2646. // skip over three four whacks
  2647. npos = 2;
  2648. if( szPath[0] != TEXT( '\\' ) && szPath[1] != TEXT( '\\' ) )
  2649. {
  2650. return FALSE;
  2651. }
  2652. for( int n = 0; n < 2 ; n++ )
  2653. {
  2654. while( szPath[ npos ] != TEXT( '\\' ) && szPath[ npos ] != TEXT( '\0' ) )
  2655. {
  2656. npos++;
  2657. }
  2658. if( szPath[ npos ] == TEXT( '\0' ) )
  2659. {
  2660. return FALSE;
  2661. }
  2662. npos++;
  2663. }
  2664. }
  2665. else
  2666. {
  2667. if( szPath[1] != TEXT( ':' ) && szPath[2] != TEXT( '\\' ) )
  2668. {
  2669. return FALSE;
  2670. }
  2671. npos = 3;
  2672. }
  2673. SECURITY_ATTRIBUTES securityAttributes;
  2674. ZeroMemory( &securityAttributes , sizeof( SECURITY_ATTRIBUTES ) );
  2675. // its redundant to check the bIsRemote flag since for dsadmin createdir is only called for
  2676. // UNC paths
  2677. if( m_pUSht->GetDSAType() && bIsRemote )
  2678. {
  2679. //
  2680. // From EricB's DSPROP_CreateHomeDirectory
  2681. PSID psidAdmins = NULL;
  2682. SID_IDENTIFIER_AUTHORITY NtAuth = SECURITY_NT_AUTHORITY;
  2683. if (!AllocateAndInitializeSid(&NtAuth,
  2684. 2,
  2685. SECURITY_BUILTIN_DOMAIN_RID,
  2686. DOMAIN_ALIAS_RID_ADMINS,
  2687. 0, 0, 0, 0, 0, 0,
  2688. &psidAdmins ) )
  2689. {
  2690. ODS( L"AllocateAndInitializeSid failed\n");
  2691. *pdwErr = GetLastError( );
  2692. return FALSE;
  2693. }
  2694. // build a DACL
  2695. PACL pDacl;
  2696. static const int nAceCount = 2;
  2697. PSID pAceSid[nAceCount];
  2698. pAceSid[0] = m_pUSht->GetUserSid( );
  2699. pAceSid[1] = psidAdmins;
  2700. EXPLICIT_ACCESS rgAccessEntry[nAceCount] = {0};
  2701. for (int i = 0 ; i < nAceCount; i++)
  2702. {
  2703. rgAccessEntry[i].grfAccessPermissions = GENERIC_ALL;
  2704. rgAccessEntry[i].grfAccessMode = GRANT_ACCESS;
  2705. rgAccessEntry[i].grfInheritance = SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  2706. // build the trustee structs
  2707. //
  2708. BuildTrusteeWithSid(&(rgAccessEntry[i].Trustee),
  2709. pAceSid[i]);
  2710. }
  2711. // add the entries to the ACL
  2712. //
  2713. *pdwErr = SetEntriesInAcl( nAceCount, rgAccessEntry, NULL, &pDacl );
  2714. if( *pdwErr != 0 )
  2715. {
  2716. ODS( L"SetEntriesInAcl() failed\n" );
  2717. return FALSE;
  2718. }
  2719. // build a security descriptor and initialize it
  2720. // in absolute format
  2721. SECURITY_DESCRIPTOR securityDescriptor;
  2722. PSECURITY_DESCRIPTOR pSecurityDescriptor = &securityDescriptor;
  2723. if( !InitializeSecurityDescriptor( pSecurityDescriptor , SECURITY_DESCRIPTOR_REVISION ) )
  2724. {
  2725. ODS( L"InitializeSecurityDescriptor() failed\n" );
  2726. *pdwErr = GetLastError( );
  2727. return FALSE;
  2728. }
  2729. // add DACL to security descriptor (must be in absolute format)
  2730. if( !SetSecurityDescriptorDacl( pSecurityDescriptor,
  2731. TRUE, // bDaclPresent
  2732. pDacl,
  2733. FALSE // bDaclDefaulted
  2734. ) )
  2735. {
  2736. ODS( L"SetSecurityDescriptorDacl() failed\n" );
  2737. *pdwErr = GetLastError( );
  2738. return FALSE;
  2739. }
  2740. // set the owner of the directory
  2741. if( !SetSecurityDescriptorOwner( pSecurityDescriptor ,
  2742. m_pUSht->GetUserSid( ) ,
  2743. FALSE // bOwnerDefaulted
  2744. ) )
  2745. {
  2746. ODS( L"SetSecurityDescriptorOwner() failed\n" );
  2747. *pdwErr = GetLastError( );
  2748. return FALSE;
  2749. }
  2750. ASSERT_( IsValidSecurityDescriptor( pSecurityDescriptor ) );
  2751. // build a SECURITY_ATTRIBUTES struct as argument for
  2752. // CreateDirectory()
  2753. securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
  2754. securityAttributes.lpSecurityDescriptor = pSecurityDescriptor;
  2755. securityAttributes.bInheritHandle = FALSE;
  2756. if( !CreateDirectory( szPath , &securityAttributes ) )
  2757. {
  2758. *pdwErr = GetLastError( );
  2759. if( psidAdmins != NULL )
  2760. {
  2761. FreeSid( psidAdmins );
  2762. }
  2763. return FALSE;
  2764. }
  2765. FreeSid( psidAdmins );
  2766. }
  2767. else
  2768. {
  2769. // for local accounts we don't need to set security
  2770. while( szPath[ npos ] != TEXT( '\0' ) )
  2771. {
  2772. while( szPath[ npos ] != TEXT( '\\' ) && szPath[ npos ] != TEXT( '\0' ) )
  2773. {
  2774. npos++;
  2775. }
  2776. if( szPath[ npos ] == TEXT( '\0' ) )
  2777. {
  2778. CreateDirectory( szPath , 0 );
  2779. }
  2780. else
  2781. {
  2782. szPath[ npos ] = 0;
  2783. CreateDirectory( szPath , 0 );
  2784. szPath[ npos ] = TEXT( '\\' );
  2785. npos++;
  2786. }
  2787. }
  2788. }
  2789. *pdwErr = 0;
  2790. return TRUE;
  2791. }