Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

829 lines
27 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. config.cpp
  5. Abstract:
  6. This module contains routines for the fax config dialog.
  7. Author:
  8. Wesley Witt (wesw) 13-Aug-1996
  9. Revision History:
  10. 20/10/99 -danl-
  11. Fix ConfigDlgProc to view proper printer properties.
  12. dd/mm/yy -author-
  13. description
  14. --*/
  15. #include "faxxp.h"
  16. #include "faxutil.h"
  17. #include "faxreg.h"
  18. #include "resource.h"
  19. #include "debugex.h"
  20. #pragma hdrstop
  21. VOID
  22. AddCoverPagesToList(
  23. HWND hwndList,
  24. LPTSTR pDirPath,
  25. BOOL ServerCoverPage
  26. )
  27. /*++
  28. Routine Description:
  29. Add the cover page files in the specified directory to a listbox
  30. Arguments:
  31. hwndList - Handle to a list window
  32. pDirPath - Directory to look for coverpage files
  33. ServerCoverPage - TRUE if the dir contains server cover pages
  34. Return Value:
  35. NONE
  36. --*/
  37. {
  38. WIN32_FIND_DATA findData;
  39. TCHAR tszDirName[MAX_PATH] = {0};
  40. TCHAR CpName[MAX_PATH] = {0};
  41. HANDLE hFindFile = INVALID_HANDLE_VALUE;
  42. TCHAR tszFileName[MAX_PATH] = {0};
  43. TCHAR tszPathName[MAX_PATH] = {0};
  44. TCHAR* pPathEnd;
  45. LPTSTR pExtension;
  46. INT listIndex;
  47. INT dirLen;
  48. INT fileLen;
  49. BOOL bGotFile = FALSE;
  50. DBG_ENTER(TEXT("AddCoverPagesToList"));
  51. //
  52. // Copy the directory path to a local buffer
  53. //
  54. if (pDirPath == NULL || pDirPath[0] == 0)
  55. {
  56. return;
  57. }
  58. if ((dirLen = _tcslen( pDirPath )) >= MAX_PATH - MAX_FILENAME_EXT - 1)
  59. {
  60. return;
  61. }
  62. _tcscpy( tszDirName, pDirPath );
  63. TCHAR* pLast = NULL;
  64. pLast = _tcsrchr(tszDirName,TEXT('\\'));
  65. if( !( pLast && (*_tcsinc(pLast)) == '\0' ) )
  66. {
  67. // the last character is not a backslash, add one...
  68. _tcscat(tszDirName, TEXT("\\"));
  69. dirLen += sizeof(TCHAR);
  70. }
  71. _tcsncpy(tszPathName, tszDirName, ARR_SIZE(tszPathName)-1);
  72. pPathEnd = _tcschr(tszPathName, '\0');
  73. TCHAR file_to_find[MAX_PATH] = {0};
  74. _tcscpy(file_to_find,tszDirName);
  75. _tcscat(file_to_find, FAX_COVER_PAGE_MASK );
  76. //
  77. // Call FindFirstFile/FindNextFile to enumerate the files
  78. // matching our specification
  79. //
  80. hFindFile = FindFirstFile( file_to_find, &findData );
  81. if (hFindFile == INVALID_HANDLE_VALUE)
  82. {
  83. CALL_FAIL(GENERAL_ERR, TEXT("FindFirstFile"), ::GetLastError());
  84. bGotFile = FALSE;
  85. }
  86. else
  87. {
  88. bGotFile = TRUE;
  89. }
  90. while (bGotFile)
  91. {
  92. _tcsncpy(pPathEnd, findData.cFileName, MAX_PATH - dirLen);
  93. if(!IsValidCoverPage(tszPathName))
  94. {
  95. goto next;
  96. }
  97. //
  98. // Exclude directories and hidden files
  99. //
  100. if (findData.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_DIRECTORY))
  101. {
  102. continue;
  103. }
  104. //
  105. // Make sure we have enough room to store the full pathname
  106. //
  107. if ((fileLen = _tcslen( findData.cFileName)) <= MAX_FILENAME_EXT )
  108. {
  109. continue;
  110. }
  111. if (fileLen + dirLen >= MAX_PATH)
  112. {
  113. continue;
  114. }
  115. //
  116. // Add the cover page name to the list window,
  117. // but don't display the filename extension
  118. //
  119. _tcscpy( CpName, findData.cFileName );
  120. if (pExtension = _tcsrchr(CpName,TEXT('.')))
  121. {
  122. *pExtension = NULL;
  123. }
  124. if ( ! ServerCoverPage )
  125. {
  126. TCHAR szPersonal[30];
  127. LoadString( g_hResource, IDS_PERSONAL, szPersonal, 30 );
  128. _tcscat( CpName, TEXT(" "));
  129. _tcscat( CpName, szPersonal );
  130. }
  131. listIndex = (INT)SendMessage(
  132. hwndList,
  133. LB_ADDSTRING,
  134. 0,
  135. (LPARAM) CpName);
  136. if (listIndex != LB_ERR)
  137. {
  138. SendMessage(hwndList,
  139. LB_SETITEMDATA,
  140. listIndex,
  141. ServerCoverPage ? SERVER_COVER_PAGE : 0);
  142. }
  143. next:
  144. bGotFile = FindNextFile(hFindFile, &findData);
  145. if (! bGotFile)
  146. {
  147. VERBOSE(DBG_MSG, TEXT("FindNextFile"), ::GetLastError());
  148. break;
  149. }
  150. }
  151. if(INVALID_HANDLE_VALUE != hFindFile)
  152. {
  153. FindClose(hFindFile);
  154. }
  155. }
  156. VOID
  157. DrawSampleText(
  158. HWND hDlg,
  159. HDC hDC,
  160. PFAXXP_CONFIG FaxConfig
  161. )
  162. {
  163. int PointSize;
  164. TCHAR PointSizeBuffer[16];
  165. TCHAR FontTypeBuffer[32];
  166. BOOL bItalic = FALSE;
  167. BOOL bBold = FALSE;
  168. DBG_ENTER(TEXT("DrawSampleText"));
  169. PointSize = abs ( MulDiv((int) FaxConfig->FontStruct.lfHeight, 72, GetDeviceCaps( hDC, LOGPIXELSY)));
  170. _stprintf( PointSizeBuffer, TEXT("%d"), PointSize );
  171. SetWindowText( GetDlgItem( hDlg, IDC_FONT_SIZE ), PointSizeBuffer );
  172. SetWindowText( GetDlgItem( hDlg, IDC_FONT_NAME), FaxConfig->FontStruct.lfFaceName );
  173. //
  174. // get the font type
  175. //
  176. ZeroMemory(FontTypeBuffer, sizeof(FontTypeBuffer) );
  177. if (FaxConfig->FontStruct.lfItalic)
  178. {
  179. bItalic = TRUE;
  180. }
  181. if ( FaxConfig->FontStruct.lfWeight == FW_BOLD )
  182. {
  183. bBold = TRUE;
  184. }
  185. if (bBold)
  186. {
  187. LoadString(g_hResource, IDS_FONT_BOLD, FontTypeBuffer, sizeof(FontTypeBuffer) / sizeof(FontTypeBuffer[0]) );
  188. // concat "italic"
  189. if (bItalic)
  190. {
  191. LoadString(g_hResource,
  192. IDS_FONT_ITALIC,
  193. &FontTypeBuffer[lstrlen(FontTypeBuffer)],
  194. sizeof(FontTypeBuffer) / sizeof(FontTypeBuffer[0]) - lstrlen(FontTypeBuffer) );
  195. }
  196. }
  197. else if (bItalic)
  198. {
  199. LoadString(g_hResource, IDS_FONT_ITALIC, FontTypeBuffer, sizeof(FontTypeBuffer) / sizeof(FontTypeBuffer[0]) );
  200. }
  201. else
  202. {
  203. LoadString(g_hResource, IDS_FONT_REGULAR, FontTypeBuffer, sizeof(FontTypeBuffer) / sizeof(FontTypeBuffer[0]) );
  204. }
  205. SetWindowText( GetDlgItem( hDlg, IDC_FONT_STYLE), FontTypeBuffer );
  206. }
  207. void EnableCoverPageList(HWND hDlg)
  208. {
  209. DBG_ENTER(TEXT("EnableCoverPageList"));
  210. if (IsDlgButtonChecked( hDlg, IDC_USE_COVERPAGE ) == BST_CHECKED)
  211. {
  212. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), TRUE );
  213. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST_LABEL ), TRUE );
  214. }
  215. else
  216. {
  217. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST ), FALSE );
  218. EnableWindow( GetDlgItem( hDlg, IDC_COVERPAGE_LIST_LABEL ), FALSE );
  219. }
  220. }
  221. INT_PTR CALLBACK
  222. ConfigDlgProc(
  223. HWND hDlg,
  224. UINT message,
  225. WPARAM wParam,
  226. LPARAM lParam
  227. )
  228. /*++
  229. Routine Description:
  230. Dialog procedure for the fax mail transport configuration
  231. Arguments:
  232. hDlg - Window handle for this dialog
  233. message - Message number
  234. wParam - Parameter #1
  235. lParam - Parameter #2
  236. Return Value:
  237. TRUE - Message was handled
  238. FALSE - Message was NOT handled
  239. --*/
  240. {
  241. static PFAXXP_CONFIG FaxConfig = NULL;
  242. static HWND hwndListPrn = NULL;
  243. static HWND hwndListCov = NULL;
  244. PPRINTER_INFO_2 PrinterInfo = NULL;
  245. DWORD CountPrinters = 0;
  246. DWORD dwSelectedItem = 0;
  247. DWORD dwNewSelectedItem = 0;
  248. TCHAR Buffer[256] = {0};
  249. TCHAR CpDir[MAX_PATH] = {0};
  250. LPTSTR p = NULL;
  251. PAINTSTRUCT ps;
  252. HANDLE hFax = NULL;
  253. DWORD dwError = 0;
  254. DWORD dwMask = 0;
  255. BOOL bShortCutCp = FALSE;
  256. BOOL bGotFaxPrinter = FALSE;
  257. BOOL bIsCpLink = FALSE;
  258. DBG_ENTER(TEXT("ConfigDlgProc"));
  259. switch( message )
  260. {
  261. case WM_INITDIALOG:
  262. FaxConfig = (PFAXXP_CONFIG) lParam;
  263. hwndListPrn = GetDlgItem( hDlg, IDC_PRINTER_LIST );
  264. hwndListCov = GetDlgItem( hDlg, IDC_COVERPAGE_LIST );
  265. //
  266. // populate the printers combobox
  267. //
  268. PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters(NULL,
  269. 2,
  270. &CountPrinters);
  271. if (NULL != PrinterInfo)
  272. {
  273. DWORD j = 0;
  274. for (DWORD i=0; i<CountPrinters; i++)
  275. {
  276. if ((NULL != PrinterInfo[i].pDriverName) &&
  277. (_tcscmp( PrinterInfo[i].pDriverName, FAX_DRIVER_NAME ) == 0))
  278. {
  279. //
  280. //if the current printer is a fax printer, add it to the CB list
  281. //
  282. bGotFaxPrinter = TRUE;
  283. SendMessage( hwndListPrn, CB_ADDSTRING, 0, (LPARAM) PrinterInfo[i].pPrinterName );
  284. if ((NULL != FaxConfig->PrinterName) &&
  285. (NULL != PrinterInfo[i].pPrinterName) &&
  286. (_tcscmp( PrinterInfo[i].pPrinterName, FaxConfig->PrinterName ) == 0))
  287. {
  288. //
  289. //if it is also the default printer according to transport config.
  290. //place the default selection on it
  291. //
  292. dwSelectedItem = j;
  293. }
  294. if(FaxConfig->PrinterName == NULL || _tcslen(FaxConfig->PrinterName) == 0)
  295. {
  296. //
  297. // There is no default fax printer
  298. // Choose the first one
  299. //
  300. MemFree(FaxConfig->PrinterName);
  301. FaxConfig->PrinterName = StringDup(PrinterInfo[i].pPrinterName);
  302. if(FaxConfig->PrinterName == NULL)
  303. {
  304. CALL_FAIL(MEM_ERR, TEXT("StringDup"), ERROR_NOT_ENOUGH_MEMORY);
  305. ErrorMsgBox(g_hResource, IDS_OUT_OF_MEM);
  306. EndDialog( hDlg, IDABORT);
  307. return FALSE;
  308. }
  309. if(PrinterInfo[i].pServerName)
  310. {
  311. MemFree(FaxConfig->ServerName);
  312. FaxConfig->ServerName = StringDup(PrinterInfo[i].pServerName);
  313. if(FaxConfig->ServerName == NULL)
  314. {
  315. CALL_FAIL(MEM_ERR, TEXT("StringDup"), ERROR_NOT_ENOUGH_MEMORY);
  316. ErrorMsgBox(g_hResource, IDS_OUT_OF_MEM);
  317. EndDialog( hDlg, IDABORT);
  318. return FALSE;
  319. }
  320. }
  321. dwSelectedItem = j;
  322. }
  323. j += 1;
  324. } // if fax printer
  325. } // for
  326. MemFree( PrinterInfo );
  327. PrinterInfo = NULL;
  328. SendMessage( hwndListPrn, CB_SETCURSEL, (WPARAM)dwSelectedItem, 0 );
  329. }
  330. if (! bGotFaxPrinter)
  331. {
  332. //
  333. // there were no printers at all, or non of the printers is a fax printer.
  334. //
  335. CALL_FAIL(GENERAL_ERR, TEXT("MyEnumPrinters"), ::GetLastError());
  336. ErrorMsgBox(g_hResource, IDS_NO_FAX_PRINTER);
  337. EndDialog( hDlg, IDABORT);
  338. break;
  339. }
  340. //
  341. // Get the Server CP flag and receipts options
  342. //
  343. FaxConfig->ServerCpOnly = FALSE;
  344. if (FaxConnectFaxServer(FaxConfig->ServerName,&hFax))
  345. {
  346. DWORD dwReceiptOptions;
  347. BOOL bEnableReceiptsCheckboxes = FALSE;
  348. if(!FaxGetPersonalCoverPagesOption(hFax, &FaxConfig->ServerCpOnly))
  349. {
  350. CALL_FAIL(GENERAL_ERR, TEXT("FaxGetPersonalCoverPagesOption"), ::GetLastError());
  351. ErrorMsgBox(g_hResource, IDS_CANT_ACCESS_SERVER);
  352. }
  353. else
  354. {
  355. //
  356. // Inverse logic
  357. //
  358. FaxConfig->ServerCpOnly = !FaxConfig->ServerCpOnly;
  359. }
  360. if (!FaxGetReceiptsOptions (hFax, &dwReceiptOptions))
  361. {
  362. CALL_FAIL(GENERAL_ERR, TEXT("FaxGetPersonalCoverPagesOption"), GetLastError());
  363. }
  364. else
  365. {
  366. if (DRT_EMAIL & dwReceiptOptions)
  367. {
  368. //
  369. // Server supports receipts by email - enable the checkboxes
  370. //
  371. bEnableReceiptsCheckboxes = TRUE;
  372. }
  373. }
  374. EnableWindow( GetDlgItem( hDlg, IDC_ATTACH_FAX), bEnableReceiptsCheckboxes);
  375. EnableWindow( GetDlgItem( hDlg, IDC_SEND_SINGLE_RECEIPT), bEnableReceiptsCheckboxes);
  376. FaxClose(hFax);
  377. hFax = NULL;
  378. }
  379. else
  380. {
  381. CALL_FAIL(GENERAL_ERR, TEXT("FaxConnectFaxServer"), ::GetLastError());
  382. ErrorMsgBox(g_hResource, IDS_CANT_ACCESS_SERVER);
  383. }
  384. //
  385. //send single receipt for a fax sent to multiple recipients?
  386. //
  387. if(FaxConfig->SendSingleReceipt)
  388. {
  389. CheckDlgButton( hDlg, IDC_SEND_SINGLE_RECEIPT, BST_CHECKED );
  390. }
  391. //
  392. // Attach fax document?
  393. //
  394. if (FaxConfig->bAttachFax)
  395. {
  396. CheckDlgButton( hDlg, IDC_ATTACH_FAX, BST_CHECKED );
  397. }
  398. //
  399. //cover page CB & LB enabling
  400. //
  401. if (FaxConfig->UseCoverPage)
  402. {
  403. CheckDlgButton( hDlg, IDC_USE_COVERPAGE, BST_CHECKED );
  404. }
  405. EnableCoverPageList(hDlg);
  406. //
  407. // Emulate printer's selection change, in order to collect printer config info.
  408. // including cover pages LB population
  409. //
  410. ConfigDlgProc(hDlg, WM_COMMAND,MAKEWPARAM(IDC_PRINTER_LIST,CBN_SELCHANGE),(LPARAM)0);
  411. break;
  412. case ( WM_PAINT ) :
  413. if (BeginPaint( hDlg, &ps ))
  414. {
  415. DrawSampleText( hDlg, ps.hdc, FaxConfig );
  416. EndPaint( hDlg, &ps );
  417. }
  418. break;
  419. case WM_COMMAND:
  420. if (HIWORD(wParam) == BN_CLICKED)
  421. {
  422. if (LOWORD(wParam) == IDC_USE_COVERPAGE)
  423. {
  424. EnableCoverPageList(hDlg);
  425. return FALSE;
  426. }
  427. }
  428. if (HIWORD(wParam) == CBN_SELCHANGE && LOWORD(wParam) == IDC_PRINTER_LIST)
  429. {
  430. //
  431. // refresh cover pages list
  432. //
  433. TCHAR SelectedPrinter[MAX_PATH];
  434. DWORD dwPrinterNameLength = 0;
  435. //
  436. // a new fax printer was selected - delete all old coverpages from the list
  437. // because they might include the old fax server's cover pages
  438. //
  439. SendMessage(hwndListCov, LB_RESETCONTENT, 0, 0);
  440. if (CB_ERR != (dwSelectedItem = (DWORD)SendMessage( hwndListPrn, CB_GETCURSEL, 0, 0 )))
  441. //
  442. // get the 0 based index of the currently pointed printer
  443. //
  444. {
  445. if (CB_ERR != (dwPrinterNameLength = (DWORD)SendMessage( hwndListPrn, CB_GETLBTEXTLEN, dwSelectedItem, 0)))
  446. {
  447. if (dwPrinterNameLength < MAX_PATH)
  448. {
  449. if (CB_ERR != SendMessage( hwndListPrn, CB_GETLBTEXT, dwSelectedItem, (LPARAM) SelectedPrinter ))
  450. //
  451. // get that printer's name into SelectedPrinter
  452. //
  453. {
  454. if (NULL != (PrinterInfo = (PPRINTER_INFO_2) MyGetPrinter( SelectedPrinter, 2 )))
  455. {
  456. LPTSTR lptszServerName = NULL;
  457. if (GetServerNameFromPrinterInfo(PrinterInfo,&lptszServerName))
  458. {
  459. if (GetServerCpDir( lptszServerName, CpDir, sizeof(CpDir)/sizeof(CpDir[0]) ))
  460. {
  461. AddCoverPagesToList( hwndListCov, CpDir, TRUE );
  462. }
  463. if ((NULL == FaxConfig->ServerName) ||(NULL == lptszServerName) ||
  464. (_tcscmp(FaxConfig->ServerName,lptszServerName) != 0))
  465. {
  466. //
  467. // the server's name and config are not updated - refresh them
  468. //
  469. MemFree(FaxConfig->ServerName);
  470. FaxConfig->ServerName = lptszServerName;
  471. //
  472. // get the new server's ServerCpOnly flag
  473. //
  474. FaxConfig->ServerCpOnly = FALSE;
  475. if (FaxConnectFaxServer(FaxConfig->ServerName,&hFax) )
  476. {
  477. DWORD dwReceiptOptions;
  478. BOOL bEnableReceiptsCheckboxes = FALSE;
  479. if (!FaxGetPersonalCoverPagesOption(hFax,&FaxConfig->ServerCpOnly))
  480. {
  481. CALL_FAIL(GENERAL_ERR, TEXT("FaxGetPersonalCoverPagesOption"), GetLastError());
  482. }
  483. else
  484. {
  485. //
  486. // inverse logic
  487. //
  488. FaxConfig->ServerCpOnly = !FaxConfig->ServerCpOnly;
  489. }
  490. if (!FaxGetReceiptsOptions (hFax, &dwReceiptOptions))
  491. {
  492. CALL_FAIL(GENERAL_ERR, TEXT("FaxGetPersonalCoverPagesOption"), GetLastError());
  493. }
  494. else
  495. {
  496. if (DRT_EMAIL & dwReceiptOptions)
  497. {
  498. //
  499. // Server supports receipts by email - enable the checkboxes
  500. //
  501. bEnableReceiptsCheckboxes = TRUE;
  502. }
  503. }
  504. EnableWindow( GetDlgItem( hDlg, IDC_ATTACH_FAX), bEnableReceiptsCheckboxes);
  505. EnableWindow( GetDlgItem( hDlg, IDC_SEND_SINGLE_RECEIPT), bEnableReceiptsCheckboxes);
  506. FaxClose(hFax);
  507. hFax = NULL;
  508. }
  509. }
  510. else
  511. {
  512. //
  513. // The server's name hasn't changed, all details are OK
  514. //
  515. MemFree(lptszServerName);
  516. lptszServerName = NULL;
  517. }
  518. }
  519. else
  520. //
  521. // GetServerNameFromPrinterInfo failed
  522. //
  523. {
  524. FaxConfig->ServerCpOnly = FALSE;
  525. }
  526. //
  527. // don't add client coverpages if FaxConfig->ServerCpOnly is set to true
  528. //
  529. if (! FaxConfig->ServerCpOnly)
  530. {
  531. if(GetClientCpDir( CpDir, sizeof(CpDir) / sizeof(CpDir[0])))
  532. {
  533. //
  534. // if the function failes- the ext. is installed on a machine
  535. // that doesn't have a client on it,
  536. // so we shouldn't look for personal cp
  537. //
  538. AddCoverPagesToList( hwndListCov, CpDir, FALSE );
  539. }
  540. }
  541. MemFree( PrinterInfo );
  542. PrinterInfo = NULL;
  543. //
  544. // check if we have any cp in the LB, if not- don't allow the user to
  545. // ask for a cp with he's fax
  546. //
  547. DWORD dwItemCount = (DWORD)SendMessage(hwndListCov, LB_GETCOUNT, NULL, NULL);
  548. if(LB_ERR == dwItemCount)
  549. {
  550. CALL_FAIL(GENERAL_ERR, TEXT("SendMessage (LB_GETCOUNT)"), ::GetLastError());
  551. }
  552. else
  553. {
  554. EnableWindow( GetDlgItem( hDlg, IDC_USE_COVERPAGE ), dwItemCount ? TRUE : FALSE );
  555. }
  556. if(FaxConfig->CoverPageName)
  557. {
  558. _tcscpy( Buffer, FaxConfig->CoverPageName );
  559. }
  560. if ( ! FaxConfig->ServerCoverPage )
  561. {
  562. TCHAR szPersonal[30] = _T("");
  563. LoadString( g_hResource, IDS_PERSONAL, szPersonal, 30 );
  564. _tcscat( Buffer, _T(" ") );
  565. _tcscat( Buffer, szPersonal );
  566. }
  567. dwSelectedItem = (DWORD)SendMessage( hwndListCov, LB_FINDSTRING, -1, (LPARAM) Buffer );
  568. //
  569. // get the index of the default CP
  570. // if it is supposed to be a link, and the cp that we found is not a link,
  571. // find the next string that matches.
  572. // this can happen if there's al ink to a cp named X, and a regular cp named X.
  573. //
  574. if (dwSelectedItem == LB_ERR)
  575. {
  576. dwSelectedItem = 0;
  577. }
  578. SendMessage( hwndListCov, LB_SETCURSEL, (WPARAM) dwSelectedItem, 0 );
  579. //
  580. // place the default selection on that CP
  581. //
  582. }
  583. }
  584. }
  585. }
  586. }
  587. break;
  588. }
  589. switch (wParam)
  590. {
  591. case IDC_SET_FONT:
  592. {
  593. CHOOSEFONT cf;
  594. LOGFONT FontStruct;
  595. CopyMemory( &FontStruct, &FaxConfig->FontStruct, sizeof(LOGFONT) );
  596. cf.lStructSize = sizeof(CHOOSEFONT);
  597. cf.hwndOwner = hDlg;
  598. cf.lpLogFont = &FontStruct;
  599. cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
  600. cf.rgbColors = 0;
  601. cf.lCustData = 0;
  602. cf.lpfnHook = NULL;
  603. cf.lpTemplateName = NULL;
  604. cf.hInstance = NULL;
  605. cf.lpszStyle = NULL;
  606. cf.nFontType = SCREEN_FONTTYPE;
  607. cf.nSizeMin = 0;
  608. cf.nSizeMax = 0;
  609. if (ChooseFont(&cf))
  610. {
  611. CopyMemory( &FaxConfig->FontStruct, &FontStruct, sizeof(LOGFONT) );
  612. InvalidateRect(hDlg, NULL, TRUE);
  613. UpdateWindow( hDlg );
  614. }
  615. }
  616. break;
  617. case IDOK :
  618. //
  619. // Update UseCoverPage
  620. //
  621. FaxConfig->UseCoverPage = (IsDlgButtonChecked( hDlg, IDC_USE_COVERPAGE ) == BST_CHECKED);
  622. //
  623. // Update SendSingleReceipt
  624. //
  625. FaxConfig->SendSingleReceipt = (IsDlgButtonChecked(hDlg, IDC_SEND_SINGLE_RECEIPT) == BST_CHECKED);
  626. //
  627. // Update AttachFax
  628. //
  629. FaxConfig->bAttachFax = (IsDlgButtonChecked(hDlg, IDC_ATTACH_FAX) == BST_CHECKED);
  630. //
  631. // Update selected printer
  632. //
  633. dwSelectedItem = (DWORD)SendMessage( hwndListPrn, CB_GETCURSEL, 0, 0 );
  634. if (dwSelectedItem != CB_ERR)
  635. {
  636. if (CB_ERR != SendMessage( hwndListPrn, CB_GETLBTEXT, dwSelectedItem, (LPARAM) Buffer ))
  637. {
  638. MemFree( FaxConfig->PrinterName );
  639. FaxConfig->PrinterName = StringDup( Buffer );
  640. if(!FaxConfig->PrinterName)
  641. {
  642. CALL_FAIL(MEM_ERR, TEXT("StringDup"), ERROR_NOT_ENOUGH_MEMORY);
  643. ErrorMsgBox(g_hResource, IDS_OUT_OF_MEM);
  644. EndDialog( hDlg, IDABORT);
  645. break;
  646. }
  647. }
  648. }
  649. //
  650. // Update cover page
  651. //
  652. dwSelectedItem = (DWORD)SendMessage( hwndListCov, LB_GETCURSEL, 0, 0 );
  653. if (dwSelectedItem != LB_ERR) //LB_ERR when no items in list
  654. {
  655. if (LB_ERR != SendMessage( hwndListCov, LB_GETTEXT, dwSelectedItem, (LPARAM) Buffer ))
  656. //
  657. // get the selected CP name into the buffer
  658. //
  659. {
  660. dwMask = (DWORD)SendMessage( hwndListCov, LB_GETITEMDATA, dwSelectedItem, 0 );
  661. if (dwMask != LB_ERR)
  662. {
  663. FaxConfig->ServerCoverPage = (dwMask & SERVER_COVER_PAGE) == SERVER_COVER_PAGE;
  664. if (!FaxConfig->ServerCoverPage)
  665. {
  666. //
  667. // if the selected CP in the LB is not a server's CP
  668. // Omit the suffix: "(personal)"
  669. //
  670. p = _tcsrchr( Buffer, '(' );
  671. Assert(p);
  672. if( p )
  673. {
  674. p = _tcsdec(Buffer,p);
  675. if( p )
  676. {
  677. _tcsnset(p,TEXT('\0'),1);
  678. }
  679. }
  680. }
  681. }
  682. //
  683. // update CP name to the selected one in the LB
  684. //
  685. MemFree( FaxConfig->CoverPageName );
  686. FaxConfig->CoverPageName = StringDup( Buffer );
  687. if(!FaxConfig->CoverPageName)
  688. {
  689. CALL_FAIL(MEM_ERR, TEXT("StringDup"), ERROR_NOT_ENOUGH_MEMORY);
  690. ErrorMsgBox(g_hResource, IDS_OUT_OF_MEM);
  691. EndDialog( hDlg, IDABORT);
  692. break;
  693. }
  694. }
  695. }
  696. EndDialog( hDlg, IDOK );
  697. break;
  698. case IDCANCEL:
  699. EndDialog( hDlg, IDCANCEL );
  700. break;
  701. }
  702. break;
  703. case WM_HELP:
  704. WinHelpContextPopup(((LPHELPINFO)lParam)->dwContextId, hDlg);
  705. return TRUE;
  706. case WM_CONTEXTMENU:
  707. WinHelpContextPopup(GetWindowContextHelpId((HWND)wParam), hDlg);
  708. return TRUE;
  709. }
  710. return FALSE;
  711. }