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