fontdlg.c
Upload User: caisha3
Upload Date: 2013-09-21
Package Size: 208739k
Code Size: 4k
Category:

Windows Develop

Development Platform:

Visual C++

  1. /* File: D:WACKERtdllfontdlg.c (Created: 14-Jan-1994)
  2.  *
  3.  * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4.  * All rights reserved
  5.  *
  6.  * $Revision: 3 $
  7.  * $Date: 2/05/99 3:20p $
  8.  */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include "stdtyp.h"
  12. #include "globals.h"
  13. #include "print.hh"
  14. #include "session.h"
  15. #include "misc.h"
  16. #include "term.h"
  17. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  18.  * FUNCTION:
  19.  * DisplayFontDialog
  20.  *
  21.  * DESCRIPTION:
  22.  * Invokes the common dialog box for font selection.
  23.  *
  24.  * ARGUMENTS:
  25.  * HWND hwnd - handle to parent dialog window.
  26.  *
  27.  * RETURNS:
  28.  * void
  29.  *
  30.  */
  31. void DisplayFontDialog(const HSESSION hSession, BOOL fPrinterFont )
  32. {
  33. LOGFONT  lf, lfOld;
  34. CHOOSEFONT  chf;
  35. BOOL  fRet;
  36. const HWND  hwnd     = sessQueryHwnd(hSession);
  37.     HHPRINT     hhPrint  = (HHPRINT) sessQueryPrintHdl(hSession);
  38.     //
  39.     // setup font structure
  40.     //
  41. chf.lStructSize = sizeof(CHOOSEFONT);
  42. chf.hwndOwner   = hwnd;
  43. chf.lpLogFont   = &lf;
  44. chf.rgbColors   = RGB(0, 0, 0);
  45. chf.lCustData   = 0;
  46. chf.hInstance   = glblQueryHinst();
  47. chf.lpszStyle   = (LPTSTR)0;
  48. chf.nFontType   = SCREEN_FONTTYPE;
  49. chf.nSizeMin    = 0;
  50. chf.nSizeMax    = 0;
  51.     //
  52.     // set up for terminal font selection
  53.     //
  54.     if ( !fPrinterFont )
  55.         {
  56.     SendMessage(sessQueryHwndTerminal(hSession), WM_TERM_GETLOGFONT, 0,
  57.                    (LPARAM)&lf);
  58.     chf.hDC    = GetDC(hwnd);
  59.         chf.Flags  = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_NOVERTFONTS |
  60.      CF_INITTOLOGFONTSTRUCT;
  61.      lfOld = lf;
  62.     fRet = ChooseFont(&chf);
  63.      ReleaseDC(hwnd, chf.hDC);
  64.         }
  65.     
  66.     //
  67.     // set up for printer font selection
  68.     //
  69.     else
  70.         {
  71.         hhPrint->hDC = printCtrlCreateDC((HPRINT)hhPrint);
  72.         
  73.         lf = hhPrint->lf;
  74.         chf.hDC    = hhPrint->hDC;
  75.     chf.Flags  = CF_EFFECTS | CF_PRINTERFONTS | CF_NOVERTFONTS | 
  76.                      CF_INITTOLOGFONTSTRUCT;
  77.      lfOld = lf;
  78.     fRet = ChooseFont(&chf);
  79.         }
  80.     // 
  81.     // Save any changes that were made
  82.     //
  83. if (fRet && memcmp(&lf, &lfOld, sizeof(LOGFONT)) != 0)
  84. {
  85. const HWND hwndTerm = sessQueryHwndTerminal(hSession);
  86.         if ( !fPrinterFont )
  87.         {
  88.          SendMessage(hwndTerm, WM_TERM_SETLOGFONT, 0, (LPARAM)&lf);
  89.      RefreshTermWindow(hwndTerm);
  90.             }
  91.         else
  92.             {
  93.             //
  94.             // save the dialog returned log font in the print handle and also 
  95.             // save the selected point size.  This is done since the font point
  96.             // size returned by the dialog is is not correct when used for 
  97.             // printing.  However the dialog settings must be saved for the 
  98.             // next time the dialog is displayed.  The correct font is calculated
  99.             // based on the save point size and face name before printing by the 
  100.             // printCreatePointFont function.
  101.             //
  102.             hhPrint->iFontPointSize = chf.iPointSize;
  103.             hhPrint->lf = lf; 
  104.   
  105.             lf.lfHeight = chf.iPointSize;
  106.             //
  107.             // if char set is ansi change to oem to get line draw characters
  108.             //
  109.         
  110.             if ( lf.lfCharSet == ANSI_CHARSET )
  111.                 {
  112.                 lf.lfCharSet = OEM_CHARSET;
  113.                 }
  114.             }
  115.         //
  116.         // get rid of the printer device context if one was created
  117.         //
  118.         if ( fPrinterFont )
  119.             {
  120.             printCtrlDeleteDC((HPRINT)hhPrint);
  121.             }
  122. }
  123.     return;
  124. }