home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 7.ddi / MWHC.007 / IB < prev    next >
Encoding:
Text File  |  1991-10-16  |  46.8 KB  |  1,448 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Showfont.c
  4.  
  5.     PURPOSE: Adds, deletes, creates and displays fonts
  6.  
  7.     FUNCTIONS:
  8.  
  9.         WinMain() - calls initialization function, processes message loop
  10.         EditfileInit() - initializes window data and registers window
  11.         EditfileWndProc() - processes messages
  12.         About() - processes messages for "About" dialog box
  13.         SelectFont() - select a font
  14.         GetSizes() - get size of current font
  15.         GetFonts() - get available fonts
  16.         SetMyDC() - initializes DC
  17.         Metric() - Metric dialog box
  18.         Log() - Log dialog box
  19.         AddDlg() - dialog box for adding a font
  20.         RemoveDlg() - dialog box for removing a font
  21.         CFontDlg()
  22.         _lstrcpy() - long strcpy()
  23.         _lstrncpy() - long strncpy()
  24.         _lstrlen()  - long strlen()
  25.         CheckFileName() - check for valid filename
  26.         SeparateFile() - Separate filename and pathname
  27.         UpdateListBox() - update file list box
  28.         AddExt() - add default extension
  29.         SetFaceName() - update title with current font's face name
  30.  
  31. ****************************************************************************/
  32.  
  33. #include <stdio.h>
  34. #include <string.h>
  35. #include "windows.h"
  36. #include "showfont.h"
  37.  
  38. HANDLE hInst;
  39.  
  40. HFONT hOFont, hFFont, hVFont, hSFont, hDFont, hMFont, hFont;
  41. int hFile;
  42. char line[4][64];
  43. char FontNameList[32][128];                          /* list of added fonts  */
  44. int nFontIndex = 0;                                  /* position in FontList */
  45. int nLineSpace;
  46.  
  47. TEXTMETRIC TextMetric;
  48. LOGFONT LogFont;
  49. FARPROC lpCFontDlg;
  50. POINT ptCurrent = {0, 0};
  51. short nBkMode = OPAQUE;
  52. DWORD rgbBkColor = RGB(255, 255, 255);
  53. DWORD rgbTextColor = RGB(0, 0, 0);
  54. DWORD rgbColor;
  55. short nAlignLCR = TA_LEFT;
  56. short nAlignTBB = TA_TOP; 
  57. WORD wPaint = 0;
  58. FARPROC lpColors;
  59. char FontList[MAXFONT][32];
  60. BYTE CharSet[MAXFONT];
  61. BYTE PitchAndFamily[MAXFONT];
  62. int FontIndex = 0;
  63. int SizeList[MAXSIZE];
  64. int SizeIndex = 0;
  65. int CurrentFont = 0;
  66. int CurrentSize = 0;
  67. FARPROC lpSelectFont;
  68. FARPROC lpEnumFunc;
  69. WORD wPrevVAlign = IDM_ALIGNBASE;
  70. WORD wPrevHAlign = IDM_ALIGNLEFT;
  71. WORD wPrevFont = IDM_SYSTEM;
  72. char AppName[] = "ShowFont Sample Application   Font: ";
  73. char WindowTitle[80];
  74. char str[255];
  75. char DefPath[128];
  76. char DefExt[] = ".fon";
  77. char DefSpec[13];
  78. char FontFileName[128];
  79.  
  80. /****************************************************************************
  81.  
  82.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  83.  
  84.     PURPOSE: calls initialization function, processes message loop
  85.  
  86. ****************************************************************************/
  87.  
  88. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  89. HANDLE hInstance;
  90. HANDLE hPrevInstance;
  91. LPSTR lpCmdLine;
  92. int nCmdShow;
  93. {
  94.     HWND hWnd;
  95.     MSG msg;
  96.  
  97.     if (!hPrevInstance)
  98.         if (!ShowFontInit(hInstance))
  99.             return (FALSE);
  100.  
  101.     hInst = hInstance;
  102.  
  103.     strcpy(WindowTitle, AppName);
  104.     strcat(WindowTitle, "SYSTEM");                 /* default is SYSTEM font */
  105.  
  106.     hWnd = CreateWindow("ShowFont",
  107.         WindowTitle,
  108.         WS_OVERLAPPEDWINDOW,
  109.         CW_USEDEFAULT,
  110.         CW_USEDEFAULT,
  111.         CW_USEDEFAULT,
  112.         CW_USEDEFAULT,
  113.         NULL,
  114.         NULL,
  115.         hInstance,
  116.         NULL);
  117.  
  118.     if (!hWnd)
  119.         return (FALSE);
  120.  
  121.     ShowWindow(hWnd, nCmdShow);
  122.     UpdateWindow(hWnd);
  123.  
  124.     while (GetMessage(&msg, NULL, NULL, NULL)) {
  125.         TranslateMessage(&msg);
  126.         DispatchMessage(&msg);
  127.     }
  128.     return (msg.wParam);
  129. }
  130.  
  131. /****************************************************************************
  132.  
  133.     FUNCTION: ShowFontInit(HANDLE)
  134.  
  135.     PURPOSE: Initializes window data and registers window class
  136.  
  137. ****************************************************************************/
  138.  
  139. int ShowFontInit(hInstance)
  140. HANDLE hInstance;
  141. {
  142.     PWNDCLASS pWndClass;
  143.     WNDCLASS ww;
  144.     BOOL bSuccess;
  145.  
  146.     pWndClass = &ww;
  147.     memset(pWndClass, 0, sizeof ww);
  148.     pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
  149.     pWndClass->hIcon = LoadIcon(NULL, IDI_APPLICATION);
  150.     pWndClass->lpszMenuName = "ShowFont";
  151.     pWndClass->lpszClassName = "ShowFont";
  152.     pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
  153.     pWndClass->hInstance = hInstance;
  154.     pWndClass->style = NULL;
  155.     pWndClass->lpfnWndProc = ShowFontWndProc;
  156.  
  157.     bSuccess = RegisterClass((LPWNDCLASS) pWndClass);
  158.     return (bSuccess);
  159. }
  160.  
  161. /****************************************************************************
  162.  
  163.     FUNCTION: SetMyDC(HDC)
  164.  
  165.     PURPOSE: Initializes the DC
  166.  
  167. ****************************************************************************/
  168.  
  169. void SetMyDC(hDC) 
  170. HDC hDC;
  171. {
  172.     SetBkMode(hDC, nBkMode);
  173.     SetBkColor(hDC, rgbBkColor);
  174.     SetTextColor(hDC, rgbTextColor);
  175.     SetTextAlign(hDC, nAlignLCR | nAlignTBB);
  176. }
  177.  
  178. /****************************************************************************
  179.  
  180.     FUNCTION: GetStringExtent(HDC, PSTR, HFONT)
  181.  
  182.     PURPOSE: get the string extent
  183.  
  184. ****************************************************************************/
  185.  
  186. short GetStringExtent(hDC, pString, hFont)
  187. HDC hDC;
  188. PSTR pString;
  189. HFONT hFont;
  190. {
  191.     HFONT hOldFont;
  192.     DWORD dwExtent;
  193.  
  194.     if ((hOldFont=SelectObject(hDC, hFont)) != 0) {
  195.         dwExtent = GetTextExtent(hDC, pString, strlen(pString));
  196.         SelectObject(hDC, hOldFont);
  197.         return (LOWORD(dwExtent));
  198.     }
  199.     else
  200.         return (0);
  201. }
  202.  
  203. /****************************************************************************
  204.  
  205.     FUNCTION: GetStringExtent(HDC, PSTR, HFONT)
  206.  
  207.     PURPOSE: Sends string to application's window
  208.  
  209. ****************************************************************************/
  210.  
  211. short StringOut(hDC, X, Y, pString, hFont)
  212. HDC hDC;
  213. short X;
  214. short Y;
  215. PSTR pString;
  216. HFONT hFont;
  217. {
  218.     HFONT hOldFont;
  219.     DWORD dwExtent=0;
  220.  
  221.     hOldFont = SelectObject(hDC, hFont);
  222.     if (hOldFont != NULL) {
  223.         dwExtent = GetTextExtent(hDC, pString, strlen(pString));
  224.         TextOut(hDC, X, Y, pString, strlen(pString));
  225.         SelectObject(hDC, hOldFont);
  226.     }
  227.     return (LOWORD(dwExtent));
  228. }
  229.  
  230. /****************************************************************************
  231.  
  232.     FUNCTION: ShowString(HWND)
  233.  
  234.     PURPOSE: Show string in current font
  235.  
  236. ****************************************************************************/
  237.  
  238. void ShowString(hWnd)
  239. HWND hWnd;
  240. {
  241.     HFONT hItalicFont;
  242.     HFONT hBoldFont;
  243.     HFONT hUnderlineFont;
  244.     HFONT hStrikeOutFont;
  245.     HDC hDC;
  246.     short X, tmpX;
  247.     short Y;
  248.     short nAlign;
  249.  
  250.     GetObject(hFont, sizeof(LOGFONT), (LPSTR) &LogFont);
  251.     LogFont.lfItalic = TRUE;
  252.     hItalicFont = CreateFontIndirect(&LogFont);
  253.     LogFont.lfItalic = FALSE;
  254.     LogFont.lfUnderline = TRUE;
  255.     hUnderlineFont = CreateFontIndirect(&LogFont);
  256.     LogFont.lfUnderline = FALSE;
  257.     LogFont.lfStrikeOut = TRUE;
  258.     hStrikeOutFont = CreateFontIndirect(&LogFont);
  259.     LogFont.lfStrikeOut = FALSE;
  260.     LogFont.lfWeight = FW_BOLD;
  261.     hBoldFont = CreateFontIndirect(&LogFont);
  262.  
  263.     hDC=GetDC(hWnd);
  264.     SetMyDC(hDC);
  265.     X=ptCurrent.x;
  266.     Y=ptCurrent.y;
  267.     nAlign =  nAlignLCR | nAlignTBB;                   /* GetTextAlign(hDC); */
  268.     if ((nAlign & TA_CENTER) == TA_CENTER) {
  269.         tmpX = X;
  270.         nAlignLCR = TA_LEFT;
  271.         SetTextAlign(hDC, nAlignLCR | nAlignTBB);
  272.         X += StringOut(hDC, X, Y, ", and ", hFont);
  273.         X += StringOut(hDC, X, Y, "strikeout", hStrikeOutFont);
  274.         X += StringOut(hDC, X, Y, " in a single line.", hFont);
  275.         X = tmpX;
  276.         nAlignLCR = TA_RIGHT;
  277.         SetTextAlign(hDC, nAlignLCR | nAlignTBB);
  278.         X -= StringOut(hDC, X, Y, "underline", hUnderlineFont);
  279.         X -= StringOut(hDC, X, Y, ", ", hFont);
  280.         X -= StringOut(hDC, X, Y, "italic", hItalicFont);
  281.         X -= StringOut(hDC, X, Y, ", ", hFont);
  282.         X -= StringOut(hDC, X, Y, "bold", hBoldFont);
  283.         X -= StringOut(hDC, X, Y, "You can use ", hFont);
  284.         nAlignLCR = TA_CENTER;
  285.     }
  286.     else if ((nAlign & TA_CENTER) == TA_RIGHT) {
  287.         X -= StringOut(hDC, X, Y, " in a single line.", hFont);
  288.         X -= StringOut(hDC, X, Y, "strikeout", hStrikeOutFont);
  289.         X -= StringOut(hDC, X, Y, ", and ", hFont);
  290.         X -= StringOut(hDC, X, Y, "underline", hUnderlineFont);
  291.         X -= StringOut(hDC, X, Y, ", ", hFont);
  292.         X -= StringOut(hDC, X, Y, "italic", hItalicFont);
  293.         X -= StringOut(hDC, X, Y, ", ", hFont);
  294.         X -= StringOut(hDC, X, Y, "bold", hBoldFont);
  295.         X -= StringOut(hDC, X, Y, "You can use ", hFont);
  296.     }
  297.     else  {
  298.         X += StringOut(hDC, X, Y, "You can use ", hFont);
  299.         X += StringOut(hDC, X, Y, "bold", hBoldFont);
  300.         X += StringOut(hDC, X, Y, ", ", hFont);
  301.         X += StringOut(hDC, X, Y, "italic", hItalicFont);
  302.         X += StringOut(hDC, X, Y, ", ", hFont);
  303.         X += StringOut(hDC, X, Y, "underline", hUnderlineFont);
  304.         X += StringOut(hDC, X, Y, ", and ", hFont);
  305.         X += StringOut(hDC, X, Y, "strikeout", hStrikeOutFont);
  306.         X += StringOut(hDC, X, Y, " in a single line.", hFont);
  307.     }
  308.  
  309.     ReleaseDC(hWnd, hDC);
  310.     DeleteObject(hItalicFont);
  311.     DeleteObject(hUnderlineFont);
  312.     DeleteObject(hStrikeOutFont);
  313.     DeleteObject(hBoldFont);
  314. }
  315.  
  316. /****************************************************************************
  317.  
  318.     FUNCTION: ShowCharacterSet(HDC, HFONT)
  319.  
  320.     PURPOSE: display character set using current font
  321.  
  322. ****************************************************************************/
  323.  
  324. void ShowCharacterSet(hDC, hFont)
  325. HDC hDC;
  326. HFONT hFont;
  327. {
  328.     HFONT hOldFont;
  329.     TEXTMETRIC TextMetric;
  330.     short X;
  331.     short Y;
  332.  
  333.     if ((hOldFont = SelectObject(hDC, hFont)) == 0)
  334.         return;
  335.     GetTextMetrics(hDC, &TextMetric);
  336.     nLineSpace = (TextMetric.tmHeight + TextMetric.tmExternalLeading)*2;
  337.     X = ptCurrent.x;
  338.     Y = ptCurrent.y;
  339.     TextOut(hDC, X, Y, line[0], 64);
  340.     TextOut(hDC, X, Y += nLineSpace, line[1], 64);
  341.     TextOut(hDC, X, Y += nLineSpace, line[2], 64);
  342.     TextOut(hDC, X, Y += nLineSpace, line[3], 64);
  343.     SelectObject(hDC, hOldFont);
  344. }
  345.  
  346. /****************************************************************************
  347.  
  348.     FUNCTION: ShowLogFont(HWND, HFONT)
  349.  
  350.     PURPOSE: Create dialog box to show information about logical font
  351.  
  352. ****************************************************************************/
  353.  
  354. void ShowLogFont(hWnd, hFont)
  355. HWND hWnd;
  356. HFONT hFont;
  357. {
  358.     HFONT hOldFont;
  359.     FARPROC lpProcLog;
  360.     HDC hDC;
  361.     TEXTMETRIC TextMetric;
  362.     HANDLE hDlgBox;
  363.     char DialogTitle[100];
  364.  
  365.     hDC = GetDC(hWnd);
  366.     if ((hOldFont = SelectObject(hDC, hSFont)) == 0)
  367.         return;
  368.     GetTextMetrics(hDC, &TextMetric);
  369.     nLineSpace = TextMetric.tmHeight + TextMetric.tmExternalLeading;
  370.     GetObject(hFont, sizeof(LOGFONT), (LPSTR) &LogFont);
  371.  
  372.     lpProcLog = MakeProcInstance((FARPROC) Log, hInst);
  373.     hDlgBox = CreateDialog(hInst, "LogBox", hWnd, lpProcLog);
  374.  
  375.     strcpy(DialogTitle, "Log Font: ");
  376.     strcat(DialogTitle, LogFont.lfFaceName);
  377.     SetWindowText(hDlgBox, (LPSTR) DialogTitle);
  378.  
  379.     SelectObject(hDC, hOldFont);
  380.     ReleaseDC(hWnd, hDC);
  381. }
  382.  
  383. /****************************************************************************
  384.  
  385.     FUNCTION: ShowMetricFont(HWND, HFONT)
  386.  
  387.     PURPOSE: Create dialog box to show information about metric font
  388.  
  389. ****************************************************************************/
  390.  
  391. void ShowTextMetric(hWnd, hFont)
  392. HWND hWnd;
  393. HFONT hFont;
  394. {
  395.     FARPROC lpProcMetric;
  396.     HFONT hOldFont;
  397.     HDC hDC;
  398.     HANDLE hDlgBox;
  399.     char buf[80];
  400.     char DialogTitle[100];
  401.  
  402.     hDC = GetDC(hWnd);
  403.     if ((hOldFont = SelectObject(hDC, hFont)) == 0)
  404.         return;
  405.     GetTextMetrics(hDC, &TextMetric);
  406.  
  407.     lpProcMetric = MakeProcInstance((FARPROC) Metric, hInst);
  408.     hDlgBox = CreateDialog(hInst, "MetricBox", hWnd, lpProcMetric);
  409.  
  410.     strcpy(DialogTitle, "Metric Font: ");
  411.     GetTextFace(hDC, 80, buf);
  412.     strcat(DialogTitle, buf);
  413.     SetWindowText(hDlgBox, (LPSTR) DialogTitle);
  414.  
  415.     SelectObject(hDC, hOldFont);
  416.     ReleaseDC(hWnd, hDC);
  417. }
  418.  
  419. /****************************************************************************
  420.  
  421.     FUNCTION: Colors(HWND, unsigned, WORD LONG)
  422.  
  423.     PURPOSE: Dialog box for changing background color of text
  424.  
  425. ****************************************************************************/
  426.  
  427. BOOL FAR PASCAL Colors(hDlg, message, wParam, lParam)
  428. HWND hDlg;
  429. unsigned message;
  430. WORD wParam;
  431. LONG lParam;
  432. {
  433.     int Red, Green, Blue;
  434.  
  435.     switch (message) {
  436.         case WM_INITDIALOG:
  437.             SetDlgItemInt(hDlg, ID_RED, GetRValue(rgbColor), FALSE);
  438.             SetDlgItemInt(hDlg, ID_GREEN, GetGValue(rgbColor), FALSE);
  439.             SetDlgItemInt(hDlg, ID_BLUE, GetBValue(rgbColor), FALSE);
  440.             return (TRUE);
  441.  
  442.         case WM_COMMAND:
  443.             switch (wParam) {
  444.                 case IDOK:
  445.                     Red = GetDlgItemInt(hDlg, ID_RED, NULL, FALSE);
  446.                     Green = GetDlgItemInt(hDlg, ID_GREEN, NULL, FALSE);
  447.                     Blue = GetDlgItemInt(hDlg, ID_BLUE, NULL, FALSE);
  448.                     rgbColor = RGB(Red, Green, Blue);
  449.                     EndDialog(hDlg, 1);
  450.                     break;
  451.  
  452.                 case IDCANCEL:
  453.                     EndDialog(hDlg, 0);
  454.                     break;
  455.             }
  456.             break;
  457.     }
  458.     return (FALSE);
  459. }
  460.  
  461. /****************************************************************************
  462.  
  463.     FUNCTION: EnumFunc(LPLOGFONT, LPTEXTMETRIC, short, LPSTR)
  464.  
  465.     PURPOSE: Initializes window data and registers window class
  466.  
  467. ****************************************************************************/
  468.  
  469. int FAR PASCAL EnumFunc(lpLogFont, lpTextMetric, FontType, lpData)
  470. LPLOGFONT lpLogFont;
  471. LPTEXTMETRIC lpTextMetric;
  472. short FontType;
  473. LPSTR lpData;
  474. {
  475.     switch (LOWORD(lpData)) {
  476.         case 0:
  477.             if (FontIndex >= MAXFONT)
  478.                 return (0);
  479.             _lstrcpy((LPSTR) FontList[FontIndex],
  480.                 (LPSTR) (lpLogFont->lfFaceName));
  481.             CharSet[FontIndex] = lpLogFont->lfCharSet;
  482.             PitchAndFamily[FontIndex] = lpLogFont->lfPitchAndFamily;
  483.             return (++FontIndex);
  484.  
  485.         case 1:
  486.             if (SizeIndex >= MAXSIZE)
  487.                 return (0);
  488.             SizeList[SizeIndex] = lpLogFont->lfHeight;
  489.             return (++SizeIndex);
  490.     }
  491. }
  492.  
  493. /****************************************************************************
  494.  
  495.     FUNCTION: GetFonts(HWND)
  496.  
  497.     PURPOSE: Get available fonts
  498.  
  499. ****************************************************************************/
  500.  
  501. void GetFonts(hWnd)
  502. HWND hWnd;
  503. {
  504.     HDC hDC;
  505.  
  506.     FontIndex = 0;
  507.     SizeIndex = 0;
  508.     hDC = GetDC(hWnd);
  509.     lpEnumFunc = MakeProcInstance(EnumFunc, hInst);
  510.     EnumFonts(hDC, (LPSTR) NULL, lpEnumFunc, (LPSTR) NULL); 
  511.     FreeProcInstance(lpEnumFunc);
  512.     ReleaseDC(hWnd, hDC);
  513. }
  514.  
  515. /****************************************************************************
  516.  
  517.     FUNCTION: GetSizes(hWnd, CurrentFont)
  518.  
  519.     PURPOSE: Get size of current font
  520.  
  521. ****************************************************************************/
  522.  
  523. void GetSizes(hWnd, CurrentFont)
  524. HWND hWnd;
  525. int CurrentFont;
  526. {
  527.     HDC hDC;
  528.  
  529.     SizeIndex = 0;
  530.     hDC = GetDC(hWnd);
  531.     lpEnumFunc = MakeProcInstance(EnumFunc, hInst);
  532.     EnumFonts(hDC, FontList[CurrentFont], lpEnumFunc, MAKEINTRESOURCE(1));
  533.     FreeProcInstance(lpEnumFunc);
  534.     ReleaseDC(hWnd, hDC);
  535. }
  536.  
  537.  
  538. /****************************************************************************
  539.  
  540.     FUNCTION: SelectFont(HWND, unsigned, WORD, LONG)
  541.  
  542.     PURPOSE: Initializes window data and registers window class
  543.  
  544. ****************************************************************************/
  545.  
  546. BOOL FAR PASCAL SelectFont(hDlg, message, wParam, lParam)
  547. HWND hDlg;
  548. unsigned message;
  549. WORD wParam;
  550. LONG lParam;
  551. {
  552.  
  553.     int i;
  554.     int index;
  555.     char buf[LF_FACESIZE];
  556.  
  557.     switch (message) {
  558.         case WM_INITDIALOG:
  559.             for (i=0; i<FontIndex; i++) {        /* displays available fonts */
  560.                 SendDlgItemMessage(hDlg, ID_TYPEFACE, LB_ADDSTRING,
  561.                     NULL, (LONG) FontList[i]);
  562.                 SendDlgItemMessage(hDlg, ID_TYPEFACE, LB_SETCURSEL,
  563.                     0, 0L);
  564.             }
  565.             GetSizes(hDlg, 0);
  566.             for (i=0; i<SizeIndex; i++) {        /* displays font sizes      */
  567.                 sprintf(buf, "%d", SizeList[i]);
  568.                 SendDlgItemMessage(hDlg, ID_SIZE, LB_ADDSTRING,
  569.                     0, (LONG) buf);
  570.                 SendDlgItemMessage(hDlg, ID_SIZE, LB_SETCURSEL,
  571.                     0, 0L);
  572.             }
  573.             return (TRUE);
  574.  
  575.         case WM_COMMAND:
  576.             switch (wParam) {
  577.                 case IDOK:
  578. okay:
  579.                     index=SendDlgItemMessage(hDlg, ID_TYPEFACE,
  580.                         LB_GETCURSEL, 0, 0L);
  581.                     if (index == LB_ERR) {
  582.                         MessageBox(hDlg, "No font selected",
  583.                             "Select Font", MB_OK | MB_ICONEXCLAMATION);
  584.                     break;
  585.             }
  586.             CurrentFont = index;
  587.             index = SendDlgItemMessage(hDlg, ID_SIZE,
  588.                 LB_GETCURSEL, 0, 0L);
  589.             if (index == LB_ERR) {
  590.                 MessageBox(hDlg, "No size selected",
  591.                     "Select Font", MB_OK | MB_ICONEXCLAMATION);
  592.                 break;
  593.             }
  594.             CurrentSize = index;
  595.             EndDialog(hDlg, 1);
  596.             break;
  597.  
  598.         case IDCANCEL:
  599.             EndDialog(hDlg, 0);
  600.             break;
  601.  
  602.         case ID_TYPEFACE:
  603.             switch (HIWORD(lParam)) {
  604.                 case LBN_SELCHANGE:
  605.                     index = SendDlgItemMessage(hDlg, ID_TYPEFACE,
  606.                         LB_GETCURSEL, 0, 0L);
  607.                     if (index == LB_ERR)
  608.                         break;
  609.                     SendDlgItemMessage(hDlg, ID_SIZE, LB_RESETCONTENT, 0, 0L);
  610.                     GetSizes(hDlg, index);
  611.                     for (i = 0; i < SizeIndex; i++) {
  612.                         sprintf(buf, "%d", SizeList[i]);
  613.                         SendDlgItemMessage(hDlg, ID_SIZE,
  614.                             LB_ADDSTRING, 0, (LONG) buf);
  615.                         SendDlgItemMessage(hDlg, ID_SIZE, LB_SETCURSEL, 0, 0L);
  616.             }
  617.             break;
  618.  
  619.                 case LBN_DBLCLK:
  620.                 goto okay;
  621.             }
  622.             break;
  623.  
  624.         case ID_SIZE:
  625.             if(HIWORD(lParam) == LBN_DBLCLK)
  626.                 goto okay;
  627.             break;
  628.         }
  629.         break;
  630.     }
  631.     return (FALSE);
  632. }
  633.  
  634. /****************************************************************************
  635.  
  636.     FUNCTION: ShowFontWndProc(HWND, WORD, WORD, LONG)
  637.  
  638.     PURPOSE: Processes messages
  639.  
  640. ****************************************************************************/
  641.  
  642. long FAR PASCAL ShowFontWndProc(hWnd, message, wParam, lParam)
  643. HWND hWnd;
  644. WORD message;
  645. WORD wParam;
  646. LONG lParam;
  647. {
  648.     FARPROC lpProcAbout, lpAddDlg, lpRemoveDlg;
  649.     HDC hDC;
  650.     PAINTSTRUCT ps;
  651.     int i;
  652.  
  653.     switch(message) {
  654.         case WM_CREATE:
  655.             GetFonts(hWnd);
  656.             hMFont = CreateFont(
  657.                 10,                                      /* height           */
  658.                 10,                                      /* width            */
  659.                 0,                                       /* escapement       */
  660.                 0,                                       /* orientation      */
  661.                 FW_NORMAL,                               /* weight           */
  662.                 FALSE,                                   /* italic           */
  663.                 FALSE,                                   /* underline        */
  664.                 FALSE,                                   /* strikeout        */
  665.                 OEM_CHARSET,                             /* charset          */
  666.                 OUT_DEFAULT_PRECIS,                      /* out precision    */
  667.                 CLIP_DEFAULT_PRECIS,                     /* clip precision   */
  668.                 DEFAULT_QUALITY,                         /* quality          */
  669.                 FIXED_PITCH | FF_MODERN,                 /* pitch and family */
  670.                 "Courier");                              /* typeface         */
  671.             hOFont = GetStockObject(OEM_FIXED_FONT);
  672.             hFFont = GetStockObject(ANSI_FIXED_FONT);
  673.             hVFont = GetStockObject(ANSI_VAR_FONT);
  674.             hSFont = GetStockObject(SYSTEM_FONT);
  675.             hDFont = GetStockObject(DEVICE_DEFAULT_FONT);
  676.             hFont = hSFont;
  677.             GetObject(hFont, sizeof(LOGFONT), (LPSTR) &LogFont);
  678.             strcpy(WindowTitle, AppName);
  679.             strcat(WindowTitle, "SYSTEM");
  680.             SetWindowText(hWnd, (LPSTR) WindowTitle);
  681.  
  682.             for (i=0; i<64; i++) {
  683.                 line[0][i] = i;
  684.                 line[1][i] = i+64;
  685.                 line[2][i] = i+128;
  686.                 line[3][i] = i+192;
  687.             }
  688.             break;
  689.  
  690.         case WM_PAINT:
  691.             hDC = BeginPaint(hWnd, &ps);
  692.             SetMyDC(hDC);
  693.             switch (wPaint) {
  694.                 case IDM_SHOWCHARSET:
  695.                 ShowCharacterSet(hDC, hFont);
  696.                 break;
  697.             }
  698.             EndPaint(hWnd, &ps);
  699.             break;
  700.  
  701.         case WM_COMMAND:
  702.             switch (wParam) {
  703.  
  704.                 /* File menu */
  705.  
  706.                 case IDM_ADDFONT:
  707.  
  708.                     /* Call AddDlg() to get the filename */
  709.  
  710.                     lpAddDlg = MakeProcInstance((FARPROC) AddDlg, hInst);
  711.                     if (DialogBox(hInst, "Add", hWnd, lpAddDlg)) {
  712.  
  713.                         /* Check to see if it is a new font name */
  714.  
  715.                         for (i = 0; i < nFontIndex; i++) {
  716.                             if (!strcmp(FontFileName, &FontNameList[i][0])) {
  717.                                 MessageBox(hWnd, "Font already exists",
  718.                                     "Add Font", MB_OK | MB_ICONQUESTION);
  719.                                 FreeProcInstance(lpAddDlg);
  720.                                 return (0L);
  721.                             }
  722.                         }
  723.  
  724.                         /* Tell Windows to add the font resource */
  725.  
  726.                         AddFontResource((LPSTR) FontFileName);
  727.  
  728.                         /* Let all applications know there is a new font
  729.                          * resource
  730.                          */
  731.  
  732.                         SendMessage((HWND) 0xFFFF, WM_FONTCHANGE, NULL,
  733.                             (LONG) NULL);
  734.  
  735.                         /* Copy the name selected to the list of fonts added */
  736.  
  737.                         strcpy(&FontNameList[nFontIndex++][0], FontFileName);
  738.                     }
  739.  
  740.                     FreeProcInstance(lpAddDlg);
  741.                     break;
  742.  
  743.                 case IDM_DELFONT:
  744.                     if (!nFontIndex) {
  745.                         MessageBox(hWnd, "No fonts to delete",
  746.                             "Remove Font", MB_OK | MB_ICONQUESTION);
  747.                         break;
  748.                     }
  749.  
  750.                     lpRemoveDlg = MakeProcInstance((FARPROC) RemoveDlg, hInst);
  751.                     if (DialogBox(hInst, "Remove", hWnd, lpRemoveDlg)) {
  752.                         for (i = 0; i < nFontIndex; i++) {
  753.                             if (!strcmp(FontFileName, &FontNameList[i][0])) {
  754.                                 RemoveFontResource((LPSTR) FontFileName);
  755.                                 SendMessage((HWND) 0xFFFF, WM_FONTCHANGE, NULL,
  756.                                     (LONG) NULL);
  757.                                 strcpy(&FontNameList[i][0],
  758.                                     &FontNameList[--nFontIndex][0]);
  759.                                 break;
  760.                             }
  761.                         }
  762.                     }
  763.                     FreeProcInstance(lpRemoveDlg);
  764.                     break;
  765.  
  766.                 case IDM_EXIT:
  767.                     DestroyWindow(hWnd);
  768.                     break;
  769.  
  770.                 case IDM_ABOUT:
  771.                     lpProcAbout = MakeProcInstance((FARPROC) About, hInst);
  772.                     DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  773.                     FreeProcInstance(lpProcAbout);
  774.                     break;
  775.  
  776.                 /* Show menu */
  777.  
  778.                 case IDM_SHOWSTRING:
  779.                     ShowString(hWnd);
  780.                     break;
  781.  
  782.                 case IDM_SHOWCHARSET:
  783.                     InvalidateRect(hWnd, (LPRECT)NULL, TRUE);
  784.                     wPaint = wParam;
  785.                     break;
  786.  
  787.                 case IDM_SHOWLOGFONT:
  788.                     ShowLogFont(hWnd, hFont);
  789.                     break;
  790.  
  791.                 case IDM_SHOWTEXTMETRICS:
  792.                     ShowTextMetric(hWnd, hFont);
  793.                     break;
  794.  
  795.                 case IDM_CLEAR:
  796.                     InvalidateRect(hWnd, (LPRECT)NULL, TRUE);
  797.                     wPaint = 0;
  798.                     break;
  799.  
  800.                 /* Font menu */
  801.  
  802.                 case IDM_OEM:
  803.                     hFont = hOFont;
  804.                     SetFaceName(hWnd);                  /* sets window title */
  805.                     CheckMenuItem(GetMenu(hWnd), wPrevFont, MF_UNCHECKED);
  806.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  807.                     wPrevFont = wParam;
  808.                     break;
  809.  
  810.                 case IDM_ANSIFIXED:
  811.                     hFont = hFFont;
  812.                     SetFaceName(hWnd);
  813.                     CheckMenuItem(GetMenu(hWnd), wPrevFont, MF_UNCHECKED);
  814.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  815.                     wPrevFont = wParam;
  816.                     break;
  817.  
  818.                 case IDM_ANSIVAR:
  819.                     hFont = hVFont;
  820.                     SetFaceName(hWnd);
  821.                     CheckMenuItem(GetMenu(hWnd), wPrevFont, MF_UNCHECKED);
  822.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  823.                     wPrevFont = wParam;
  824.                     break;
  825.  
  826.                 case IDM_SYSTEM:
  827.                     hFont = hSFont;
  828.                     SetFaceName(hWnd);
  829.                     CheckMenuItem(GetMenu(hWnd), wPrevFont, MF_UNCHECKED);
  830.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  831.                     wPrevFont = wParam;
  832.                     break;
  833.  
  834.                 case IDM_DEVICEDEF:
  835.                     hFont = hDFont;
  836.                     SetFaceName(hWnd);
  837.                     CheckMenuItem(GetMenu(hWnd), wPrevFont, MF_UNCHECKED);
  838.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  839.                     wPrevFont = wParam;
  840.                     break;
  841.  
  842.                 case IDM_SELECTFONT:
  843.                     lpSelectFont = MakeProcInstance(SelectFont, hInst);
  844.                     if (DialogBox(hInst, "SelectFont", hWnd, lpSelectFont)) {
  845.                         DeleteObject(hMFont);
  846.                         hMFont = CreateFont(
  847.                             SizeList[CurrentSize],
  848.                             0,
  849.                             0,
  850.                             0,
  851.                             FW_NORMAL,
  852.                             FALSE,
  853.                             FALSE,
  854.                             FALSE,
  855.                             CharSet[CurrentFont],
  856.                             OUT_DEFAULT_PRECIS,
  857.                             CLIP_DEFAULT_PRECIS,
  858.                             DEFAULT_QUALITY,
  859.                             PitchAndFamily[CurrentFont],
  860.                             FontList[CurrentFont]);
  861.                         hFont = hMFont;
  862.                         SetFaceName(hWnd);
  863.                     }
  864.                     FreeProcInstance(lpSelectFont);
  865.                     break;
  866.  
  867.                 case IDM_CFONT:
  868.                     lpCFontDlg = MakeProcInstance(CFontDlg, hInst);
  869.                     GetObject(hMFont, sizeof(LOGFONT), (LPSTR) &CLogFont);
  870.                     if (DialogBox(hInst, "CFont", hWnd, lpCFontDlg)) {
  871.                         DeleteObject(hMFont);
  872.                         hMFont = CreateFontIndirect(&CLogFont);
  873.                         hFont = hMFont;
  874.                         SetFaceName(hWnd);
  875.                     }
  876.                     FreeProcInstance(lpCFontDlg);
  877.                     break;
  878.  
  879.                 /* Options menu */
  880.  
  881.                 case IDM_TEXTCOLOR:
  882.                     lpColors = MakeProcInstance(Colors, hInst);
  883.                     rgbColor = rgbTextColor;
  884.                     if (DialogBox(hInst, "Colors", hWnd, lpColors))
  885.                         rgbTextColor = rgbColor;
  886.                     FreeProcInstance(lpColors);
  887.                     break;
  888.  
  889.                 case IDM_BACKGROUNDCOLOR:
  890.                     lpColors = MakeProcInstance(Colors, hInst);
  891.                     rgbColor = rgbBkColor;
  892.                     if (DialogBox(hInst, "Colors", hWnd, lpColors))
  893.                         rgbBkColor = rgbColor;
  894.                     FreeProcInstance(lpColors);
  895.                     break;
  896.  
  897.                 case IDM_OPAQUE:
  898.                     nBkMode = OPAQUE;
  899.                     CheckMenuItem(GetMenu(hWnd), IDM_TRANSPARENT, MF_UNCHECKED);
  900.                     CheckMenuItem(GetMenu(hWnd), IDM_OPAQUE, MF_CHECKED);
  901.                     break;
  902.  
  903.                 case IDM_TRANSPARENT:
  904.                     nBkMode = TRANSPARENT;
  905.                     CheckMenuItem(GetMenu(hWnd), IDM_OPAQUE,  MF_UNCHECKED);
  906.                     CheckMenuItem(GetMenu(hWnd), IDM_TRANSPARENT,  MF_CHECKED);
  907.                     break;
  908.  
  909.                 case IDM_ALIGNLEFT:
  910.                     nAlignLCR = TA_LEFT;
  911.                     CheckMenuItem(GetMenu(hWnd), wPrevHAlign, MF_UNCHECKED);
  912.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  913.                     wPrevHAlign = wParam;
  914.                     break;
  915.  
  916.                 case IDM_ALIGNCENTER:
  917.                     nAlignLCR = TA_CENTER;
  918.                     CheckMenuItem(GetMenu(hWnd), wPrevHAlign, MF_UNCHECKED);
  919.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  920.                     wPrevHAlign = wParam;
  921.                     break;
  922.  
  923.                 case IDM_ALIGNRIGHT:
  924.                     nAlignLCR = TA_RIGHT;
  925.                     CheckMenuItem(GetMenu(hWnd), wPrevHAlign, MF_UNCHECKED);
  926.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  927.                     wPrevHAlign = wParam;
  928.                     break;
  929.  
  930.                 case IDM_ALIGNTOP:
  931.                     nAlignTBB = TA_TOP;
  932.                     CheckMenuItem(GetMenu(hWnd), wPrevVAlign, MF_UNCHECKED);
  933.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  934.                     wPrevVAlign = wParam;
  935.                     break;
  936.  
  937.                 case IDM_ALIGNBASE:
  938.                     nAlignTBB = TA_BASELINE;
  939.                     CheckMenuItem(GetMenu(hWnd), wPrevVAlign, MF_UNCHECKED);
  940.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  941.                     wPrevVAlign = wParam;
  942.                     break;
  943.  
  944.                 case IDM_ALIGNBOTTOM:
  945.                     nAlignTBB = TA_BOTTOM;
  946.                     CheckMenuItem(GetMenu(hWnd), wPrevVAlign, MF_UNCHECKED);
  947.                     CheckMenuItem(GetMenu(hWnd), wParam, MF_CHECKED);
  948.                     wPrevVAlign = wParam;
  949.                     break;
  950.             }
  951.             break;
  952.  
  953.         case WM_LBUTTONUP:
  954.             ptCurrent.x = LOWORD(lParam);
  955.             ptCurrent.y = HIWORD(lParam);
  956.             ShowString(hWnd);
  957.             break;
  958.  
  959.         case WM_FONTCHANGE:
  960.             GetFonts(hWnd);
  961.             break;
  962.  
  963.         case WM_DESTROY:
  964.             /* Remove any fonts that were added */
  965.             for (i = 0; i < nFontIndex; i++)
  966.                 RemoveFontResource((LPSTR) &FontNameList[i][0]);
  967.  
  968.             /* Notify any other applications know the fonts have been deleted */
  969.  
  970.             SendMessage((HWND) 0xFFFF, WM_FONTCHANGE, NULL, (LONG) NULL);
  971.             PostQuitMessage(0);
  972.             break;
  973.  
  974.         default:
  975.             return (DefWindowProc(hWnd, message, wParam, lParam));
  976.     }
  977.     return (0L);
  978. }
  979.  
  980. /****************************************************************************
  981.  
  982.     FUNCTION: Metric(HWND, unsigned, WORD, LONG)
  983.  
  984.     PURPOSE: Modeless dialog box to display metric font information
  985.  
  986. ****************************************************************************/
  987.  
  988. BOOL FAR PASCAL Metric(hDlg, message, wParam, lParam)
  989. HWND hDlg;
  990. unsigned message;
  991. WORD wParam;
  992. LONG lParam;
  993. {
  994.     switch (message) {
  995.         case WM_INITDIALOG:
  996.             SetDlgItemInt(hDlg, IDMB_HEIGHT, TextMetric.tmHeight, FALSE);
  997.             SetDlgItemInt(hDlg, IDMB_ASCENT, TextMetric.tmAscent, FALSE);
  998.             SetDlgItemInt(hDlg, IDMB_DESCENT, TextMetric.tmDescent, FALSE);
  999.             SetDlgItemInt(hDlg, IDMB_INTERNALLEADING,
  1000.                 TextMetric.tmInternalLeading, FALSE);
  1001.             SetDlgItemInt(hDlg, IDMB_EXTERNALLEADING,
  1002.                 TextMetric.tmExternalLeading, FALSE);
  1003.             SetDlgItemInt(hDlg, IDMB_AVECHARWIDTH, TextMetric.tmAveCharWidth,
  1004.                 FALSE);
  1005.             SetDlgItemInt(hDlg, IDMB_MAXCHARWIDTH, TextMetric.tmMaxCharWidth,
  1006.                 FALSE);
  1007.             SetDlgItemInt(hDlg, IDMB_WEIGHT, TextMetric.tmWeight, FALSE);
  1008.             SetDlgItemInt(hDlg, IDMB_ITALIC, TextMetric.tmItalic, FALSE);
  1009.             SetDlgItemInt(hDlg, IDMB_UNDERLINED, TextMetric.tmUnderlined,
  1010.                 FALSE);
  1011.             SetDlgItemInt(hDlg, IDMB_STRUCKOUT, TextMetric.tmStruckOut, FALSE);
  1012.             SetDlgItemInt(hDlg, IDMB_FIRSTCHAR, TextMetric.tmFirstChar, FALSE);
  1013.             SetDlgItemInt(hDlg, IDMB_LASTCHAR, TextMetric.tmLastChar, FALSE);
  1014.             SetDlgItemInt(hDlg, IDMB_DEFAULTCHAR, TextMetric.tmDefaultChar,
  1015.                 FALSE);
  1016.             SetDlgItemInt(hDlg, IDMB_BREAKCHAR, TextMetric.tmBreakChar, FALSE);
  1017.             SetDlgItemInt(hDlg, IDMB_PITCHANDFAMILY,
  1018.                 TextMetric.tmPitchAndFamily, FALSE);
  1019.             SetDlgItemInt(hDlg, IDMB_CHARSET, TextMetric.tmCharSet, FALSE);
  1020.             SetDlgItemInt(hDlg, IDMB_OVERHANG, TextMetric.tmOverhang, FALSE);
  1021.             SetDlgItemInt(hDlg, IDMB_DIGITIZEDASPECTX,
  1022.                 TextMetric.tmDigitizedAspectX, FALSE);
  1023.             SetDlgItemInt(hDlg, IDMB_DIGITIZEDASPECTY,
  1024.                 TextMetric.tmDigitizedAspectY, FALSE);
  1025.             return (TRUE);
  1026.  
  1027.         case WM_CLOSE:
  1028.             DestroyWindow(hDlg);
  1029.             break;
  1030.     }
  1031.     return (FALSE);
  1032. }
  1033.  
  1034. /****************************************************************************
  1035.  
  1036.     FUNCTION: Log(HWND, unsigned, WORD, LONG)
  1037.  
  1038.     PURPOSE: Displays logical font information
  1039.  
  1040. ****************************************************************************/
  1041.  
  1042. BOOL FAR PASCAL Log(hDlg, message, wParam, lParam)
  1043. HWND hDlg;
  1044. unsigned message;
  1045. WORD wParam;
  1046. LONG lParam;
  1047. {
  1048.  
  1049.     switch (message) {
  1050.         case WM_INITDIALOG:
  1051.             SetDlgItemInt(hDlg, IDMI_HEIGHT, LogFont.lfHeight, FALSE);
  1052.             SetDlgItemInt(hDlg, IDMI_WIDTH, LogFont.lfWidth, FALSE);
  1053.             SetDlgItemInt(hDlg, IDMI_ESCAPEMENT, LogFont.lfEscapement, FALSE);
  1054.             SetDlgItemInt(hDlg, IDMI_ORIENTATION, LogFont.lfOrientation, FALSE);
  1055.             SetDlgItemInt(hDlg, IDMI_WEIGHT, LogFont.lfWeight, FALSE);
  1056.             SetDlgItemInt(hDlg, IDMI_ITALIC, LogFont.lfItalic, FALSE);
  1057.             SetDlgItemInt(hDlg, IDMI_UNDERLINED, LogFont.lfUnderline, FALSE);
  1058.             SetDlgItemInt(hDlg, IDMI_STRIKEOUT, LogFont.lfStrikeOut, FALSE);
  1059.             SetDlgItemInt(hDlg, IDMI_CHARSET, LogFont.lfCharSet, FALSE);
  1060.             SetDlgItemInt(hDlg, IDMI_OUTPRECISION, LogFont.lfOutPrecision,
  1061.                 FALSE);
  1062.             SetDlgItemInt(hDlg, IDMI_CLIPPRECISION, LogFont.lfClipPrecision,
  1063.                 FALSE);
  1064.             SetDlgItemInt(hDlg, IDMI_QUALITY, LogFont.lfQuality, FALSE);
  1065.             SetDlgItemInt(hDlg, IDMI_PITCHANDFAMILY,
  1066.                 LogFont.lfPitchAndFamily, FALSE);
  1067.             return (TRUE);
  1068.  
  1069.         case WM_CLOSE:
  1070.             DestroyWindow(hDlg);
  1071.             break;
  1072.  
  1073.     }
  1074.     return (FALSE);
  1075. }
  1076.  
  1077. /****************************************************************************
  1078.  
  1079.     FUNCTION: AddDlg(HWND, unsigned, WORD, LONG)
  1080.  
  1081.     PURPOSE: Used to add a font
  1082.  
  1083.     COMMENTS:
  1084.  
  1085.         This dialog box displays all the availble font files on the currently
  1086.         selected directory, and lets the user select a font to add.
  1087.  
  1088. ****************************************************************************/
  1089.  
  1090. BOOL FAR PASCAL AddDlg(hDlg, message, wParam, lParam)
  1091. HWND hDlg;
  1092. unsigned message;
  1093. WORD wParam;
  1094. LONG lParam;
  1095. {
  1096.     switch (message) {
  1097.         case WM_COMMAND:
  1098.             switch (wParam) {
  1099.                 case ID_LISTBOX:
  1100.  
  1101.                     switch (HIWORD(lParam)) {
  1102.                         case LBN_SELCHANGE:
  1103.                             /* If item is a directory name, append "*.*" */
  1104.                             if (DlgDirSelect(hDlg, str, ID_LISTBOX)) 
  1105.                                 strcat(str, DefSpec);
  1106.  
  1107.                             SetDlgItemText(hDlg, ID_EDIT, str);
  1108.                             SendDlgItemMessage(hDlg,
  1109.                                 ID_EDIT,
  1110.                                 EM_SETSEL,
  1111.                                 NULL,
  1112.                                 MAKELONG(0, 0x7fff));
  1113.                             break;
  1114.  
  1115.                         case LBN_DBLCLK:
  1116.                             goto CheckSelection;
  1117.  
  1118.                     }                              /* end of ID_LISTBOX case */
  1119.                     return (TRUE);
  1120.  
  1121.                 case IDOK:
  1122. CheckSelection:
  1123.                     /* Get the filename from the edit control */
  1124.  
  1125.                     GetDlgItemText(hDlg, ID_EDIT, str, 128);
  1126.                     GetDlgItemText(hDlg, ID_PATH, DefPath, 128);
  1127.  
  1128.                     /* Check for wildcard.  If found, use the string as a new
  1129.                      * search path.
  1130.                      */
  1131.  
  1132.                     if (strchr(str, '*') ||
  1133.                         strchr(str, '?')) {
  1134.  
  1135.                     /* Separate filename from path.  The path is stored in
  1136.                      * str which is discarded if null, else it is used for a new
  1137.                      * search path.
  1138.                      */
  1139.  
  1140.                         SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
  1141.                             (LPSTR) str);
  1142.                         if (str[0])
  1143.                             strcpy(DefPath, str);
  1144.  
  1145.                         UpdateListBox(hDlg);
  1146.                         return (TRUE);
  1147.                     }
  1148.  
  1149.                     /* Ignore it if no filename specified */
  1150.  
  1151.                     if (!str[0]) {
  1152.                         MessageBox(hDlg, "No filename specified.",
  1153.                             NULL, MB_OK | MB_ICONQUESTION);
  1154.                         return (TRUE);
  1155.                     }
  1156.  
  1157.                     /* Append the default extension if needed */
  1158.  
  1159.                     strcpy(FontFileName, DefPath);
  1160.                     strcat(FontFileName, str);
  1161.                     AddExt(FontFileName, DefExt);
  1162.                     EndDialog(hDlg, TRUE);
  1163.                     return (TRUE);
  1164.  
  1165.                 case IDCANCEL:
  1166.  
  1167.                     /* Let the caller know the user cancelled */
  1168.  
  1169.                     EndDialog(hDlg, FALSE);
  1170.                     return (TRUE);
  1171.             }
  1172.             break;
  1173.  
  1174.         case WM_INITDIALOG:
  1175.             SetWindowText(hDlg, (LPSTR) "Add Font Resource");
  1176.             strcpy(DefSpec, "*.fon");
  1177.             UpdateListBox(hDlg);
  1178.             SetDlgItemText(hDlg, ID_EDIT, DefSpec);
  1179.             SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL, NULL,
  1180.                 MAKELONG(0, 0x7fff));
  1181.             SetFocus(GetDlgItem(hDlg, ID_EDIT));
  1182.             return (FALSE);
  1183.     }
  1184.     return FALSE;
  1185. }
  1186.  
  1187. /****************************************************************************
  1188.  
  1189.     FUNCTION: RemoveDlg(HANDLE)
  1190.  
  1191.     PURPOSE: Used to remove a font
  1192.  
  1193.     COMMENTS:
  1194.  
  1195.         This dialog box displays all fonts which have been added to the system,
  1196.         and lets the user select which font to delete.
  1197.  
  1198. ****************************************************************************/
  1199.  
  1200. BOOL FAR PASCAL RemoveDlg(hDlg, message, wParam, lParam)
  1201. HWND hDlg;
  1202. unsigned message;
  1203. WORD wParam;
  1204. LONG lParam;
  1205. {
  1206.     WORD index;
  1207.     int i;
  1208.  
  1209.     switch (message) {
  1210.         case WM_COMMAND:
  1211.  
  1212.             switch (wParam) {
  1213.                 case ID_LISTBOX:
  1214.  
  1215.                     switch (HIWORD(lParam)) {
  1216.                         case LBN_SELCHANGE:
  1217.                             index = SendDlgItemMessage(hDlg,
  1218.                                 ID_LISTBOX,
  1219.                                 LB_GETCURSEL,         /* get index command   */
  1220.                                 NULL,
  1221.                                 (LONG) NULL);
  1222.                             SendDlgItemMessage(hDlg,
  1223.                                 ID_LISTBOX,
  1224.                                 LB_GETTEXT,           /* copy string command */
  1225.                                 index,
  1226.                                 (LONG) FontFileName);
  1227.                             SetDlgItemText(hDlg, ID_EDIT, FontFileName);
  1228.                             break;
  1229.  
  1230.                         case LBN_DBLCLK:
  1231.                             GetDlgItemText(hDlg, ID_EDIT, FontFileName, 128);
  1232.                             EndDialog(hDlg, TRUE);
  1233.                             return (TRUE);
  1234.                     }
  1235.                     return (TRUE);
  1236.  
  1237.                 case IDOK:
  1238.  
  1239.                     /* Get the filename from the edit control */
  1240.  
  1241.                     GetDlgItemText(hDlg, ID_EDIT, FontFileName, 128);
  1242.  
  1243.                     /* Ignore it if no filename specified */
  1244.  
  1245.                     if (!FontFileName[0]) {
  1246.                         MessageBox(hDlg, "No filename specified.",
  1247.                             NULL, MB_OK | MB_ICONQUESTION);
  1248.                         return (TRUE);
  1249.                     }
  1250.  
  1251.                     EndDialog(hDlg, TRUE);
  1252.                     return (TRUE);
  1253.  
  1254.                 case IDCANCEL:
  1255.                     EndDialog(hDlg, FALSE);
  1256.                     return (TRUE);
  1257.             }
  1258.             break;
  1259.  
  1260.         case WM_INITDIALOG:
  1261.             SetWindowText(hDlg, (LPSTR) "Remove Font Resource");
  1262.             for (i = 0; i < nFontIndex; i++)
  1263.                 SendDlgItemMessage(hDlg,
  1264.                     ID_LISTBOX,
  1265.                     LB_ADDSTRING,
  1266.                     NULL,
  1267.                     (LONG)(char far *) &FontNameList[i][0]);
  1268.  
  1269.             SetFocus(GetDlgItem(hDlg, ID_EDIT));
  1270.             return (FALSE);
  1271.     }
  1272.     return FALSE;
  1273. }
  1274.  
  1275. /****************************************************************************
  1276.  
  1277.     FUNCTION: UpdateListBox(HWND);
  1278.  
  1279.     PURPOSE: Update the list box of OpenDlg
  1280.  
  1281. ****************************************************************************/
  1282.  
  1283. void UpdateListBox(hDlg)
  1284. HWND hDlg;
  1285. {
  1286.     strcpy(str, DefPath);
  1287.     strcat(str, DefSpec);
  1288.     DlgDirList(hDlg, str, ID_LISTBOX, ID_PATH, 0x4010);
  1289.     SetDlgItemText(hDlg, ID_EDIT, DefSpec);
  1290. }
  1291.  
  1292. /****************************************************************************
  1293.  
  1294.     FUNCTION: AddExt(PSTR, PSTR);
  1295.  
  1296.     PURPOSE: Add default extension
  1297.  
  1298. ****************************************************************************/
  1299.  
  1300. void AddExt(Name, Ext)
  1301. PSTR Name, Ext;
  1302. {
  1303.     PSTR pTptr;
  1304.  
  1305.     pTptr = Name;
  1306.     while (*pTptr && *pTptr != '.')
  1307.         pTptr++;
  1308.     if (*pTptr != '.')
  1309.         strcat(Name, Ext);
  1310. }
  1311.  
  1312. /****************************************************************************
  1313.  
  1314.     FUNCTION: SeparateFile(HWND, LPSTR, LPSTR, LPSTR)
  1315.  
  1316.     PURPOSE: Separate filename and pathname
  1317.  
  1318.     COMMENTS:
  1319.  
  1320.         This function takes a source filespec and splits it into a path and a
  1321.         filename, and copies these into the strings specified.  Because it
  1322.         uses the AnsiPrev call, it will work in any language.
  1323.  
  1324. ****************************************************************************/
  1325.  
  1326. void SeparateFile(hDlg, lpDestPath, lpDestFileName, lpSrcFileName)
  1327. HWND hDlg;
  1328. LPSTR lpDestPath, lpDestFileName, lpSrcFileName;
  1329. {
  1330.     LPSTR lpTmp;
  1331.  
  1332.     lpTmp = lpSrcFileName + (long) _lstrlen(lpSrcFileName);
  1333.     while (*lpTmp != ':' && *lpTmp != '\\' && lpTmp > lpSrcFileName)
  1334.         lpTmp = AnsiPrev(lpSrcFileName, lpTmp);
  1335.     if (*lpTmp != ':' && *lpTmp != '\\') {                  /* no path given */
  1336.         _lstrcpy(lpDestFileName, lpSrcFileName);
  1337.         lpDestPath[0] = 0;
  1338.         return;
  1339.     }
  1340.     _lstrcpy(lpDestFileName, lpTmp + 1L);
  1341.     _lstrncpy(lpDestPath, lpSrcFileName, (int) (lpTmp - lpSrcFileName) + 1);
  1342.     lpDestPath[(lpTmp - lpSrcFileName) + 1] = 0;
  1343. }
  1344.  
  1345. /****************************************************************************
  1346.  
  1347.     FUNCTION: _lstrlen(LPSTR)
  1348.  
  1349.     PURPOSE:  uses a long far pointer to the string, returns the length
  1350.  
  1351. ****************************************************************************/
  1352.  
  1353. int _lstrlen(lpStr)
  1354. LPSTR lpStr;
  1355. {
  1356.     int i;
  1357.     for (i=0; *lpStr++; i++);
  1358.     return (i);
  1359. }
  1360.  
  1361. /****************************************************************************
  1362.  
  1363.     FUNCTION: _lstrncpy(LPSTR, LPSTR)
  1364.  
  1365.     PURPOSE:  FAR version of strncpy()
  1366.  
  1367. ****************************************************************************/
  1368.  
  1369. void _lstrncpy(lpDest, lpSrc, n)
  1370. LPSTR lpDest, lpSrc;
  1371. int n;
  1372. {
  1373.     while (n--)
  1374.         if((*lpDest++ = *lpSrc++) == 0)
  1375.             return;
  1376. }
  1377.  
  1378. /****************************************************************************
  1379.  
  1380.     FUNCTION: _lstrcpy(LPSTR, LPSTR)
  1381.  
  1382.     PURPOSE:  FAR version of strcpy()
  1383.  
  1384. ****************************************************************************/
  1385.  
  1386. void _lstrcpy(lpDest, lpSrc)
  1387. LPSTR lpDest, lpSrc;
  1388. {
  1389.     while((*lpDest++ = *lpSrc++) != 0) ;
  1390. }
  1391.  
  1392. /****************************************************************************
  1393.  
  1394.     FUNCTION: SetFaceName(HWND)
  1395.  
  1396.     PURPOSE: Retireves current font's face name, places it in WindowTitle
  1397.  
  1398. ****************************************************************************/
  1399.  
  1400. SetFaceName(hWnd)
  1401. HWND hWnd;
  1402. {
  1403.     char buf[80];
  1404.     HDC hDC;
  1405.  
  1406.     hDC = GetDC(hWnd);
  1407.     SelectObject(hDC, hFont);
  1408.     strcpy(WindowTitle, AppName);
  1409.     GetTextFace(hDC, 80, buf);
  1410.     strcat(WindowTitle, buf);
  1411.     SetWindowText(hWnd, (LPSTR) WindowTitle);
  1412.  
  1413.     ReleaseDC(hWnd, hDC);
  1414. }
  1415.  
  1416. /****************************************************************************
  1417.  
  1418.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  1419.  
  1420.     PURPOSE:  Processes messages for "About" dialog box
  1421.  
  1422.     MESSAGES:
  1423.  
  1424.         WM_INITDIALOG - initialize dialog box
  1425.         WM_COMMAND    - Input received
  1426.  
  1427. ****************************************************************************/
  1428.  
  1429. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  1430. HWND hDlg;
  1431. unsigned message;
  1432. WORD wParam;
  1433. LONG lParam;
  1434. {
  1435.     switch (message) {
  1436.         case WM_INITDIALOG:
  1437.             return (TRUE);
  1438.  
  1439.         case WM_COMMAND:
  1440.             if (wParam == IDOK) {
  1441.                 EndDialog(hDlg, TRUE);
  1442.                 return (TRUE);
  1443.             }
  1444.             return (TRUE);
  1445.     }
  1446.     return (FALSE);
  1447. }
  1448.