home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / fontedit / fonthead.c < prev    next >
Text File  |  1996-01-07  |  27KB  |  768 lines

  1. #include "windows.h"
  2. #include <windowsx.h>
  3. #include "fontedit.h"
  4. #include "fcntl.h"
  5. #include "stdio.h"
  6.  
  7. #define ATTRDIRLIST 0x4010      /* Include directories and drives in listbox */
  8.  
  9. /****************************************************************************/
  10. /*              Shared Variables                                            */
  11. /****************************************************************************/
  12. extern LONG lSizeOfOldFontHeader;        /* Old font header type. */
  13. extern FontHeaderType font;             /* Structure of Font File Header */
  14. extern FontHeaderType fontBuffer;       /* temp structure of font file header */
  15. CHAR szFontFileFull[FILENAMEMAX] = {"*.FNT"}; /* Name of Font File */
  16. CHAR szFontFile[FILENAMEMAX] = {"*.FNT"}; /* Name of Font File */
  17. CHAR szNewFile[FILENAMEMAX] = {"*.FNT"};  /* Name of New File */
  18. extern CHAR szFaceName[];               /* Face Name of Font */
  19. extern BOOL NewFile;                    /* flag indicating if file was opened
  20.                                            by selecting NEW on menu */
  21. extern CHAR *vrgsz[CSTRINGS];           /* string table */
  22. extern BOOL fChanged;                   /* Note if we did anything */
  23. extern INT swH;
  24. extern BYTE iChar, jChar;
  25.  
  26. extern HWND hFont;                      /* Handle to Show window */
  27. extern HWND hBox;                       /* Handle to Edit Window */
  28. extern HDC hMemDC;                      /* Handle to Memory Display Context */
  29.  
  30. extern CHAR szAppName[];
  31. extern INT iFontFormat;             /* format of font currently being edited */
  32. extern DWORD cTable;                /* offset table size */
  33. /****************************************************************************/
  34. /*              Local Variables                                             */
  35. /****************************************************************************/
  36. WORD newCharSet;                  /* Temporary value of font.CharSet */
  37. WORD newFamily;                   /* Temporary value of font.Family << 4 */
  38. BOOL newFV;     /* Temporay value of Fixed/Variable flag */
  39. WORD newItalic, newUnderline, newStrikeOut;
  40. WORD newWeight;         /* Temporary value of font.Weight */
  41. BOOL fMsgBoxUp; /* Bug Fix Hack explained in ReSizeProc */
  42. /****************************************************************************/
  43. /*              Local Functions                                             */
  44. /****************************************************************************/
  45.  
  46. VOID SetCharSet(HWND hDial);
  47. VOID SetFamily(HWND hDial);
  48. VOID SetFixed(HWND hDial, BOOL fFV);
  49. VOID SetWeight(HWND hDial);
  50.  
  51. /****************************************************************************
  52.  * BOOL  APIENTRY HeaderProc(hDial, message, wParam, lParam)
  53.  *
  54.  * purpose : Dialog function which verifies and accepts inputs which may
  55.  *           alter font's header information (font attributes)
  56.  *
  57.  * params  : Same as for all dialog functions
  58.  *
  59.  * side effects: may alter font attributes
  60.  *
  61.  ***************************************************************************/
  62. BOOL  APIENTRY 
  63. HeaderProc(
  64.     HWND   hDial,
  65.     WORD   message,
  66.     WPARAM wParam,
  67.     LPARAM lParam
  68.     )
  69. {
  70.     FontHeaderType FAR * lpFont;
  71.     BOOL fOk;               /* for GetDlgItemInt errors! */
  72.     UINT i;
  73.  
  74.     UNREFERENCED_PARAMETER(lParam);
  75.     
  76.     lpFont = (FontHeaderType FAR *)&font;
  77.     switch (message)
  78.         {
  79.     default:
  80.         return FALSE;
  81.     case WM_INITDIALOG:
  82.         newCharSet = font.CharSet;
  83.         SetCharSet(hDial);      /* Set OEM/ANSI buttons */
  84.  
  85.         newFamily = (WORD) (font.Family >> 4);   /* Working value */
  86.         SetFamily(hDial);               /* Set Font Family */
  87.  
  88.         CheckDlgButton(hDial, ID_ITALIC, newItalic = font.Italic);
  89.         CheckDlgButton(hDial, ID_UNDERLINE, newUnderline = font.Underline);
  90.         CheckDlgButton(hDial, ID_STRIKEOUT, newStrikeOut = font.StrikeOut);
  91.  
  92.         SetDlgItemInt(hDial, ID_POINTS, lpFont->Points, FALSE);
  93.         SetDlgItemInt(hDial, ID_VERT_RES, lpFont->VertRes, FALSE);
  94.         SetDlgItemInt(hDial, ID_HORIZ_RES, lpFont->HorizRes, FALSE);
  95.         SetDlgItemInt(hDial, ID_ASCENT, lpFont->Ascent, FALSE);
  96.         SetDlgItemInt(hDial, ID_EXT_LEADING, lpFont->ExtLeading, FALSE);
  97.         SetDlgItemInt(hDial, ID_INT_LEADING, lpFont->IntLeading, FALSE);
  98.         SetDlgItemInt(hDial, ID_DEFAULT_CHAR,lpFont->DefaultChar , FALSE);
  99.         SetDlgItemInt(hDial, ID_BREAK_CHAR, lpFont->BreakChar, FALSE);
  100.  
  101.         SetDlgItemText(hDial, ID_COPYRIGHT, lpFont->Copyright);
  102.         SetDlgItemText(hDial, ID_FACE_NAME, (LPSTR)szFaceName);
  103.         SetDlgItemText(hDial, ID_FONT_NAME, (LPSTR)szFontFile);
  104.         break;
  105.     case WM_COMMAND:
  106.         switch (LOWORD(wParam))
  107.             {
  108.         case ID_ANSI:
  109.             newCharSet = ANSI_CHARSET;
  110.             SetCharSet(hDial);          /* Set OEM/ANSI buttons */
  111.             break;
  112.         case ID_SYMBOL:
  113.             newCharSet = SYMBOL_CHARSET;
  114.             SetCharSet(hDial);          /* Set OEM/ANSI buttons */
  115.             break;
  116.         case ID_OEM:
  117.             newCharSet = OEM_CHARSET;
  118.             SetCharSet(hDial);          /* Set OEM/ANSI buttons */
  119.             break;
  120.         case ID_SHIFTJIS:
  121.             newCharSet = SHIFTJIS_CHARSET;
  122.             SetCharSet(hDial);        /* Set OEM/ANSI buttons */
  123.             break;
  124.         case ID_UNKNOWN:
  125.             newFamily = 0;
  126.             SetFamily(hDial);
  127.             break;
  128.         case ID_ROMAN:
  129.             newFamily = 1;
  130.             SetFamily(hDial);
  131.             break;
  132.         case ID_SWISS:
  133.             newFamily = 2;
  134.             SetFamily(hDial);
  135.             break;
  136.         case ID_MODERN:
  137.             newFamily = 3;
  138.             SetFamily(hDial);
  139.             break;
  140.         case ID_SCRIPT:
  141.             newFamily = 4;
  142.             SetFamily(hDial);
  143.             break;
  144.         case ID_DECORATIVE:
  145.             newFamily = 5;
  146.             SetFamily(hDial);
  147.             break;
  148.         case ID_ITALIC:
  149.             newItalic = (WORD) !newItalic;
  150.             CheckDlgButton(hDial, ID_ITALIC, newItalic);
  151.             break;
  152.         case ID_UNDERLINE:
  153.             newUnderline = (WORD) !newUnderline;
  154.             CheckDlgButton(hDial, ID_UNDERLINE, newUnderline);
  155.             break;
  156.         case ID_STRIKEOUT:
  157.             newStrikeOut = (WORD) !newStrikeOut;
  158.             CheckDlgButton(hDial, ID_STRIKEOUT, newStrikeOut);
  159.             break;
  160.         case ID_CHAR_SET  :
  161.             i = GetDlgItemInt(hDial, ID_CHAR_SET, (LPBOOL)&fOk, FALSE);
  162.             if (fOk && (i < 256))
  163.                 {
  164.                 font.CharSet = (BYTE) (newCharSet = (WORD) i);
  165.                 CheckDlgButton(hDial, ID_ANSI, (WORD) (i == ANSI_CHARSET));
  166.                 CheckDlgButton(hDial, ID_SYMBOL, (WORD) (i == SYMBOL_CHARSET));
  167.                 CheckDlgButton(hDial, ID_OEM, (WORD) (i == OEM_CHARSET));
  168.                 CheckDlgButton(hDial, ID_SHIFTJIS,i == SHIFTJIS_CHARSET);
  169.                 }
  170.             break;
  171.  
  172.         case IDOK:
  173.             font.CharSet = (BYTE) newCharSet;
  174.             font.Family = (BYTE) ((newFamily << 4) | (font.Family & 1));
  175.             font.Italic = (BYTE) newItalic;
  176.             font.Underline = (BYTE) newUnderline;
  177.             font.StrikeOut = (BYTE) newStrikeOut;
  178.             fChanged = TRUE;
  179.  
  180.             /* nominal point size */
  181.             i = GetDlgItemInt(hDial, ID_POINTS, (LPBOOL)&fOk, FALSE);
  182.             if (fOk)
  183.                 lpFont->Points = (WORD) i;
  184.             else{
  185.                 ErrorBox(hDial, vszNomPtSizeNotOk);
  186.                 SetFocus(GetDlgItem(hDial, ID_POINTS));
  187.                 break;
  188.                 }
  189.             /* nominal vertical resolution */
  190.             i = GetDlgItemInt(hDial, ID_VERT_RES, (LPBOOL)&fOk, FALSE);
  191.             if (fOk)
  192.                 lpFont->VertRes = (WORD) i;
  193.             else{
  194.                 ErrorBox(hDial, vszNomVertResNotOk);
  195.                 SetFocus(GetDlgItem(hDial, ID_VERT_RES));
  196.                 break;
  197.                 }
  198.             /* nominal horizontal resolution */
  199.             i = GetDlgItemInt(hDial, ID_HORIZ_RES, (LPBOOL)&fOk, FALSE);
  200.             if (fOk)
  201.                 lpFont->HorizRes = (WORD) i;
  202.             else{
  203.                 ErrorBox(hDial, vszNomHorResNotOk);
  204.                 SetFocus(GetDlgItem(hDial, ID_HORIZ_RES));
  205.                 break;
  206.                 }
  207.             /* font ascent */
  208.             i = GetDlgItemInt(hDial, ID_ASCENT, (LPBOOL)&fOk, FALSE);
  209.             if (fOk)
  210.                 {
  211.                 if (i <= font.PixHeight)
  212.                     lpFont->Ascent = (WORD) i;
  213.                 else{
  214.                     ErrorBox(hDial, vszAscentTooBig);
  215.                     SetFocus(GetDlgItem(hDial, ID_ASCENT));
  216.                     break;
  217.                     }
  218.                 }
  219.             else{
  220.                 ErrorBox(hDial, vszAscentNotOk);
  221.                 SetFocus(GetDlgItem(hDial, ID_ASCENT));
  222.                 break;
  223.                 }
  224.             /* font external leading */
  225.             i = GetDlgItemInt(hDial, ID_EXT_LEADING, (LPBOOL)&fOk, FALSE);
  226.             if (fOk)
  227.                 lpFont->ExtLeading = (WORD) i;
  228.             else{
  229.                 ErrorBox(hDial, vszExtLeadNotOk);
  230.                 SetFocus(GetDlgItem(hDial, ID_EXT_LEADING));
  231.                 break;
  232.                 }
  233.             /* font internal leading */
  234.             i = GetDlgItemInt(hDial, ID_INT_LEADING, (LPBOOL)&fOk, FALSE);
  235.             if (fOk)
  236.                 {
  237.                 if (i <= font.Ascent)
  238.                     lpFont->IntLeading = (WORD) i;
  239.                 else{
  240.                     ErrorBox(hDial, vszIntLeadTooBig);
  241.                     SetFocus(GetDlgItem(hDial, ID_INT_LEADING));
  242.                     break;
  243.                     }
  244.                 }
  245.             else{
  246.                 ErrorBox(hDial, vszIntLeadNotOk);
  247.                 SetFocus(GetDlgItem(hDial, ID_INT_LEADING));
  248.                 break;
  249.                 }
  250.             /* font character set */
  251.             i = GetDlgItemInt(hDial, ID_CHAR_SET, (LPBOOL)&fOk, FALSE);
  252.             if (fOk && i < 256)
  253.                 {
  254.                 font.CharSet = (BYTE) i;
  255.                 SetCharSet(hDial);
  256.                 }
  257.             else{
  258.                 ErrorBox(hDial, vszCharSetOutOfBounds);
  259.                 SetFocus(GetDlgItem(hDial, ID_CHAR_SET));
  260.                 break;
  261.                 }
  262.             /* font default char number */
  263.             i = GetDlgItemInt(hDial, ID_DEFAULT_CHAR, (LPBOOL)&fOk, FALSE);
  264.  
  265.             if (fOk)
  266.                 {
  267. #ifdef JAPAN // this makes no sense so it will remain langauge specific
  268.                 if (i <= (UINT)font.LastChar - (UINT)font.FirstChar)
  269. #else
  270.                 if ((i >= font.FirstChar) && (i <= font.LastChar))
  271. #endif
  272.                     lpFont->DefaultChar = (BYTE) i;
  273.                 else{
  274.                     ErrorBox(hDial, vszDefCharOutsideFont);
  275.                     SetFocus(GetDlgItem(hDial, ID_DEFAULT_CHAR));
  276.                     break;
  277.                     }
  278.                 }
  279.             else{
  280.                 ErrorBox(hDial, vszDefCharNotOk);
  281.                 SetFocus(GetDlgItem(hDial, ID_DEFAULT_CHAR));
  282.                 break;
  283.                 }
  284.             /* break char number */
  285.             i = GetDlgItemInt(hDial, ID_BREAK_CHAR, (LPBOOL)&fOk, FALSE);
  286.             if (fOk)
  287.                 {
  288.                 if ((BYTE)i <= (font.LastChar - font.FirstChar))
  289.                     lpFont->BreakChar = (BYTE) i;
  290.                 else{
  291.                     ErrorBox(hDial, vszBreakCharOutsideFont);
  292.                     SetFocus(GetDlgItem(hDial, ID_BREAK_CHAR));
  293.                     break;
  294.                     }
  295.                 }
  296.             else{
  297.                 ErrorBox(hDial, vszBreakCharNotOk);
  298.                 SetFocus(GetDlgItem(hDial, ID_BREAK_CHAR));
  299.                 break;
  300.                 }
  301.             /* facename string */
  302.             GetDlgItemText(hDial, ID_COPYRIGHT, lpFont->Copyright, 60);
  303.             GetDlgItemText(hDial, ID_FACE_NAME, (LPSTR)szFaceName, szNamesMax);
  304.             if (!lstrlen((LPSTR)szFaceName))
  305.                 {
  306.                 lstrcpy((LPSTR)szFaceName, (LPSTR)vszUnknown);
  307.                 ErrorBox(hDial, vszUnknownFace);
  308.                 }
  309.             /* fall thru to enddialog */
  310.  
  311.  
  312.         case IDCANCEL:
  313.             EndDialog(hDial, wParam != IDCANCEL);
  314.             break;
  315.  
  316.         default:
  317.             break;
  318.             }
  319.         }
  320.     return TRUE;
  321. }
  322.  
  323. /****************************************************************************
  324.  * char * VerifyHeaderContents()
  325.  *
  326.  * purpose: Checks if the Header information of the file just read makes
  327.  *          sense. If not, returns an error message string to FontLoad
  328.  *
  329.  * params : none
  330.  *
  331.  * returns :char *szError : ptr to error string if error occurs
  332.  *                          NULL otherwise
  333.  *
  334.  * side effects: none
  335.  *
  336.  ***************************************************************************/
  337. CHAR * PASCAL 
  338. VerifyHeaderContents(
  339.     VOID
  340.     )
  341. {
  342.      if (fontBuffer.Points > 999)
  343.         return vszNomPtSizeNotOk;
  344.      if (fontBuffer.VertRes > 999)
  345.         return vszNomVertResNotOk;
  346.      if (fontBuffer.HorizRes > 999)
  347.         return vszNomHorResNotOk;
  348.      if (fontBuffer.Ascent > fontBuffer.PixHeight)
  349.         return vszAscentTooBig;
  350.      if (fontBuffer.Ascent > 999)
  351.         return vszAscentNotOk;
  352.      if (fontBuffer.ExtLeading > 999)
  353.         return vszExtLeadNotOk;
  354.      if (fontBuffer.IntLeading > fontBuffer.Ascent)
  355.         return vszIntLeadTooBig;
  356.      if (fontBuffer.IntLeading > 999)
  357.         return vszIntLeadNotOk;
  358.      if (fontBuffer.LastChar > 255)
  359.         return vszCharSetOutOfBounds;
  360.      if (fontBuffer.DefaultChar > fontBuffer.FirstChar + (fontBuffer.LastChar - fontBuffer.FirstChar))
  361. #if 0
  362.           fontBuffer.DefaultChar = 0;
  363. #else
  364.         return vszDefCharOutsideFont;
  365. #endif
  366.      if (fontBuffer.DefaultChar > 255)
  367.         return vszDefCharNotOk;
  368.      if (fontBuffer.BreakChar > (fontBuffer.LastChar - fontBuffer.FirstChar))
  369.         return vszBreakCharOutsideFont;
  370.      if (fontBuffer.BreakChar > 255)
  371.         return vszBreakCharNotOk;
  372.      if (fontBuffer.PixHeight > 64) 
  373.         return vszHeightOutOfBounds;
  374.      if (fontBuffer.MaxWidth > 64)
  375.         return vszMaxWidthOutOfBounds;
  376.      if (fontBuffer.AvgWidth > 64)
  377.         return vszAvgWidthOutOfBounds;
  378.      if (iFontFormat == ID_FORMAT2)
  379.         if (fontBuffer.BitsOffset > (DWORD)SEGMENT_SIZE)
  380.             return vszBitsOffsetNotOk;
  381.      return NULL;
  382. }
  383.  
  384. /****************************************************************************
  385.  * BOOL PASCAL Format20FileTooBig(iHeight, iWidth)
  386.  *
  387.  * purpose: Checks if the 2.0 font file size is within the 64k
  388.  *          limit imposed by the 2.0 format offset table.( if file over
  389.  *          size limit is saved  in 2.0 format, loss of information will
  390.  *          result)
  391.  *
  392.  * params:  WORD iHeight : current height of font in pixels
  393.  *          WORD iWidth  : current width of font in pixels
  394.  *
  395.  * returns: TRUE  : file too large
  396.  *          FALSE : ok to save
  397.  *
  398.  * side effects: none
  399.  *
  400.  ***************************************************************************/
  401. BOOL PASCAL 
  402. Format20FileTooBig(
  403.     WORD iHeight,
  404.     WORD iWidth
  405.     )
  406. {
  407.     if ((DWORD)lSizeOfOldFontHeader + (DWORD)cTable
  408.          + (font.LastChar - font.FirstChar +1)
  409.          * (((DWORD)iHeight * (DWORD)iWidth ) >> 3) >= WORD_LIMIT)
  410.              return TRUE;
  411.     return FALSE;
  412. }
  413.  
  414. /****************************************************************************
  415.  * BOOL  APIENTRY ReSizeProc(hDial, message, wParam, lParam)
  416.  *
  417.  * purpose : dialog fn. which verifies and accepts font resize (stretch,
  418.  *           shrink...) input and calls the appropriate routine to perform
  419.  *           the function. Also alters font weight attributes (bold, light,
  420.  *           extra light...)
  421.  *
  422.  * params  : same as for all dialog functions
  423.  *
  424.  * side effects: alters header information regarding font dimensions and font
  425.  *               weight
  426.  *
  427.  ***************************************************************************/
  428. BOOL  APIENTRY 
  429. ReSizeProc(
  430.     HWND   hDial,
  431.     WORD   message,
  432.     WPARAM wParam,
  433.     LPARAM lParam 
  434.     )
  435. {
  436.     FontHeaderType FAR * lpFont;
  437.     BOOL fOk;               /* for GetDlgItemInt errors! */
  438.     UINT i;
  439.     HMENU hMenu;
  440.     static BOOL fFV; /* temporary fixed/var width flag */
  441.  
  442.     UNREFERENCED_PARAMETER(lParam);
  443.  
  444.     lpFont = (FontHeaderType FAR *)&font;
  445.     switch (message)
  446.         {
  447.     case WM_INITDIALOG:
  448.         fMsgBoxUp = FALSE;
  449.         newWeight = (WORD) font.Weight;
  450.         newFV = (BOOL) (font.Family & 1);
  451.         fFV = newFV;
  452.         SetFixed(hDial, fFV);   /* Set Fixed or Variable width */
  453.         SetDlgItemInt(hDial, ID_PIX_HEIGHT, lpFont->PixHeight, FALSE);
  454.         SetDlgItemInt(hDial, ID_FIRST_CHAR, lpFont->FirstChar, FALSE);
  455.         if (!fFV)
  456.             SetDlgItemInt(hDial, ID_WIDTH, lpFont->AvgWidth, FALSE);
  457.         else
  458.             SetDlgItemInt(hDial, ID_WIDTH, lpFont->MaxWidth, FALSE);
  459.         SetDlgItemInt(hDial, ID_AVERAGE, lpFont->AvgWidth, FALSE);
  460.         SetDlgItemInt(hDial, ID_LAST_CHAR, lpFont->LastChar, FALSE);
  461.         SetWeight(hDial);
  462.         SetFixed(hDial, fFV);
  463.         break;
  464.  
  465.     case WM_COMMAND:
  466.         switch (LOWORD(wParam))
  467.             {
  468.         case ID_THIN:
  469.             newWeight = FW_THIN;
  470.             SetWeight(hDial);
  471.             break;
  472.         case ID_EXTRALIGHT:
  473.             newWeight = FW_EXTRALIGHT;
  474.             SetWeight(hDial);
  475.             break;
  476.         case ID_LIGHT:
  477.             newWeight = FW_LIGHT;
  478.             SetWeight(hDial);
  479.             break;
  480.         case ID_NORMAL:
  481.             newWeight = FW_NORMAL;
  482.             SetWeight(hDial);
  483.             break;
  484.         case ID_MEDIUM:
  485.             newWeight = FW_MEDIUM;
  486.             SetWeight(hDial);
  487.             break;
  488.         case ID_BOLD:
  489.             newWeight = FW_BOLD;
  490.             SetWeight(hDial);
  491.             break;
  492.         case ID_SEMIBOLD:
  493.             newWeight = FW_SEMIBOLD;
  494.             SetWeight(hDial);
  495.             break;
  496.         case ID_EXTRABOLD:
  497.             newWeight = FW_EXTRABOLD;
  498.             SetWeight(hDial);
  499.             break;
  500.         case ID_HEAVY:
  501.             newWeight = FW_HEAVY;
  502.             SetWeight(hDial);
  503.             break;
  504.  
  505.         case ID_FIXED:
  506.             fFV = 0;
  507.             SetFixed(hDial, fFV);
  508.             break;
  509.         case ID_VARIABLE:
  510.             fFV = 1;
  511.             SetFixed(hDial, fFV);
  512.             break;
  513.  
  514.         case IDOK:
  515.             fChanged = TRUE;
  516.             font.Weight = newWeight;
  517.             /* give warning if user attempts to change from variable to
  518.                fixed width */
  519.             if ((fFV == 0) && (newFV != 0))
  520.                 {
  521.                 fMsgBoxUp = TRUE;
  522.                 ErrorBox(hDial, vszNoVarToFixChange);
  523.                 fMsgBoxUp = FALSE;
  524.                 SetFocus(GetDlgItem(hDial, ID_VARIABLE));
  525.                 break;
  526.                 }
  527.             else
  528.                 newFV = fFV;
  529.  
  530.             if (newFV && !(font.Family & 1))
  531.                 {
  532.                 font.PixWidth = 0;      /* All we need to do to make this */
  533.                 font.Family |= 1;       /* .. font variable width */
  534.                 }
  535.             /* change height command */
  536.             i = GetDlgItemInt(hDial, ID_PIX_HEIGHT, (LPBOOL)&fOk, FALSE);
  537.             if (fOk && i && i < kBoxLim && i>0 )
  538.                 {
  539.                     if (i != font.PixHeight){        /* Same size ? */
  540.                         /* No: Resize body height */
  541.                         if (!ResizeBody(font.WidthBytes, i)){
  542.                             SetFocus(hDial);
  543.                             break;
  544.                         }
  545.                     }
  546.                 }
  547.             else{
  548.                 ErrorBox(hDial, vszHeightOutOfBounds);
  549.                 SetFocus(GetDlgItem(hDial, ID_PIX_HEIGHT));
  550.                 break;
  551.                 }
  552.  
  553.             /* change width command */
  554.             i = GetDlgItemInt(hDial, ID_WIDTH, (LPBOOL)&fOk, FALSE);
  555.             if (fOk && i < wBoxLim && i > 0){
  556.                 int kki;
  557.                 kki = (newFV) ? font.MaxWidth : font.AvgWidth;
  558.                 if (i != (UINT)kki){
  559.                     if (newFV){
  560.                         if (!SpreadWidths(i)){
  561.                             SetFocus(hDial);
  562.                             break;      /* new variable widths */
  563.                         }
  564.                     }
  565.                     else{
  566.                         if (!ResizeWidths(i)){
  567.                             SetFocus(hDial);
  568.                             break;      /* new fixed widths */
  569.                         }
  570.                     }
  571.                 }
  572.             }
  573.             else{
  574.                 ErrorBox(hDial, vszWidthOutOfBounds);
  575.                 SetFocus(GetDlgItem(hDial, ID_WIDTH));
  576.                 break;
  577.                 }
  578.  
  579.             /* new first char command */
  580.             i = GetDlgItemInt(hDial, ID_FIRST_CHAR, (LPBOOL)&fOk, FALSE);
  581.             if (fOk)
  582.                 {
  583.                 if ((i <= font.LastChar) && (i <= font.DefaultChar))
  584.                     {
  585.                     if (i != font.FirstChar)
  586.                         {
  587.                         if (!NewFirstChar(i))
  588.                             break;
  589.                         iChar = jChar = (CHAR) i;
  590.                         swH = 0;
  591.                         ScrollFont();           /* Show front end */
  592.                         }
  593.                     }
  594.                 else{
  595.                     ErrorBox(hDial, vszChar1MoreThanDChar);
  596.                     SetFocus(GetDlgItem(hDial, ID_FIRST_CHAR));
  597.                     break;
  598.                     }
  599.                 }
  600.             else{
  601.                 ErrorBox(hDial, vszChar1NotOk);
  602.                 SetFocus(GetDlgItem(hDial, ID_FIRST_CHAR));
  603.                 break;
  604.                 }
  605.  
  606.  
  607.             /* new last char command */
  608.             i = GetDlgItemInt(hDial, ID_LAST_CHAR, (LPBOOL)&fOk, FALSE);
  609.             if (fOk && i < 256)
  610.                 {
  611.                 if ((i >= font.FirstChar) && 
  612.                     (i >= font.DefaultChar))
  613.                     {
  614.                     if (i != font.LastChar)
  615.                         {
  616.                         if (!NewLastChar(i))
  617.                             break;
  618.                         iChar = jChar = (CHAR) i;
  619.                         swH = 100;
  620.                         ScrollFont();           /* Show back end */
  621.                         }
  622.                     }
  623.                 else{
  624.                     ErrorBox(hDial, vszLastCharTooSmall);
  625.                     SetFocus(GetDlgItem(hDial, ID_LAST_CHAR));
  626.                     break;
  627.                     }
  628.                 }
  629.             else{
  630.                 ErrorBox(hDial, vszLastCharNotOk);
  631.                 SetFocus(GetDlgItem(hDial, ID_LAST_CHAR));
  632.                 break;
  633.                 }
  634.  
  635.             /* this is moved from SetFixed, since it should only be done
  636.              * if idok pressed. */
  637.             if (newFV)
  638.                 {  /* Enable "width" if variable-width font */
  639.                 hMenu = GetMenu(hBox);
  640.                 EnableMenuItem(hMenu, 4, MF_BYPOSITION | MF_ENABLED);
  641.                 DrawMenuBar(hBox);
  642.                 }
  643.  
  644.             /* fall thru to enddialog...*/
  645.  
  646.         case IDCANCEL:
  647.             EndDialog(hDial, wParam != IDCANCEL);
  648.             break;
  649.  
  650.         default:
  651.             return FALSE;
  652.             break;
  653.             }  /* end switch wParam */
  654.  
  655.     default:
  656.         return FALSE;
  657.         } /* end switch message */
  658.  
  659.     return TRUE;
  660. }
  661.  
  662. VOID
  663. ErrorBox(
  664.     HWND hWndparent,    
  665.     CHAR * szMessage
  666.     )
  667.     /* Show Message Box */
  668. {
  669.     MessageBox(hWndparent, (LPSTR)szMessage, (LPSTR)szAppName,
  670.                   MB_OK | MB_ICONASTERISK | MB_APPLMODAL);
  671. }
  672.  
  673. /****************************************************************************
  674.  * SetCharSet(hDial)
  675.  *
  676.  * purpose : Set ANSI/OEM dialog button and set the number in edit window
  677.  *
  678.  * param   : HWND hDial : handle to dialog box window
  679.  *
  680.  * returns : none
  681.  *
  682.  ***************************************************************************/
  683. VOID
  684. SetCharSet(
  685.     HWND hDial
  686.     )
  687. {
  688.     CheckDlgButton(hDial, ID_ANSI, (WORD) (newCharSet == ANSI_CHARSET));
  689.     CheckDlgButton(hDial, ID_SYMBOL, (WORD) (newCharSet == SYMBOL_CHARSET));
  690.     CheckDlgButton(hDial, ID_OEM, (WORD) (newCharSet == OEM_CHARSET));
  691.     CheckDlgButton(hDial, ID_SHIFTJIS, newCharSet == SHIFTJIS_CHARSET);
  692.     SetDlgItemInt(hDial,  ID_CHAR_SET, newCharSet, FALSE);
  693. }
  694.  
  695. /****************************************************************************
  696.  * SetFixed(hDial)
  697.  *
  698.  * purpose : Set fixed/variable dialog button
  699.  *
  700.  * params  : HWND hDial : handle to dialog box window
  701.  *           BOOL fFV   : variable or fixed
  702.  *
  703.  * returns : none
  704.  *
  705.  ***************************************************************************/
  706. VOID
  707. SetFixed(
  708.     HWND hDial,
  709.     BOOL fFV
  710.     )
  711. {
  712.     CheckDlgButton(hDial, ID_FIXED, (WORD)(fFV == 0));
  713.     CheckDlgButton(hDial, ID_VARIABLE, (WORD)(fFV == 1));
  714.     if (newFV)
  715.         SetDlgItemText(hDial, ID_WIDTH_TEXT, (LPSTR)vszMaxWidth);
  716.     else
  717.         SetDlgItemText(hDial, ID_WIDTH_TEXT, (LPSTR)vszCharPixelWidth);
  718. }
  719.  
  720. /****************************************************************************
  721.  * SetWeight(hDial)
  722.  *
  723.  * purpose : Set font weight dialog button
  724.  *
  725.  * params  : HWND hDial : handle to dialog box window
  726.  *
  727.  * returns : none
  728.  *
  729.  ****************************************************************************/
  730. VOID
  731. SetWeight(
  732.     HWND hDial
  733.     )
  734. {
  735.     CheckDlgButton(hDial, ID_THIN, (WORD)(newWeight == FW_THIN));
  736.     CheckDlgButton(hDial, ID_EXTRALIGHT, (WORD)(newWeight == FW_EXTRALIGHT));
  737.     CheckDlgButton(hDial, ID_LIGHT, (WORD)(newWeight == FW_LIGHT));
  738.     CheckDlgButton(hDial, ID_NORMAL, (WORD)(newWeight == FW_NORMAL));
  739.     CheckDlgButton(hDial, ID_MEDIUM, (WORD)(newWeight == FW_MEDIUM));
  740.     CheckDlgButton(hDial, ID_SEMIBOLD, (WORD)(newWeight == FW_SEMIBOLD));
  741.     CheckDlgButton(hDial, ID_BOLD, (WORD)(newWeight == FW_BOLD));
  742.     CheckDlgButton(hDial, ID_EXTRABOLD, (WORD)(newWeight == FW_EXTRABOLD));
  743.     CheckDlgButton(hDial, ID_HEAVY, (WORD)(newWeight == FW_HEAVY));
  744. }
  745.  
  746. /****************************************************************************
  747.  * SetFamily(hDial)
  748.  *
  749.  * purpose : Set font family dialog button
  750.  *
  751.  * params  : HWND hDial : handle to dialog box window
  752.  *
  753.  * returns : none
  754.  *
  755.  ***************************************************************************/
  756. VOID
  757. SetFamily(
  758.     HWND hDial
  759.     )
  760. {
  761.     CheckDlgButton(hDial, ID_UNKNOWN, (WORD) (newFamily == 0));
  762.     CheckDlgButton(hDial, ID_ROMAN, (WORD)(newFamily == 1));
  763.     CheckDlgButton(hDial, ID_SWISS, (WORD)(newFamily == 2));
  764.     CheckDlgButton(hDial, ID_MODERN, (WORD)(newFamily == 3));
  765.     CheckDlgButton(hDial, ID_SCRIPT, (WORD)(newFamily == 4));
  766.     CheckDlgButton(hDial, ID_DECORATIVE, (WORD) (newFamily == 5));
  767. }
  768.