home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VOL12N03.ZIP / BITFO2.ZIP / BITFONT2.C next >
C/C++ Source or Header  |  1992-10-30  |  5KB  |  157 lines

  1. /*------------------------------------------
  2.    BITFONTS.C -- Displays OS/2 Bitmap Fonts
  3.                  (c) Charles Petzold, 1993
  4.   ------------------------------------------*/
  5.  
  6. #define INCL_WIN
  7. #define INCL_GPI
  8. #include <os2.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include "bitfont2.h"
  12. #include "bmf.h"
  13.  
  14. #define LCID_FONT   1
  15.  
  16. MRESULT EXPENTRY ClientWndProc (HWND, ULONG, MPARAM, MPARAM) ;
  17.  
  18. int main (void)
  19.      {
  20.      static CHAR  szClientClass [] = "BitFont2" ;
  21.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
  22.                                  FCF_SIZEBORDER    | FCF_MINMAX   |
  23.                                  FCF_SHELLPOSITION | FCF_TASKLIST |
  24.                                  FCF_MENU ;
  25.      HAB          hab ;
  26.      HMQ          hmq ;
  27.      HWND         hwndFrame, hwndClient ;
  28.      QMSG         qmsg ;
  29.  
  30.      hab = WinInitialize (0) ;
  31.      hmq = WinCreateMsgQueue (hab, 0) ;
  32.  
  33.      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
  34.  
  35.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  36.                                      &flFrameFlags, szClientClass,
  37.                                      "Bitmap Fonts", 0L,
  38.                                      NULLHANDLE, ID_RESOURCE, &hwndClient) ;
  39.  
  40.      while (WinGetMsg (hab, &qmsg, NULLHANDLE, 0, 0))
  41.           WinDispatchMsg (hab, &qmsg) ;
  42.  
  43.      WinDestroyWindow (hwndFrame) ;
  44.      WinDestroyMsgQueue (hmq) ;
  45.      WinTerminate (hab) ;
  46.      return 0 ;
  47.      }
  48.  
  49. MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  50.      {
  51.      static BOOL  fItalic, fUnder, fStrike, fBold ;
  52.      static HWND  hwndMenu ;
  53.      static SHORT cyClient ;
  54.      CHAR         szBuffer [FACESIZE + 32] ;
  55.      FONTMETRICS  fm ;
  56.      HPS          hps ;
  57.      int          iFace, iSize ;
  58.      PFONTLIST    pfl ;
  59.      POINTL       ptl ;
  60.  
  61.      switch (msg)
  62.       {
  63.           case WM_CREATE:
  64.                hwndMenu = WinWindowFromID (WinQueryWindow (hwnd, QW_PARENT),
  65.                                            FID_MENU) ;
  66.                return 0 ;
  67.  
  68.           case WM_SIZE:
  69.                cyClient = HIUSHORT (mp2) ;
  70.                return 0 ;
  71.  
  72.           case WM_COMMAND:
  73.                switch (COMMANDMSG(&msg)->cmd)
  74.                     {
  75.                     case IDM_ITALIC:      fItalic   = ! fItalic   ;  break ;
  76.                     case IDM_UNDERSCORE:  fUnder    = ! fUnder    ;  break ;
  77.                     case IDM_STRIKEOUT:   fStrike   = ! fStrike   ;  break ;
  78.                     case IDM_BOLD:        fBold     = ! fBold     ;  break ;
  79.  
  80.                     default:  return 0 ;
  81.                     }
  82.  
  83.                WinCheckMenuItem (hwndMenu, COMMANDMSG(&msg)->cmd,
  84.                     ! WinIsMenuItemChecked (hwndMenu, COMMANDMSG(&msg)->cmd)) ;
  85.  
  86.                WinInvalidateRect (hwnd, NULL, TRUE) ;
  87.                return 0 ;
  88.  
  89.           case WM_PAINT:
  90.                hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;
  91.  
  92.                GpiErase (hps) ;
  93.  
  94.                     // Get the font list
  95.  
  96.                pfl = GetAllBitmapFonts (hps) ;
  97.  
  98.                     // Set POINTL structure to upper left corner of client
  99.  
  100.                ptl.x = 0 ;
  101.                ptl.y = cyClient ;
  102.  
  103.                     // Loop through all the bitmap fonts
  104.  
  105.                for (iFace = 0 ; iFace < pfl->iNumFaces              ; iFace ++)
  106.                for (iSize = 0 ; iSize < pfl->faces[iFace].iNumSizes ; iSize ++)
  107.                     {
  108.                          // Create the logical font and select it
  109.  
  110.                     CreateBitmapFont (hps, LCID_FONT,
  111.                                    pfl->faces[iFace].szFacename,
  112.                                    pfl->faces[iFace].psizes[iSize].iPointSize,
  113.                                    (fItalic  ? FATTR_SEL_ITALIC     : 0) |
  114.                                    (fUnder   ? FATTR_SEL_UNDERSCORE : 0) |
  115.                                    (fStrike  ? FATTR_SEL_STRIKEOUT  : 0) |
  116.                                    (fBold    ? FATTR_SEL_BOLD       : 0),
  117.                                    0) ;
  118.  
  119.                     GpiSetCharSet (hps, LCID_FONT) ;
  120.  
  121.                          // Query the font metrics of the current font
  122.  
  123.                     GpiQueryFontMetrics (hps, sizeof (FONTMETRICS), &fm) ;
  124.  
  125.                          // Set up a text string to display
  126.  
  127.                     sprintf (szBuffer, "%s - %d points",
  128.                              pfl->faces[iFace].szFacename,
  129.                              pfl->faces[iFace].psizes[iSize].iPointSize) ;
  130.  
  131.                          // Drop POINTL structure to baseline of font
  132.  
  133.                     ptl.y -= fm.lMaxAscender ;
  134.  
  135.                          // Display the character string
  136.  
  137.                     GpiCharStringAt (hps, &ptl, strlen (szBuffer), szBuffer) ;
  138.  
  139.                          // Drop POINTL structure down to bottom of text
  140.  
  141.                     ptl.y -= fm.lMaxDescender ;
  142.  
  143.                          // Select the default font; delete the logical font
  144.  
  145.                     GpiSetCharSet (hps, LCID_DEFAULT) ;
  146.                     GpiDeleteSetId (hps, LCID_FONT) ;
  147.                     }
  148.  
  149.                WinEndPaint (hps) ;
  150.                return 0 ;
  151.  
  152.           case WM_DESTROY:
  153.                return 0 ;
  154.           }
  155.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  156.      }
  157.