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.

877 lines
28 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. dcomputer.cpp
  5. Abstract:
  6. This file contains implementation of
  7. the computer selection dialog.
  8. Environment:
  9. WIN32 User Mode
  10. Author:
  11. Darwin Ouyang (t-darouy) 30-Sept-1997
  12. --*/
  13. #include "stdafx.h"
  14. #include "dgenprop.h"
  15. #include "faxcompd.h" // IComponentData
  16. #include "inode.h" // internal node
  17. #include "iroot.h" // root node
  18. #include "adminhlp.h"
  19. #pragma hdrstop
  20. #define MyHideWindow(_hwnd) ::SetWindowLong((_hwnd),GWL_STYLE,::GetWindowLong((_hwnd),GWL_STYLE)&~WS_VISIBLE)
  21. ////////////////////////////////////////////////////////////////////////////////////////////////////
  22. ////////////////////////////////////////////////////////////////////////////////////////////////////
  23. ////////////////////////////////////////////////////////////////////////////////////////////////////
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////
  25. //
  26. //
  27. // Constructor and destructor
  28. //
  29. //
  30. CFaxGeneralSettingsPropSheet::CFaxGeneralSettingsPropSheet(
  31. IN HINSTANCE hInstance,
  32. IN LONG_PTR hMmcNotify,
  33. IN CInternalRoot * NodePtr
  34. )
  35. : _hMmcNotify( hMmcNotify ),
  36. _pOwnNode( NodePtr )
  37. /*++
  38. Routine Description:
  39. Constructor
  40. Arguments:
  41. hInstance - the instance pointer
  42. hMmcNotify - the MMC notify handle
  43. NodePtr - a pointer to the owning node
  44. Return Value:
  45. None.
  46. --*/
  47. {
  48. DebugPrint(( TEXT("CFaxGeneralSettingsPropSheet Created") ));
  49. _PropSheet.dwSize = sizeof( *this );
  50. _PropSheet.dwFlags = PSP_USETITLE | PSP_USECALLBACK ;
  51. _PropSheet.hInstance = hInstance;
  52. _PropSheet.pszTemplate = MAKEINTRESOURCE(IDP_GENERAL_PROPS);
  53. _PropSheet.pszTitle = MAKEINTRESOURCE(IDP_GENERAL_PROPS_TITLE);
  54. _PropSheet.pfnDlgProc = CFaxGeneralSettingsPropSheet::DlgProc;
  55. _PropSheet.lParam = (LONG_PTR)this;
  56. _PropSheet.pfnCallback = &PropSheetPageProc;
  57. _hPropSheet = NULL;
  58. _hPropSheet = CreatePropertySheetPage( &_PropSheet );
  59. INITCOMMONCONTROLSEX icex;
  60. icex.dwSize = sizeof(icex);
  61. icex.dwICC = ICC_DATE_CLASSES;
  62. InitCommonControlsEx(&icex);
  63. assert( _hPropSheet != NULL );
  64. _hFaxServer = NodePtr->m_pCompData->m_FaxHandle;
  65. _pCompData = NodePtr->m_pCompData;
  66. assert( _hFaxServer );
  67. _MapiProfiles = NULL;
  68. }
  69. CFaxGeneralSettingsPropSheet::~CFaxGeneralSettingsPropSheet()
  70. /*++
  71. Routine Description:
  72. Destructor
  73. Arguments:
  74. None.
  75. Return Value:
  76. None.
  77. --*/
  78. {
  79. DebugPrint(( TEXT("CFaxGeneralSettingsPropSheet Destroyed") ));
  80. }
  81. ////////////////////////////////////////////////////////////////////////////////////////////////////
  82. ////////////////////////////////////////////////////////////////////////////////////////////////////
  83. ////////////////////////////////////////////////////////////////////////////////////////////////////
  84. ////////////////////////////////////////////////////////////////////////////////////////////////////
  85. //
  86. //
  87. // Dialog Proc
  88. //
  89. //
  90. INT_PTR
  91. APIENTRY
  92. CFaxGeneralSettingsPropSheet::DlgProc(
  93. IN HWND hwndDlg,
  94. IN UINT message,
  95. IN WPARAM wParam,
  96. IN LPARAM lParam
  97. )
  98. /*++
  99. Routine Description:
  100. Dialog Procedure
  101. Arguments:
  102. hwndDlg - the hwnd of the dialog
  103. message - the message
  104. wParam, lParam - the window message parameters
  105. Return Value:
  106. BOOL
  107. --*/
  108. {
  109. // DebugPrint(( TEXT("Trace: CFaxGeneralSettingsPropSheet::DlgProc") ));
  110. BOOL fRet = FALSE;
  111. HWND hwnd = NULL;
  112. HWND hwndSheet = NULL;
  113. PFAX_CONFIGURATION config= NULL;
  114. TCHAR buffer[ 20 ];
  115. switch( message ) {
  116. case WM_INITDIALOG:
  117. {
  118. DebugPrint(( TEXT("CFaxGeneralSettingsPropSheet::DlgProc -- WM_INITDIALOG\n") ));
  119. assert( lParam != NULL );
  120. LONG_PTR lthis = ((CFaxGeneralSettingsPropSheet *)lParam)->_PropSheet.lParam;
  121. CFaxGeneralSettingsPropSheet * pthis = (CFaxGeneralSettingsPropSheet *)lthis;
  122. assert( pthis != NULL );
  123. SetWindowLongPtr( hwndDlg, DWLP_USER, lthis );
  124. // get the fax config data
  125. try {
  126. if( pthis->_pCompData->QueryRpcError() ) {
  127. fRet = FALSE;
  128. break;
  129. }
  130. if( !FaxGetConfiguration( pthis->_hFaxServer, &config ) ) {
  131. if (GetLastError() != ERROR_ACCESS_DENIED) {
  132. pthis->_pCompData->NotifyRpcError( TRUE );
  133. assert(FALSE);
  134. }
  135. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  136. fRet = FALSE;
  137. break;
  138. }
  139. } catch( ... ) {
  140. pthis->_pCompData->NotifyRpcError( TRUE );
  141. assert(FALSE);
  142. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  143. fRet = FALSE;
  144. break;
  145. }
  146. // setup retry count
  147. ZeroMemory( (PVOID)buffer, sizeof( TCHAR ) * 20 );
  148. SetDlgItemText( hwndDlg, IDC_RETRY_COUNT, _itot( config->Retries, buffer, 10 ) );
  149. SendMessage( GetDlgItem(hwndDlg, IDC_RETRY_COUNT), EM_SETLIMITTEXT, 2 , 0 );
  150. // setup retry delay
  151. ZeroMemory( (PVOID)buffer, sizeof( TCHAR ) * 20 );
  152. SetDlgItemText( hwndDlg, IDC_RETRY_DELAY, _itot( config->RetryDelay, buffer, 10 ) );
  153. SendMessage( GetDlgItem(hwndDlg, IDC_RETRY_DELAY), EM_SETLIMITTEXT, 2 , 0 );
  154. // setup unsent keep time
  155. ZeroMemory( (PVOID)buffer, sizeof( TCHAR ) * 20 );
  156. SetDlgItemText( hwndDlg, IDC_KEEP_DAYS, _itot( config->DirtyDays, buffer, 10 ) );
  157. SendMessage( GetDlgItem(hwndDlg, IDC_KEEP_DAYS), EM_SETLIMITTEXT, 2 , 0 );
  158. // setup print banner
  159. hwnd = GetDlgItem( hwndDlg, IDC_PRINT_BANNER );
  160. if( config->Branding == TRUE ) {
  161. SendMessage( hwnd, BM_SETCHECK, BST_CHECKED, 0 );
  162. } else {
  163. SendMessage( hwnd, BM_SETCHECK, BST_UNCHECKED, 0 );
  164. }
  165. // setup use TSID
  166. hwnd = GetDlgItem( hwndDlg, IDC_USE_TSID );
  167. if( config->UseDeviceTsid == TRUE ) {
  168. SendMessage( hwnd, BM_SETCHECK, BST_CHECKED, 0 );
  169. } else {
  170. SendMessage( hwnd, BM_SETCHECK, BST_UNCHECKED, 0 );
  171. }
  172. // setup use server coverpages
  173. hwnd = GetDlgItem( hwndDlg, IDC_FORCESERVERCP );
  174. if( config->ServerCp == TRUE ) {
  175. SendMessage( hwnd, BM_SETCHECK, BST_CHECKED, 0 );
  176. } else {
  177. SendMessage( hwnd, BM_SETCHECK, BST_UNCHECKED, 0 );
  178. }
  179. // setup archive outgoing faxes
  180. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE );
  181. if( config->ArchiveOutgoingFaxes == TRUE ) {
  182. SendMessage( hwnd, BM_SETCHECK, BST_CHECKED, 0 );
  183. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_PATH );
  184. EnableWindow( hwnd, TRUE );
  185. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_BROWSE );
  186. EnableWindow( hwnd, TRUE );
  187. } else {
  188. SendMessage( hwnd, BM_SETCHECK, BST_UNCHECKED, 0 );
  189. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_PATH );
  190. EnableWindow( hwnd, FALSE );
  191. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_BROWSE );
  192. EnableWindow( hwnd, FALSE );
  193. }
  194. // setup archive path
  195. SetDlgItemText( hwndDlg, IDC_ARCHIVE_PATH, config->ArchiveDirectory );
  196. SendMessage( GetDlgItem(hwndDlg, IDC_ARCHIVE_PATH), EM_SETLIMITTEXT, MAX_PATH-16 , 0 );
  197. //
  198. // setup server mapi profile box
  199. //
  200. if ( !FaxGetMapiProfiles( pthis->_hFaxServer, &pthis->_MapiProfiles ) ) {
  201. pthis->_MapiProfiles = NULL;
  202. hwnd = GetDlgItem( hwndDlg, IDC_SERVER_MAPI_PROFILE );
  203. SendMessage( hwnd, CB_RESETCONTENT, 0 , 0 );
  204. MyHideWindow(hwnd);
  205. MyHideWindow(GetDlgItem(hwndDlg, IDC_STATIC_MAPI_PROFILE) );
  206. } else {
  207. hwnd = GetDlgItem( hwndDlg, IDC_SERVER_MAPI_PROFILE );
  208. EnableWindow( GetDlgItem( hwndDlg, IDC_STATIC_MAPI_PROFILE ), TRUE );
  209. EnableWindow( hwnd, TRUE );
  210. SendMessage( hwnd,CB_RESETCONTENT, 0 , 0 );
  211. EnumMapiProfiles( hwnd, (LPTSTR) config->InboundProfile, pthis );
  212. }
  213. // initialize time controls
  214. InitTimeControl( GetDlgItem( hwndDlg, IDC_TIMESTART ),
  215. config->StartCheapTime
  216. );
  217. InitTimeControl( GetDlgItem( hwndDlg, IDC_TIMEEND ),
  218. config->StopCheapTime
  219. );
  220. FaxFreeBuffer( (PVOID) config );
  221. pthis->_pCompData->IncPropSheetCount();
  222. fRet = TRUE;
  223. break;
  224. }
  225. case WM_COMMAND:
  226. {
  227. DebugPrint(( TEXT("CFaxGeneralSettingsPropSheet::DlgProc -- WM_COMMAND\n") ));
  228. // activate apply button
  229. WORD wID = LOWORD( wParam );
  230. switch( HIWORD( wParam) ) {
  231. case EN_CHANGE:
  232. switch( wID ) {
  233. case IDC_ARCHIVE_PATH:
  234. case IDC_RETRY_COUNT:
  235. case IDC_RETRY_DELAY:
  236. case IDC_KEEP_DAYS:
  237. hwndSheet = GetParent( hwndDlg );
  238. PropSheet_Changed( hwndSheet, hwndDlg );
  239. break;
  240. }
  241. break;
  242. case CBN_SELCHANGE:
  243. if (wID == IDC_SERVER_MAPI_PROFILE) {
  244. hwndSheet = GetParent( hwndDlg );
  245. PropSheet_Changed( hwndSheet, hwndDlg );
  246. }
  247. break;
  248. case BN_CLICKED:
  249. switch( wID ) {
  250. case IDC_ARCHIVE_BROWSE:
  251. if( BrowseForDirectory( hwndDlg ) == TRUE ) {
  252. hwndSheet = GetParent( hwndDlg );
  253. PropSheet_Changed( hwndSheet, hwndDlg );
  254. }
  255. break;
  256. case IDC_ARCHIVE:
  257. if( SendDlgItemMessage( hwndDlg, IDC_ARCHIVE, BM_GETCHECK, 0, 0 ) == BST_CHECKED ) {
  258. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_PATH );
  259. EnableWindow( hwnd, TRUE );
  260. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_BROWSE );
  261. EnableWindow( hwnd, TRUE );
  262. } else {
  263. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_PATH );
  264. EnableWindow( hwnd, FALSE );
  265. hwnd = GetDlgItem( hwndDlg, IDC_ARCHIVE_BROWSE );
  266. EnableWindow( hwnd, FALSE );
  267. }
  268. //fall through
  269. case IDC_PRINT_BANNER:
  270. case IDC_USE_TSID:
  271. case IDC_FORCESERVERCP:
  272. hwndSheet = GetParent( hwndDlg );
  273. PropSheet_Changed( hwndSheet, hwndDlg );
  274. break;
  275. }
  276. break;
  277. } // switch
  278. fRet = TRUE;
  279. break;
  280. }
  281. case WM_HELP:
  282. WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle,
  283. FAXCFG_HELP_FILENAME,
  284. HELP_WM_HELP,
  285. (ULONG_PTR) &ServerGeneralHelpIDs);
  286. fRet = TRUE;
  287. break;
  288. case WM_CONTEXTMENU:
  289. WinHelp((HWND) wParam,
  290. FAXCFG_HELP_FILENAME,
  291. HELP_CONTEXTMENU,
  292. (ULONG_PTR) &ServerGeneralHelpIDs);
  293. fRet = TRUE;
  294. break;
  295. case WM_NOTIFY:
  296. {
  297. // DebugPrint(( TEXT("CFaxGeneralSettingsPropSheet::DlgProc -- WM_NOTIFY\n") ));
  298. CFaxGeneralSettingsPropSheet * pthis =
  299. (CFaxGeneralSettingsPropSheet *)GetWindowLongPtr( hwndDlg,
  300. DWLP_USER );
  301. switch( ((LPNMHDR) lParam)->code ) {
  302. case PSN_APPLY:
  303. // apply changes here!!
  304. if( SUCCEEDED( pthis->UpdateData( hwndDlg ) ) ) {
  305. MMCPropertyChangeNotify( pthis->_hMmcNotify, (LONG_PTR)pthis->_pOwnNode );
  306. // deactivate apply button
  307. hwndSheet = GetParent( hwndDlg );
  308. SetWindowLongPtr( hwndDlg,
  309. DWLP_MSGRESULT,
  310. PSNRET_NOERROR );
  311. //PropSheet_UnChanged( hwndSheet, hwndDlg );
  312. } else {
  313. SetWindowLongPtr( hwndDlg,
  314. DWLP_MSGRESULT,
  315. PSNRET_INVALID_NOCHANGEPAGE );
  316. }
  317. fRet = TRUE;
  318. break;
  319. case DTN_DATETIMECHANGE:
  320. // activate apply button
  321. hwndSheet = GetParent( hwndDlg );
  322. PropSheet_Changed( hwndSheet, hwndDlg );
  323. fRet = 0;
  324. break;
  325. } // switch
  326. break;
  327. }
  328. case WM_DESTROY:
  329. {
  330. DebugPrint(( TEXT("CFaxGeneralSettingsPropSheet::DlgProc -- WM_DESTROY\n") ));
  331. CFaxGeneralSettingsPropSheet * pthis =
  332. (CFaxGeneralSettingsPropSheet *)GetWindowLongPtr( hwndDlg,
  333. DWLP_USER );
  334. if( pthis != NULL ) {
  335. pthis->_pCompData->DecPropSheetCount();
  336. MMCFreeNotifyHandle( pthis->_hMmcNotify );
  337. } else {
  338. assert( FALSE );
  339. }
  340. fRet = TRUE;
  341. break;
  342. }
  343. } // switch
  344. return fRet;
  345. }
  346. ////////////////////////////////////////////////////////////////////////////////////////////////////
  347. ////////////////////////////////////////////////////////////////////////////////////////////////////
  348. ////////////////////////////////////////////////////////////////////////////////////////////////////
  349. ////////////////////////////////////////////////////////////////////////////////////////////////////
  350. //
  351. //
  352. // Internal Functions.
  353. //
  354. //
  355. HRESULT
  356. CFaxGeneralSettingsPropSheet::UpdateData(
  357. IN HWND hwndDlg
  358. )
  359. /*++
  360. Routine Description:
  361. This routine writes the data manipulated in the property page out to the
  362. fax service.
  363. The settings are updated in the property sheet because this
  364. allows the property sheet to complete even if the owner node
  365. has already been destroyed.
  366. Arguments:
  367. hwndDlg - the dialog's window handle
  368. Return Value:
  369. HRESULT indicating SUCCEDED() or FAILED()
  370. --*/
  371. {
  372. DebugPrint(( TEXT("Trace: CInternalDevice::UpdateData") ));
  373. assert( hwndDlg != NULL );
  374. HRESULT hr = S_OK;
  375. HWND hwndSheet;
  376. BOOL rc;
  377. TCHAR buffer[ MAX_PATH + 1 ];
  378. PFAX_CONFIGURATION config = NULL;
  379. HWND hwndControl;
  380. int index;
  381. TCHAR MapiProfile[100];
  382. ZeroMemory( buffer, sizeof(TCHAR) * MAX_PATH + 1 );
  383. try {
  384. do {
  385. // get the fax config data
  386. if( _pCompData->QueryRpcError() ) {
  387. hr = E_UNEXPECTED;
  388. break;
  389. }
  390. if( !FaxGetConfiguration( _hFaxServer, &config ) ) {
  391. if (GetLastError() != ERROR_ACCESS_DENIED) {
  392. _pCompData->NotifyRpcError( TRUE );
  393. assert(FALSE);
  394. }
  395. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  396. hr = E_UNEXPECTED;
  397. break;
  398. }
  399. // setup retry count
  400. config->Retries = GetDlgItemInt( hwndDlg,
  401. IDC_RETRY_COUNT, // control identifier
  402. &rc,
  403. FALSE );
  404. if( rc == FALSE ) {
  405. hr = E_UNEXPECTED;
  406. break;
  407. }
  408. // validate and limit the retry count
  409. config->Retries = max(config->Retries,0);
  410. config->Retries = min(config->Retries,99);
  411. // setup retry delay
  412. config->RetryDelay = GetDlgItemInt( hwndDlg,
  413. IDC_RETRY_DELAY, // control identifier
  414. &rc,
  415. FALSE );
  416. if( rc == FALSE ) {
  417. hr = E_UNEXPECTED;
  418. break;
  419. }
  420. // validate and limit the retry delay
  421. config->RetryDelay = max(config->RetryDelay,0);
  422. config->RetryDelay = min(config->RetryDelay,99);
  423. // setup unsent keep time
  424. config->DirtyDays = GetDlgItemInt( hwndDlg,
  425. IDC_KEEP_DAYS, // control identifier
  426. &rc,
  427. FALSE );
  428. if( rc == FALSE ) {
  429. hr = E_UNEXPECTED;
  430. break;
  431. }
  432. // validate and limit the dirty day
  433. config->DirtyDays = max(config->DirtyDays,0);
  434. config->DirtyDays = min(config->DirtyDays,99);
  435. // setup print banner
  436. if( IsDlgButtonChecked( hwndDlg, IDC_PRINT_BANNER ) == BST_CHECKED ) {
  437. config->Branding = TRUE;
  438. } else {
  439. config->Branding = FALSE;
  440. }
  441. // setup use TSID
  442. if( IsDlgButtonChecked( hwndDlg, IDC_USE_TSID ) == BST_CHECKED ) {
  443. config->UseDeviceTsid = TRUE;
  444. } else {
  445. config->UseDeviceTsid = FALSE;
  446. }
  447. // setup use server coverpages
  448. if( IsDlgButtonChecked( hwndDlg, IDC_FORCESERVERCP ) == BST_CHECKED ) {
  449. config->ServerCp = TRUE;
  450. } else {
  451. config->ServerCp = FALSE;
  452. }
  453. // setup archive outgoing faxes
  454. config->ArchiveOutgoingFaxes = (IsDlgButtonChecked( hwndDlg, IDC_ARCHIVE ) == BST_CHECKED );
  455. if (config->ArchiveOutgoingFaxes) {
  456. GetDlgItemText( hwndDlg, IDC_ARCHIVE_PATH, buffer, MAX_PATH );
  457. if (!(*buffer)) {
  458. hwndSheet = GetParent( hwndDlg );
  459. ::GlobalStringTable->PopUpMsg( hwndSheet, IDS_NO_ARCHIVE_PATH, TRUE , 0 );
  460. hr = E_UNEXPECTED;
  461. break;
  462. }
  463. if((PathIsDirectory( buffer ) == FALSE) ) {
  464. //
  465. // try to create the directory
  466. //
  467. MakeDirectory( buffer );
  468. if (! PathIsDirectory( buffer ) ) {
  469. hwndSheet = GetParent( hwndDlg );
  470. ::GlobalStringTable->PopUpMsg( hwndSheet, IDS_BAD_ARCHIVE_PATH, TRUE , 0 );
  471. hr = E_UNEXPECTED;
  472. break;
  473. }
  474. }
  475. config->ArchiveDirectory = buffer;
  476. }
  477. // get the time control times.
  478. SYSTEMTIME time;
  479. ZeroMemory( (PVOID) &time, sizeof( SYSTEMTIME ) );
  480. DateTime_GetSystemtime( GetDlgItem( hwndDlg, IDC_TIMESTART ), &time );
  481. config->StartCheapTime.Hour = time.wHour;
  482. config->StartCheapTime.Minute = time.wMinute;
  483. ZeroMemory( (PVOID) &time, sizeof( SYSTEMTIME ) );
  484. DateTime_GetSystemtime( GetDlgItem( hwndDlg, IDC_TIMEEND ), &time );
  485. config->StopCheapTime.Hour = time.wHour;
  486. config->StopCheapTime.Minute = time.wMinute;
  487. // get the mapi profile
  488. if (_MapiProfiles) {
  489. hwndControl = GetDlgItem( hwndDlg, IDC_SERVER_MAPI_PROFILE );
  490. index = (int)SendMessage( hwndControl, CB_GETCURSEL, 0 , 0 );
  491. if (index <= 0) {
  492. config->InboundProfile = NULL;
  493. } else {
  494. index = (int)SendMessage( hwndControl, CB_GETLBTEXT,index,(LPARAM) MapiProfile );
  495. if (index != CB_ERR) {
  496. config->InboundProfile = MapiProfile;
  497. }
  498. }
  499. }
  500. if( !FaxSetConfiguration( _hFaxServer, config ) ) {
  501. if (GetLastError() != ERROR_ACCESS_DENIED) {
  502. _pCompData->NotifyRpcError( TRUE );
  503. assert(FALSE);
  504. }
  505. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  506. hr= E_UNEXPECTED;
  507. break;
  508. }
  509. } while( 0 );
  510. } catch( ... ) {
  511. _pCompData->NotifyRpcError( TRUE );
  512. assert(FALSE);
  513. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  514. hr = E_UNEXPECTED;
  515. }
  516. if(config != NULL ) {
  517. FaxFreeBuffer( (PVOID) config );
  518. config = NULL;
  519. }
  520. return hr;
  521. }
  522. ////////////////////////////////////////////////////////////////////////////////////////////////////
  523. ////////////////////////////////////////////////////////////////////////////////////////////////////
  524. ////////////////////////////////////////////////////////////////////////////////////////////////////
  525. ////////////////////////////////////////////////////////////////////////////////////////////////////
  526. //
  527. //
  528. // Utility Functions
  529. //
  530. //
  531. BOOL CFaxGeneralSettingsPropSheet::InitTimeControl(
  532. IN HWND hwndTimeCtrl,
  533. IN FAX_TIME faxTime
  534. )
  535. /*++
  536. Routine Description:
  537. This function sets the time.
  538. Arguments:
  539. hwndTime - the time control's window handle
  540. faxTime - a fax time struct to init the control to
  541. Return Value:
  542. --*/
  543. {
  544. SYSTEMTIME time;
  545. TCHAR Is24H[2], IsRTL[2], *pszTimeFormat = ::GlobalStringTable->GetString(IDS_TIME_FORMAT);
  546. if (GetLocaleInfo( LOCALE_USER_DEFAULT,LOCALE_ITIME, Is24H,sizeof(Is24H) ) && Is24H[0] == TEXT('1')) {
  547. pszTimeFormat = ::GlobalStringTable->GetString(IDS_24HTIME_FORMAT);
  548. }
  549. else if (GetLocaleInfo( LOCALE_USER_DEFAULT,LOCALE_ITIMEMARKPOSN, IsRTL,sizeof(IsRTL) ) && IsRTL[0] == TEXT('1')) {
  550. pszTimeFormat = ::GlobalStringTable->GetString(IDS_RTLTIME_FORMAT);
  551. }
  552. // initialize time
  553. GetLocalTime( &time ); // just to fill the struct in
  554. time.wHour = faxTime.Hour;
  555. time.wMinute = faxTime.Minute;
  556. time.wSecond = 0;
  557. time.wMilliseconds = 0;
  558. DateTime_SetFormat( hwndTimeCtrl,pszTimeFormat );
  559. DateTime_SetSystemtime( hwndTimeCtrl, GDT_VALID, &time );
  560. return TRUE;
  561. }
  562. BOOL
  563. CFaxGeneralSettingsPropSheet::BrowseForDirectory(
  564. IN HWND hwndDlg
  565. )
  566. /*++
  567. Routine Description:
  568. Browse for a directory
  569. Arguments:
  570. hwndDlg - Specifies the dialog window on which the Browse button is displayed
  571. Return Value:
  572. TRUE if successful, FALSE if the user presses Cancel
  573. --*/
  574. {
  575. LPITEMIDLIST pidl;
  576. WCHAR buffer[MAX_PATH];
  577. VOID SHFree(LPVOID);
  578. BOOL result = FALSE;
  579. LPMALLOC pMalloc;
  580. BROWSEINFO bi = {
  581. hwndDlg,
  582. NULL,
  583. buffer,
  584. ::GlobalStringTable->GetString( IDS_GET_ARCHIVE_DIRECTORY ),
  585. BIF_RETURNONLYFSDIRS,
  586. NULL,
  587. (LPARAM) buffer,
  588. };
  589. if(! GetDlgItemText( hwndDlg, IDC_ARCHIVE_PATH, buffer, MAX_PATH))
  590. buffer[0] = 0;
  591. if(pidl = SHBrowseForFolder(&bi)) {
  592. if(SHGetPathFromIDList(pidl, buffer)) {
  593. if(wcslen(buffer) > MAX_PATH-16)
  594. ::GlobalStringTable->PopUpMsg(0,IDS_DIR_TOO_LONG, TRUE, NULL );
  595. else {
  596. SetDlgItemText(hwndDlg, IDC_ARCHIVE_PATH, buffer);
  597. result = TRUE;
  598. }
  599. }
  600. SHGetMalloc(&pMalloc);
  601. pMalloc->Free(pidl);
  602. pMalloc->Release();
  603. }
  604. return result;
  605. }
  606. BOOL
  607. CFaxGeneralSettingsPropSheet::EnumMapiProfiles(
  608. HWND hwnd,
  609. LPWSTR SelectedProfile,
  610. CFaxGeneralSettingsPropSheet * pthis
  611. )
  612. /*++
  613. Routine Description:
  614. Put the mapi profiles in the combo box, selects the specified profile
  615. Arguments:
  616. hwnd - window handle to mapi profiles combo box
  617. Return Value:
  618. NONE
  619. --*/
  620. {
  621. LPWSTR MapiProfiles;
  622. int index;
  623. MapiProfiles = (LPWSTR) pthis->_MapiProfiles;
  624. if (!MapiProfiles) {
  625. return FALSE;
  626. }
  627. //
  628. // insert a "none" selection as the first entry
  629. //
  630. ::SendMessage(
  631. hwnd,
  632. CB_ADDSTRING,
  633. 0,
  634. (LPARAM) ::GlobalStringTable->GetString( IDS_NO_MAPI )
  635. );
  636. while (MapiProfiles && *MapiProfiles) {
  637. ::SendMessage(
  638. hwnd,
  639. CB_ADDSTRING,
  640. 0,
  641. (LPARAM) MapiProfiles
  642. );
  643. MapiProfiles += wcslen(MapiProfiles) + 1;
  644. }
  645. if (SelectedProfile) {
  646. index = (int)SendMessage(hwnd,CB_FINDSTRINGEXACT,-1,(LPARAM) SelectedProfile);
  647. } else {
  648. index = 0;
  649. }
  650. if (index != CB_ERR) {
  651. SendMessage(hwnd, CB_SETCURSEL, index, 0);
  652. }
  653. return TRUE;
  654. }
  655. UINT
  656. CALLBACK
  657. CFaxGeneralSettingsPropSheet::PropSheetPageProc(
  658. HWND hwnd,
  659. UINT uMsg,
  660. LPPROPSHEETPAGE ppsp
  661. )
  662. /*++
  663. Routine Description:
  664. Dialog Init and destroy routine
  665. Arguments:
  666. hwndDlg - the hwnd of the dialog - will be NULL
  667. uMsg - the message PSPCB_CREATE or PSPCB_RELEASE
  668. ppsp - pointer to a PROPERTYSHEETPAGE struct
  669. Return Value:
  670. UINT - nonzero to allow, zero to fail
  671. --*/
  672. {
  673. CFaxGeneralSettingsPropSheet * pthis = NULL;
  674. UINT retval = 1;
  675. // release my property sheet
  676. if( uMsg == PSPCB_RELEASE ) {
  677. try {
  678. pthis = (CFaxGeneralSettingsPropSheet * )(ppsp->lParam);
  679. delete pthis;
  680. } catch( ... ) {
  681. assert( FALSE );
  682. retval = 0;
  683. }
  684. }
  685. return retval;
  686. }