File:  [WindowsNT SDKs] / q_a / samples / printer / devcaps.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 18:29:19 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: ntsdk-jun-1992, HEAD
Microsoft Windows NT Build 297 06-28-1992

/******************************************************************************\
*
*  MODULE:      DEVCAPS.C
*
*  PURPOSE:     To create a DC based on the global varaibles DriverName,
*               DeviceName, and Port, and then query all the device
*               capabilities for that DC and list them in a dialog box.
*
*  FUNTIONS:    DevCapsDlgProc() - processes dialog messages
*               DevCapsThread()  - retrieves devcaps & inserts them in
*                                  listbox
*               TranslateCaps()  - formats text strings based on return
*                                  values of GetDeviceCaps
*               ComplexCapLine() - handles cases when GetDeviceCaps
*                                  returns multiple bit-values, inserts
*                                  1+ strings in listbox.
*
\******************************************************************************/

#include <windows.h>
#include <string.h>
#include "lookup.h"
#include "devcaps.h"
#include "vars.h"
#include "printer.h"



/******************************************************************************\
*
*  FUNCTION:	DevCapDlgProc (standard dialog procedure INPUTS/RETURNS)
*
*  GLOBAL VARS: hDevCapsDlg - dialog window handle
*
\******************************************************************************/

BOOL APIENTRY DevCapDlgProc (HWND hDlg, UINT message, UINT wParam,
			     LONG lParam)
{ switch (message)
  {
    case WM_INITDIALOG:
    {
      DWORD threadId;

      hDevCapsDlg = hDlg;

      if (!CreateThread (NULL, 0,
                         (LPTHREAD_START_ROUTINE) DevCapsThread,
                          NULL, NULL, &threadId))
        MessageBox (NULL, "DevCapsDlgProc(): CreateThread() failed",
		    "Err! - PRINTER", MB_OK | MB_ICONHAND);
      break;
    }
    case WM_COMMAND:

      switch (LOWORD(wParam))
      {
        case IDOK:
          EndDialog(hDlg, TRUE);
          break;
      }
      return (TRUE);
  }
  return (FALSE);
}



/******************************************************************************\
*
*  FUNCTION:     DevCapsThread
*
*  GLOBAL VARS:  hDevCapsDlg - DevCaps dialog window handle
*                hwndMain    - main application window handle
*                DriverName  - driver name of currently selected printer
*                DeviceName  - device name of currently selected printer
*                Port        - port of currently selected printer
*
*  LOCAL VARS:   hdc    - DC fr current device
*                i      - loop variable
*                iValue - return value of GetDeviceCaps
*
*  COMMENTS:     Retrieves all device caps for a DC & calls TranslateCaps
*                to insert them in the dialog's listbox.
*
\******************************************************************************/

void DevCapsThread ()
{
  HDC hdc;
  int i, iValue;

  if (!strcmp (DeviceName, "Display"))
  {
    if (!(hdc = GetDC (hDevCapsDlg)))
    {
      MessageBox (hDevCapsDlg, "GetCapsDlgProc(): GetDC() failed",
		  "Err! - PRINTER", MB_OK);
      return;
    }
  }
  else
  {
    if (!(hdc = CreateDC (DriverName, DeviceName, Port, NULL)))
    {
      MessageBox (hDevCapsDlg, "GetCapsDlgProc(): CreateDC() failed",
		  "Err! - PRINTER", MB_OK);
      return;
    }
  }
  for (i = 0; i < MAX_NUM_DEVICE_CAPS; i++)
  {
    iValue = GetDeviceCaps (hdc, caps[i].x.iIndex);
    TranslateCaps (i, caps[i].x.iIndex, iValue);
  }
  DeleteDC (hdc);
}



/******************************************************************************\
*
*  FUNCTION:     TranslateCaps
*
*  INPUTS:       arrayIndex - index into caps[]
*                capIndex   - devcap index (eg. TECHNOLOGY, CURVECAPS)
*                iValue     - value returned by GetDeviceCaps
*
*  GLOBAL VARS:  hDevCapsDlg  - DevCaps dialog window handle
*                caps         - LOOKUPENTRY table for all caps
*                technologies -    "          "  for TECHNOLOGY-cap flags
*                curves       -    "          "  for CURVECAPS flags
*                lines        -    "          "  for LINECAPS flags
*                polygons     -    "          "  for POLYGONALSCAPS flags
*                text         -    "          "  for TEXTCAPS flags
*                clip         -    "          "  for CLIPCAPS flags
*                raster       -    "          "  for RASTERCAPS flags
*
*  LOCAL VARS:   buf - a temporary buffer
*
*  COMMENTS:     For simple devcaps (eg. tjose with single numeric return
*                value), appends caps value to string and inserts into
*                listbox. For "complex" caps (those returning multiple
*                bit-values) calls ComplexCapsLine which handles text
*                formattting & insertion.
*
\******************************************************************************/

void TranslateCaps (int arrayIndex, int capIndex, int iValue)
{
  char buf[BIGBUFSIZE];

  strcpy (buf, caps[arrayIndex].lpszValue);
  switch (capIndex)
  {
    case TECHNOLOGY:

      ComplexCapLine (buf, technologies, MAX_NUM_TECHNOLOGY_CAPS,
                     iValue);
      break;

    case CURVECAPS:

      ComplexCapLine (buf, curves, MAX_NUM_CURVE_CAPS, iValue);
      break;

    case LINECAPS:

      ComplexCapLine (buf, lines, MAX_NUM_LINE_CAPS, iValue);
      break;

    case POLYGONALCAPS:

      ComplexCapLine (buf, polygons, MAX_NUM_POLYGON_CAPS, iValue);
      break;

    case TEXTCAPS:

      ComplexCapLine (buf, text, MAX_NUM_TEXT_CAPS, iValue);
      break;

    case CLIPCAPS:

      ComplexCapLine (buf, clip, MAX_NUM_CLIP_CAPS, iValue);
      break;

    case RASTERCAPS:

      ComplexCapLine (buf, raster, MAX_NUM_RASTER_CAPS, iValue);
      break;

    default:

      wsprintf(buf, caps[arrayIndex].lpszValue, iValue);
      SendDlgItemMessage (hDevCapsDlg, DID_LISTBOX, LB_INSERTSTRING,
			  (UINT)-1, (LONG) buf);
      break;
  }
}



/******************************************************************************\
*
*  FUNCTION:     ComplexCapLine
*
*  INPUTS:       pbuf        - pointer to buffer containing a cap-type
*                              string
*                pLkUp       - pointer to a LOOKUPENTRY table
*                iMaxEntries - # of enries in table pointed at by pLkUp
*                iValue      - an integer containing 1+ bit-value flags.
*
*  GLOBAL VARS:  hDevCapsDlg - DevCaps dialog window handle
*
*  LOCAL VARS:   i        - loop variable
*                bNewLine - flag specifying new line required
*
*  COMMENTS:     This function is used to expand an int containing
*                multiple bit-values into a set of strings which are
*                inserted into the DevCapsDlg listbox. The iValue
*                parameter is checked against each iIndex entry in the
*                LOOKUPENTRY table pointed at by pLkUp, and when matches
*                are found the corresponding (lpszValue) string is
*                inserted.
*
*                The buffer pointed to by pbuf will be destroyed.
*
\******************************************************************************/

void ComplexCapLine (char *pbuf, LOOKUPENTRY *pLkUp, int iMaxEntries,
                     int iValue)
{
  int  i;
  BOOL bNewLine = FALSE;

  for (i = 0; i < iMaxEntries; i++)

    if (iValue & (pLkUp + i)->x.iIndex)
    {
      if (bNewLine)
      {
        /**********************************************************************\
        *  Keep the first symbolic constant on the same line as the
        *  cap type, eg:  "TECHNOLOGY:     DT_RASDISPLAY".
        \**********************************************************************/

        strcpy (pbuf, BLANKS);
	strcat (pbuf, (pLkUp + i)->lpszValue);
      }
      else
      {
        /**********************************************************************\
        *  Put symbolic constant on new line, eg:
        *                 "                DT_RASPRINTER".
        \**********************************************************************/

	strcat (pbuf, (pLkUp + i)->lpszValue);
        bNewLine = TRUE;
      }
      SendDlgItemMessage (hDevCapsDlg, DID_LISTBOX, LB_INSERTSTRING,
			  (UINT)-1, (LONG) pbuf);
   }
}

unix.superglobalmegacorp.com

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