home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / progwin / chap11 / devcaps.c next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  9.2 KB  |  208 lines

  1. /*---------------------------------------------------------
  2.    DEVCAPS.C -- Display routines for DEVCAPS1 and DEVCAPS2
  3.                 (c) Charles Petzold, 1990
  4.   ---------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <string.h>
  8. #include <stdio.h>
  9.  
  10. typedef struct
  11.      {
  12.      short nMask ;
  13.      char  *szMask ;
  14.      char  *szDesc ;
  15.      }
  16.      BITS ;
  17.  
  18. void DoBasicInfo (HDC hdc, HDC hdcInfo, short cxChar, short cyChar)
  19.      {
  20.      static struct
  21.           {
  22.           short nIndex ;
  23.           char  *szDesc ;
  24.           }
  25.           info [] =
  26.           {
  27.           HORZSIZE,      "HORZSIZE     Width in millimeters:",
  28.           VERTSIZE,      "VERTSIZE     Height in millimeters:",
  29.           HORZRES,       "HORZRES      Width in pixels:",
  30.           VERTRES,       "VERTRES      Height in raster lines:",
  31.           BITSPIXEL,     "BITSPIXEL    Color bits per pixel:",
  32.           PLANES,        "PLANES       Number of color planes:",
  33.           NUMBRUSHES,    "NUMBRUSHES   Number of device brushes:",
  34.           NUMPENS,       "NUMPENS      Number of device pens:",
  35.           NUMMARKERS,    "NUMMARKERS   Number of device markers:",
  36.           NUMFONTS,      "NUMFONTS     Number of device fonts:",
  37.           NUMCOLORS,     "NUMCOLORS    Number of device colors:",
  38.           PDEVICESIZE,   "PDEVICESIZE  Size of device structure:",
  39.           ASPECTX,       "ASPECTX      Relative width of pixel:",
  40.           ASPECTY,       "ASPECTY      Relative height of pixel:",
  41.           ASPECTXY,      "ASPECTXY     Relative diagonal of pixel:",
  42.           LOGPIXELSX,    "LOGPIXELSX   Horizontal dots per inch:",
  43.           LOGPIXELSY,    "LOGPIXELSY   Vertical dots per inch:",
  44.           SIZEPALETTE,   "SIZEPALETTE  Number of palette entries:",
  45.           NUMRESERVED,   "NUMRESERVED  Reserved palette entries:",
  46.           COLORRES,      "COLORRES     Actual color resolution:"
  47.           } ;
  48.      char   szBuffer [80] ;
  49.      short  i, nLine ;
  50.  
  51.      for (i = 0 ; i < sizeof info / sizeof info [0] ; i++)
  52.           TextOut (hdc, cxChar, (i + 1) * cyChar, szBuffer,
  53.                sprintf (szBuffer, "%-40s%8d", info[i].szDesc,
  54.                     GetDeviceCaps (hdcInfo, info[i].nIndex))) ;
  55.      }
  56.  
  57. void DoOtherInfo (HDC hdc, HDC hdcInfo, short cxChar, short cyChar)
  58.      {
  59.      static BITS clip [] =
  60.           {
  61.           CP_RECTANGLE,  "CP_RECTANGLE",     "Can Clip To Rectangle:"
  62.           } ; 
  63.  
  64.      static BITS raster [] =
  65.           {
  66.           RC_BITBLT,       "RC_BITBLT",       "Capable of simple BitBlt:",
  67.           RC_BANDING,      "RC_BANDING",      "Requires banding support:",
  68.           RC_SCALING,      "RC_SCALING",      "Requires scaling support:",
  69.           RC_BITMAP64,     "RC_BITMAP64",     "Supports bitmaps >64K:",
  70.           RC_GDI20_OUTPUT, "RC_GDI20_OUTPUT", "Has 2.0 output calls:",
  71.           RC_DI_BITMAP,    "RC_DI_BITMAP",    "Supports DIB to memory:",
  72.           RC_PALETTE,      "RC_PALETTE",      "Supports a palette:",
  73.           RC_DIBTODEV,     "RC_DIBTODEV",     "Supports bitmap conversion:",
  74.           RC_BIGFONT,      "RC_BIGFONT",      "Supports fonts >64K:",
  75.           RC_STRETCHBLT,   "RC_STRETCHBLT",   "Supports StretchBlt:",
  76.           RC_FLOODFILL,    "RC_FLOODFILL",    "Supports FloodFill:"
  77.           } ;
  78.  
  79.      static char *szTech [] = { "DT_PLOTTER (Vector plotter)",
  80.                                 "DT_RASDISPLAY (Raster display)",
  81.                                 "DT_RASPRINTER (Raster printer)",
  82.                                 "DT_RASCAMERA (Raster camera)",
  83.                                 "DT_CHARSTREAM (Character-stream, PLP)",
  84.                                 "DT_METAFILE (Metafile, VDM)",
  85.                                 "DT_DISPFILE (Display-file)" } ;
  86.      char        szBuffer [80] ;
  87.      short       i ;
  88.  
  89.      TextOut (hdc, cxChar, cyChar, szBuffer,
  90.           sprintf (szBuffer, "%-24s%04XH",
  91.                "DRIVERVERSION:", GetDeviceCaps (hdcInfo, DRIVERVERSION))) ;
  92.  
  93.      TextOut (hdc, cxChar, 2 * cyChar, szBuffer,
  94.           sprintf (szBuffer, "%-24s%-40s",
  95.                "TECHNOLOGY:", szTech [GetDeviceCaps (hdcInfo, TECHNOLOGY)])) ;
  96.  
  97.      TextOut (hdc, cxChar, 4 * cyChar, szBuffer,
  98.           sprintf (szBuffer, "CLIPCAPS (Clipping capabilities)")) ;
  99.  
  100.      for (i = 0 ; i < sizeof clip / sizeof clip [0] ; i++)
  101.           TextOut (hdc, 9 * cxChar, (i + 6) * cyChar, szBuffer,
  102.                sprintf (szBuffer, "%-16s%-28s %3s",
  103.                     clip[i].szMask, clip[i].szDesc,
  104.                     GetDeviceCaps (hdcInfo, CLIPCAPS) & clip[i].nMask ?
  105.                          "Yes" : "No")) ;
  106.  
  107.      TextOut (hdc, cxChar, 8 * cyChar, szBuffer,
  108.           sprintf (szBuffer, "RASTERCAPS (Raster capabilities)")) ;
  109.  
  110.      for (i = 0 ; i < sizeof raster / sizeof raster [0] ; i++)
  111.           TextOut (hdc, 9 * cxChar, (i + 10) * cyChar, szBuffer,
  112.                sprintf (szBuffer, "%-16s%-28s %3s",
  113.                     raster[i].szMask, raster[i].szDesc,
  114.                     GetDeviceCaps (hdcInfo, RASTERCAPS) & raster[i].nMask ?
  115.                          "Yes" : "No")) ;
  116.      }
  117.  
  118. void DoBitCodedCaps (HDC hdc, HDC hdcInfo, short cxChar, short cyChar,
  119.                      short nType)
  120.      {
  121.      static BITS curves [] =
  122.           {
  123.           CC_CIRCLES,    "CC_CIRCLES",    "circles:",
  124.           CC_PIE,        "CC_PIE",        "pie wedges:",
  125.           CC_CHORD,      "CC_CHORD",      "chord arcs:",
  126.           CC_ELLIPSES,   "CC_ELLIPSES",   "ellipses:",
  127.           CC_WIDE,       "CC_WIDE",       "wide borders:",
  128.           CC_STYLED,     "CC_STYLED",     "styled borders:",
  129.           CC_WIDESTYLED, "CC_WIDESTYLED", "wide and styled borders:",
  130.           CC_INTERIORS,  "CC_INTERIORS",  "interiors:"
  131.           } ; 
  132.  
  133.      static BITS lines [] =
  134.           {
  135.           LC_POLYLINE,   "LC_POLYLINE",   "polyline:",
  136.           LC_MARKER,     "LC_MARKER",     "markers:",
  137.           LC_POLYMARKER, "LC_POLYMARKER", "polymarkers",
  138.           LC_WIDE,       "LC_WIDE",       "wide lines:",
  139.           LC_STYLED,     "LC_STYLED",     "styled lines:",
  140.           LC_WIDESTYLED, "LC_WIDESTYLED", "wide and styled lines:",
  141.           LC_INTERIORS,  "LC_INTERIORS",  "interiors:"
  142.           } ;
  143.  
  144.      static BITS poly [] =
  145.           {
  146.           PC_POLYGON,    "PC_POLYGON",    "alternate fill polygon:",
  147.           PC_RECTANGLE,  "PC_RECTANGLE",  "rectangle:",
  148.           PC_TRAPEZOID,  "PC_TRAPEZOID",  "winding number fill polygon:",
  149.           PC_SCANLINE,   "PC_SCANLINE",   "scanlines:",
  150.           PC_WIDE,       "PC_WIDE",       "wide borders:",
  151.           PC_STYLED,     "PC_STYLED",     "styled borders:",
  152.           PC_WIDESTYLED, "PC_WIDESTYLED", "wide and styled borders:",
  153.           PC_INTERIORS,  "PC_INTERIORS",  "interiors:"
  154.           } ;
  155.  
  156.      static BITS text [] =
  157.           {
  158.           TC_OP_CHARACTER, "TC_OP_CHARACTER", "character output precision:",
  159.           TC_OP_STROKE,    "TC_OP_STROKE",    "stroke output precision:",
  160.           TC_CP_STROKE,    "TC_CP_STROKE",    "stroke clip precision:",
  161.           TC_CR_90,        "TC_CP_90",        "90 degree character rotation:",
  162.           TC_CR_ANY,       "TC_CR_ANY",       "any character rotation:",
  163.           TC_SF_X_YINDEP,  "TC_SF_X_YINDEP", "scaling independent of X and Y:",
  164.           TC_SA_DOUBLE,    "TC_SA_DOUBLE",   "doubled character for scaling:",
  165.           TC_SA_INTEGER,   "TC_SA_INTEGER",  "integer multiples for scaling:",
  166.           TC_SA_CONTIN,    "TC_SA_CONTIN",  "any multiples for exact scaling:",
  167.           TC_EA_DOUBLE,    "TC_EA_DOUBLE",  "double weight characters:",
  168.           TC_IA_ABLE,      "TC_IA_ABLE",    "italicizing:",
  169.           TC_UA_ABLE,      "TC_UA_ABLE",    "underlining:",
  170.           TC_SO_ABLE,      "TC_SO_ABLE",    "strikeouts:",
  171.           TC_RA_ABLE,      "TC_RA_ABLE",    "raster fonts:",
  172.           TC_VA_ABLE,      "TC_VA_ABLE",    "vector fonts:"
  173.           } ;
  174.  
  175.      static struct
  176.           {
  177.           short nIndex ;
  178.           char  *szTitle ;
  179.           BITS  (*pbits) [] ;
  180.           short nSize ;
  181.           }
  182.           bitinfo [] =
  183.           {
  184.           CURVECAPS,  "CURVCAPS (Curve Capabilities)",
  185.                       (BITS (*)[]) curves, sizeof curves / sizeof curves [0],
  186.           LINECAPS,   "LINECAPS (Line Capabilities)",
  187.                       (BITS (*)[]) lines, sizeof lines / sizeof lines [0],
  188.           POLYGONALCAPS, "POLYGONALCAPS (Polygonal Capabilities)",
  189.                       (BITS (*)[]) poly, sizeof poly / sizeof poly [0],
  190.           TEXTCAPS,   "TEXTCAPS (Text Capabilities)",
  191.                       (BITS (*)[]) text, sizeof text / sizeof text [0]
  192.           } ;
  193.  
  194.      static char szBuffer [80] ;
  195.      BITS        (*pbits) [] = bitinfo [nType].pbits ;
  196.      short       nDevCaps = GetDeviceCaps (hdcInfo, bitinfo [nType].nIndex) ;
  197.      short       i ;
  198.  
  199.      TextOut (hdc, cxChar, cyChar, bitinfo [nType].szTitle,
  200.                     strlen (bitinfo [nType].szTitle)) ;
  201.  
  202.      for (i = 0 ; i < bitinfo [nType].nSize ; i++)
  203.           TextOut (hdc, cxChar, (i + 3) * cyChar, szBuffer,
  204.                sprintf (szBuffer, "%-16s %s %-32s %3s",
  205.                     (*pbits)[i].szMask, "Can do", (*pbits)[i].szDesc,
  206.                     nDevCaps & (*pbits)[i].nMask ? "Yes" : "No")) ;
  207.      }
  208.