Annotation of q_a/samples/printer/devcaps.c, revision 1.1.1.1

1.1       root        1: /******************************************************************************\
                      2: *
                      3: *  MODULE:      DEVCAPS.C
                      4: *
                      5: *  PURPOSE:     To create a DC based on the global varaibles DriverName,
                      6: *               DeviceName, and Port, and then query all the device
                      7: *               capabilities for that DC and list them in a dialog box.
                      8: *
                      9: *  FUNTIONS:    DevCapsDlgProc() - processes dialog messages
                     10: *               DevCapsThread()  - retrieves devcaps & inserts them in
                     11: *                                  listbox
                     12: *               TranslateCaps()  - formats text strings based on return
                     13: *                                  values of GetDeviceCaps
                     14: *               ComplexCapLine() - handles cases when GetDeviceCaps
                     15: *                                  returns multiple bit-values, inserts
                     16: *                                  1+ strings in listbox.
                     17: *
                     18: \******************************************************************************/
                     19: 
                     20: #include <windows.h>
                     21: #include <string.h>
                     22: #include "lookup.h"
                     23: #include "devcaps.h"
                     24: #include "vars.h"
                     25: #include "printer.h"
                     26: 
                     27: 
                     28: 
                     29: /******************************************************************************\
                     30: *
                     31: *  FUNCTION:   DevCapDlgProc (standard dialog procedure INPUTS/RETURNS)
                     32: *
                     33: *  GLOBAL VARS: hDevCapsDlg - dialog window handle
                     34: *
                     35: \******************************************************************************/
                     36: 
                     37: BOOL APIENTRY DevCapDlgProc (HWND hDlg, UINT message, UINT wParam,
                     38:                             LONG lParam)
                     39: { switch (message)
                     40:   {
                     41:     case WM_INITDIALOG:
                     42:     {
                     43:       DWORD threadId;
                     44: 
                     45:       hDevCapsDlg = hDlg;
                     46: 
                     47:       if (!CreateThread (NULL, 0,
                     48:                          (LPTHREAD_START_ROUTINE) DevCapsThread,
                     49:                           NULL, NULL, &threadId))
                     50:         MessageBox (NULL, "DevCapsDlgProc(): CreateThread() failed",
                     51:                    "Err! - PRINTER", MB_OK | MB_ICONHAND);
                     52:       break;
                     53:     }
                     54:     case WM_COMMAND:
                     55: 
                     56:       switch (LOWORD(wParam))
                     57:       {
                     58:         case IDOK:
                     59:           EndDialog(hDlg, TRUE);
                     60:           break;
                     61:       }
                     62:       return (TRUE);
                     63:   }
                     64:   return (FALSE);
                     65: }
                     66: 
                     67: 
                     68: 
                     69: /******************************************************************************\
                     70: *
                     71: *  FUNCTION:     DevCapsThread
                     72: *
                     73: *  GLOBAL VARS:  hDevCapsDlg - DevCaps dialog window handle
                     74: *                hwndMain    - main application window handle
                     75: *                DriverName  - driver name of currently selected printer
                     76: *                DeviceName  - device name of currently selected printer
                     77: *                Port        - port of currently selected printer
                     78: *
                     79: *  LOCAL VARS:   hdc    - DC fr current device
                     80: *                i      - loop variable
                     81: *                iValue - return value of GetDeviceCaps
                     82: *
                     83: *  COMMENTS:     Retrieves all device caps for a DC & calls TranslateCaps
                     84: *                to insert them in the dialog's listbox.
                     85: *
                     86: \******************************************************************************/
                     87: 
                     88: void DevCapsThread ()
                     89: {
                     90:   HDC hdc;
                     91:   int i, iValue;
                     92: 
                     93:   if (!strcmp (DeviceName, "Display"))
                     94:   {
                     95:     if (!(hdc = GetDC (hDevCapsDlg)))
                     96:     {
                     97:       MessageBox (hDevCapsDlg, "GetCapsDlgProc(): GetDC() failed",
                     98:                  "Err! - PRINTER", MB_OK);
                     99:       return;
                    100:     }
                    101:   }
                    102:   else
                    103:   {
                    104:     if (!(hdc = CreateDC (DriverName, DeviceName, Port, NULL)))
                    105:     {
                    106:       MessageBox (hDevCapsDlg, "GetCapsDlgProc(): CreateDC() failed",
                    107:                  "Err! - PRINTER", MB_OK);
                    108:       return;
                    109:     }
                    110:   }
                    111:   for (i = 0; i < MAX_NUM_DEVICE_CAPS; i++)
                    112:   {
                    113:     iValue = GetDeviceCaps (hdc, caps[i].x.iIndex);
                    114:     TranslateCaps (i, caps[i].x.iIndex, iValue);
                    115:   }
                    116:   DeleteDC (hdc);
                    117: }
                    118: 
                    119: 
                    120: 
                    121: /******************************************************************************\
                    122: *
                    123: *  FUNCTION:     TranslateCaps
                    124: *
                    125: *  INPUTS:       arrayIndex - index into caps[]
                    126: *                capIndex   - devcap index (eg. TECHNOLOGY, CURVECAPS)
                    127: *                iValue     - value returned by GetDeviceCaps
                    128: *
                    129: *  GLOBAL VARS:  hDevCapsDlg  - DevCaps dialog window handle
                    130: *                caps         - LOOKUPENTRY table for all caps
                    131: *                technologies -    "          "  for TECHNOLOGY-cap flags
                    132: *                curves       -    "          "  for CURVECAPS flags
                    133: *                lines        -    "          "  for LINECAPS flags
                    134: *                polygons     -    "          "  for POLYGONALSCAPS flags
                    135: *                text         -    "          "  for TEXTCAPS flags
                    136: *                clip         -    "          "  for CLIPCAPS flags
                    137: *                raster       -    "          "  for RASTERCAPS flags
                    138: *
                    139: *  LOCAL VARS:   buf - a temporary buffer
                    140: *
                    141: *  COMMENTS:     For simple devcaps (eg. tjose with single numeric return
                    142: *                value), appends caps value to string and inserts into
                    143: *                listbox. For "complex" caps (those returning multiple
                    144: *                bit-values) calls ComplexCapsLine which handles text
                    145: *                formattting & insertion.
                    146: *
                    147: \******************************************************************************/
                    148: 
                    149: void TranslateCaps (int arrayIndex, int capIndex, int iValue)
                    150: {
                    151:   char buf[BIGBUFSIZE];
                    152: 
                    153:   strcpy (buf, caps[arrayIndex].lpszValue);
                    154:   switch (capIndex)
                    155:   {
                    156:     case TECHNOLOGY:
                    157: 
                    158:       ComplexCapLine (buf, technologies, MAX_NUM_TECHNOLOGY_CAPS,
                    159:                      iValue);
                    160:       break;
                    161: 
                    162:     case CURVECAPS:
                    163: 
                    164:       ComplexCapLine (buf, curves, MAX_NUM_CURVE_CAPS, iValue);
                    165:       break;
                    166: 
                    167:     case LINECAPS:
                    168: 
                    169:       ComplexCapLine (buf, lines, MAX_NUM_LINE_CAPS, iValue);
                    170:       break;
                    171: 
                    172:     case POLYGONALCAPS:
                    173: 
                    174:       ComplexCapLine (buf, polygons, MAX_NUM_POLYGON_CAPS, iValue);
                    175:       break;
                    176: 
                    177:     case TEXTCAPS:
                    178: 
                    179:       ComplexCapLine (buf, text, MAX_NUM_TEXT_CAPS, iValue);
                    180:       break;
                    181: 
                    182:     case CLIPCAPS:
                    183: 
                    184:       ComplexCapLine (buf, clip, MAX_NUM_CLIP_CAPS, iValue);
                    185:       break;
                    186: 
                    187:     case RASTERCAPS:
                    188: 
                    189:       ComplexCapLine (buf, raster, MAX_NUM_RASTER_CAPS, iValue);
                    190:       break;
                    191: 
                    192:     default:
                    193: 
                    194:       wsprintf(buf, caps[arrayIndex].lpszValue, iValue);
                    195:       SendDlgItemMessage (hDevCapsDlg, DID_LISTBOX, LB_INSERTSTRING,
                    196:                          (UINT)-1, (LONG) buf);
                    197:       break;
                    198:   }
                    199: }
                    200: 
                    201: 
                    202: 
                    203: /******************************************************************************\
                    204: *
                    205: *  FUNCTION:     ComplexCapLine
                    206: *
                    207: *  INPUTS:       pbuf        - pointer to buffer containing a cap-type
                    208: *                              string
                    209: *                pLkUp       - pointer to a LOOKUPENTRY table
                    210: *                iMaxEntries - # of enries in table pointed at by pLkUp
                    211: *                iValue      - an integer containing 1+ bit-value flags.
                    212: *
                    213: *  GLOBAL VARS:  hDevCapsDlg - DevCaps dialog window handle
                    214: *
                    215: *  LOCAL VARS:   i        - loop variable
                    216: *                bNewLine - flag specifying new line required
                    217: *
                    218: *  COMMENTS:     This function is used to expand an int containing
                    219: *                multiple bit-values into a set of strings which are
                    220: *                inserted into the DevCapsDlg listbox. The iValue
                    221: *                parameter is checked against each iIndex entry in the
                    222: *                LOOKUPENTRY table pointed at by pLkUp, and when matches
                    223: *                are found the corresponding (lpszValue) string is
                    224: *                inserted.
                    225: *
                    226: *                The buffer pointed to by pbuf will be destroyed.
                    227: *
                    228: \******************************************************************************/
                    229: 
                    230: void ComplexCapLine (char *pbuf, LOOKUPENTRY *pLkUp, int iMaxEntries,
                    231:                      int iValue)
                    232: {
                    233:   int  i;
                    234:   BOOL bNewLine = FALSE;
                    235: 
                    236:   for (i = 0; i < iMaxEntries; i++)
                    237: 
                    238:     if (iValue & (pLkUp + i)->x.iIndex)
                    239:     {
                    240:       if (bNewLine)
                    241:       {
                    242:         /**********************************************************************\
                    243:         *  Keep the first symbolic constant on the same line as the
                    244:         *  cap type, eg:  "TECHNOLOGY:     DT_RASDISPLAY".
                    245:         \**********************************************************************/
                    246: 
                    247:         strcpy (pbuf, BLANKS);
                    248:        strcat (pbuf, (pLkUp + i)->lpszValue);
                    249:       }
                    250:       else
                    251:       {
                    252:         /**********************************************************************\
                    253:         *  Put symbolic constant on new line, eg:
                    254:         *                 "                DT_RASPRINTER".
                    255:         \**********************************************************************/
                    256: 
                    257:        strcat (pbuf, (pLkUp + i)->lpszValue);
                    258:         bNewLine = TRUE;
                    259:       }
                    260:       SendDlgItemMessage (hDevCapsDlg, DID_LISTBOX, LB_INSERTSTRING,
                    261:                          (UINT)-1, (LONG) pbuf);
                    262:    }
                    263: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.