Annotation of mstools/samples/printer/enumprt.c, revision 1.1

1.1     ! root        1: /******************************************************************************\
        !             2: *
        !             3: *  PROGRAM:     ENUMPRT.C
        !             4: *
        !             5: *  PURPOSE:     Handles display of information returned by calls to
        !             6: *               EnumPrinters, EnumPrinterDrivers. Info formatted and
        !             7: *               displayed in a dialog box.
        !             8: *
        !             9: *
        !            10: *  FUNTIONS:    EnumPrintersDlgProc      - handles messages for dialog
        !            11: *               DisplayEnumPrintersInfo  - retrieves printer info
        !            12: *               SetEnumPrintersDlgFields - formats & displays printer info
        !            13: *               ComplexEnumPrintersLine  - formats bitfield printer info
        !            14: *               EnumPrinterDriversDlgProc- handles messages for dialog
        !            15: *               DisplayPrinterDriversInfo- retrieves, formats, & displays
        !            16: *                                            printer info
        !            17: *
        !            18: *
        !            19: *                           Microsoft Developer Support
        !            20: *                     Copyright (c) 1992 Microsoft Corporation
        !            21: *
        !            22: \******************************************************************************/
        !            23: 
        !            24: #include <windows.h>
        !            25: #include <string.h>
        !            26: #include <drivinit.h>
        !            27: #include <stdio.h>
        !            28: #include <winspool.h>
        !            29: #include "common.h"
        !            30: #include "enumprt.h"
        !            31: 
        !            32: 
        !            33: 
        !            34: /******************************************************************************\
        !            35: *
        !            36: *  FUNCTION:    EnumPrintersDlgProc (standard dialog procedure INPUTS/RETURNS)
        !            37: *
        !            38: *  COMMENTS:    Processes messages for EnumPrinters dialog box
        !            39: *
        !            40: \******************************************************************************/
        !            41: 
        !            42: LRESULT CALLBACK EnumPrintersDlgProc (HWND   hwnd, UINT msg, WPARAM wParam,
        !            43:                                       LPARAM lParam)
        !            44: {
        !            45:   switch (msg)
        !            46:   {
        !            47:     case WM_INITDIALOG:
        !            48:     {
        !            49:       BOOL bReturn;
        !            50: 
        !            51:       //
        !            52:       // prompt user for EnumPrinters flags...
        !            53:       //
        !            54: 
        !            55:       if (DialogBox (GetModuleHandle (NULL), (LPCTSTR) "EnumPrtOpt",
        !            56:                      NULL, (DLGPROC) EnumPrintersOptionsDlgProc))
        !            57:       {
        !            58:         //
        !            59:         // shove all the enum printer info in the list box
        !            60:         //
        !            61: 
        !            62:         SetCursor (LoadCursor (NULL, IDC_WAIT));
        !            63:         bReturn = DisplayEnumPrintersInfo (hwnd);
        !            64:         SetCursor (LoadCursor (NULL, IDC_ARROW));
        !            65: 
        !            66:         if (!bReturn)
        !            67: 
        !            68:           EndDialog (hwnd, TRUE);
        !            69: 
        !            70:         else
        !            71: 
        !            72:           SetWindowText (hwnd, (LPCTSTR)"EnumPrinters");
        !            73:       }
        !            74:       else
        !            75: 
        !            76:           EndDialog (hwnd, TRUE);
        !            77: 
        !            78:       break;
        !            79:     }
        !            80: 
        !            81:     case WM_COMMAND:
        !            82: 
        !            83:       switch (LOWORD (wParam))
        !            84:       {
        !            85:         case DID_OK:
        !            86: 
        !            87:           EndDialog (hwnd, TRUE);
        !            88:           break;
        !            89:       }
        !            90:       break;
        !            91:   }
        !            92:   return 0;
        !            93: }
        !            94: 
        !            95: 
        !            96: 
        !            97: /******************************************************************************\
        !            98: *
        !            99: *  FUNCTION:    EnumPrintersOptionsDlgProc (standard dlg proc INPUTS/RETURNS)
        !           100: *
        !           101: *  COMMENTS:    Processes messages for EnumPrtOpt dialog box
        !           102: *
        !           103: \******************************************************************************/
        !           104: 
        !           105: LRESULT CALLBACK EnumPrintersOptionsDlgProc (HWND   hwnd,   UINT msg,
        !           106:                                              WPARAM wParam, LPARAM lParam)
        !           107: {
        !           108:   switch (msg)
        !           109:   {
        !           110:     case WM_INITDIALOG:
        !           111: 
        !           112:       gdwEnumFlags = 0;
        !           113:       gszEnumName[0] = 0;
        !           114:       break;
        !           115: 
        !           116:     case WM_COMMAND:
        !           117: 
        !           118:       switch (LOWORD (wParam))
        !           119:       {
        !           120:         case DID_OK:
        !           121: 
        !           122:           if (gdwEnumFlags)
        !           123:           {
        !           124:             if (gdwEnumFlags & PRINTER_ENUM_NAME)
        !           125:             {
        !           126:               GetDlgItemText (hwnd, DID_EDITTEXT, (LPTSTR)gszEnumName,
        !           127:                               BUFSIZE);
        !           128: 
        !           129:               if (!strlen (gszEnumName))
        !           130:               {
        !           131:                 MessageBox (hwnd,
        !           132:                             (LPCTSTR) "Please enter a valid domain/server name",
        !           133:                             (LPCTSTR) "", MB_OK);
        !           134:                 SetFocus (GetDlgItem (hwnd, DID_EDITTEXT));
        !           135:                 break;
        !           136:               }
        !           137:             }
        !           138: 
        !           139:             EndDialog (hwnd, TRUE);
        !           140:           }
        !           141: 
        !           142:           else
        !           143: 
        !           144:             EndDialog (hwnd, FALSE);
        !           145: 
        !           146:           break;
        !           147: 
        !           148:         case DID_CANCEL:
        !           149: 
        !           150:           EndDialog (hwnd, FALSE);
        !           151:           break;
        !           152: 
        !           153:         default:
        !           154: 
        !           155:           if (HIWORD(wParam) == BN_CLICKED)
        !           156:           {
        !           157:             DWORD dwControlId = (DWORD) LOWORD (wParam);
        !           158: 
        !           159:             if (gdwEnumFlags & dwControlId)
        !           160:             {
        !           161:               //
        !           162:               // remove that flag, if PRINTER_ENUM_NAME disable edittext
        !           163:               //
        !           164: 
        !           165:               gdwEnumFlags &= ~dwControlId;
        !           166: 
        !           167:               if (dwControlId & PRINTER_ENUM_NAME)
        !           168:               {
        !           169:                 SetDlgItemText (hwnd, DID_EDITTEXT, (LPCTSTR)"");
        !           170:                 EnableWindow   (GetDlgItem (hwnd, DID_EDITTEXT), FALSE);
        !           171:               }
        !           172:             }
        !           173: 
        !           174:             else
        !           175:             {
        !           176:               //
        !           177:               // add that flag, if PRINTER_ENUM_NAME enable edittext
        !           178:               //
        !           179: 
        !           180:               gdwEnumFlags |= dwControlId;
        !           181: 
        !           182:               if (dwControlId & PRINTER_ENUM_NAME)
        !           183: 
        !           184:                 EnableWindow (GetDlgItem (hwnd, DID_EDITTEXT), TRUE);
        !           185:             }
        !           186:           }
        !           187:           break;
        !           188:       }
        !           189:   }
        !           190:   return 0;
        !           191: }
        !           192: 
        !           193: 
        !           194: 
        !           195: /******************************************************************************\
        !           196: *
        !           197: *  FUNCTION:    DisplayEnumPrintersInfo
        !           198: *
        !           199: *  INPUTS:      hwnd - handle of the EnumPrinters dialog box
        !           200: *
        !           201: *  RETURNS:     TRUE if successful,
        !           202: *               FALSE otherwise
        !           203: *
        !           204: \******************************************************************************/
        !           205: 
        !           206: BOOL DisplayEnumPrintersInfo (HWND hwnd)
        !           207: {
        !           208:   DWORD  dwBytesNeeded;
        !           209:   DWORD  dwPrtRet1, dwPrtRet2;
        !           210:   DWORD  dwMaxPrt;
        !           211:   LPTSTR lpName = gdwEnumFlags & PRINTER_ENUM_NAME ? gszEnumName : NULL;
        !           212: 
        !           213:   LPPRINTER_INFO_1 pPrtInfo1;
        !           214:   LPPRINTER_INFO_2 pPrtInfo2;
        !           215: 
        !           216:   BOOL   bReturn = TRUE;
        !           217: 
        !           218:   //
        !           219:   // get byte count needed for buffer, alloc buffer, the enum the printers
        !           220:   //
        !           221: 
        !           222:   EnumPrinters (gdwEnumFlags, lpName, 1, NULL, 0, &dwBytesNeeded,
        !           223:                      &dwPrtRet1);
        !           224: 
        !           225:   //
        !           226:   // (simple error checking, if these work assume rest will too)
        !           227:   //
        !           228: 
        !           229:   if (!(pPrtInfo1 = (LPPRINTER_INFO_1) LocalAlloc (LPTR, dwBytesNeeded)))
        !           230:   {
        !           231:     ErrMsgBox ("EnumPrinters/LocalAlloc failed", ERR_MOD_NAME);
        !           232:     bReturn = FALSE;
        !           233:     goto display_prts_info_done1;
        !           234:   }
        !           235: 
        !           236:   if (!EnumPrinters (gdwEnumFlags, lpName, 1, (LPBYTE) pPrtInfo1,
        !           237:                 dwBytesNeeded, &dwBytesNeeded, &dwPrtRet1))
        !           238:   {
        !           239:     ErrMsgBox ("EnumPrinters failed", ERR_MOD_NAME);
        !           240:     bReturn = FALSE;
        !           241:     goto display_prts_info_done2;
        !           242:   }
        !           243: 
        !           244:   //
        !           245:   // get byte count needed for buffer, alloc buffer, the enum the printers
        !           246:   //
        !           247: 
        !           248:   EnumPrinters (gdwEnumFlags, lpName, 2, NULL, 0, &dwBytesNeeded,
        !           249:                 &dwPrtRet2);
        !           250: 
        !           251:   pPrtInfo2 = (LPPRINTER_INFO_2) LocalAlloc (LPTR, dwBytesNeeded);
        !           252: 
        !           253:   EnumPrinters (gdwEnumFlags, lpName, 2, (LPBYTE) pPrtInfo2,
        !           254:                 dwBytesNeeded, &dwBytesNeeded, &dwPrtRet2);
        !           255: 
        !           256:   if (!dwPrtRet1 || !dwPrtRet2)
        !           257:   {
        !           258:     ErrMsgBox ("EnumPrinters returned 0 printers", "");
        !           259:     bReturn = FALSE;
        !           260:     goto display_prts_info_done3;
        !           261:   }
        !           262: 
        !           263:   dwMaxPrt = dwPrtRet1 > dwPrtRet2 ? dwPrtRet2 : dwPrtRet1;
        !           264: 
        !           265:   SetEnumPrintersDlgFields (hwnd, dwMaxPrt, pPrtInfo1,
        !           266:                             pPrtInfo2);
        !           267: 
        !           268: display_prts_info_done3:
        !           269: 
        !           270:   LocalFree (LocalHandle (pPrtInfo2));
        !           271: 
        !           272: display_prts_info_done2:
        !           273: 
        !           274:   LocalFree (LocalHandle (pPrtInfo1));
        !           275: 
        !           276: display_prts_info_done1:
        !           277: 
        !           278:   return bReturn;
        !           279: }
        !           280: 
        !           281: 
        !           282: /******************************************************************************\
        !           283: *
        !           284: *  FUNCTION:    SetEnumPrintersDlgFields
        !           285: *
        !           286: *  INPUTS:      hwnd      - handle of the EnumPrinters dialog box
        !           287: *               dwMaxPrt  - number of elements in the following two arrays
        !           288: *               pdisplay_prts_info1 - ptr to an array of PRINTER_INFO_1 structs
        !           289: *               pdisplay_prts_info2 - ptr to an array of PRINTER_INFO_2 structs
        !           290: *
        !           291: *  COMMENTS:    This function formats the info returned by EnumPrinters()
        !           292: *               into readable strings and inserts them in the listbox.
        !           293: *
        !           294: \******************************************************************************/
        !           295: 
        !           296: void SetEnumPrintersDlgFields (HWND hwnd, DWORD dwMaxPrt,
        !           297:                                LPPRINTER_INFO_1 pPrtInfo1,
        !           298:                                LPPRINTER_INFO_2 pPrtInfo2)
        !           299: {
        !           300:   char  buf[256];
        !           301:   WORD  i;
        !           302:   DWORD j;
        !           303: 
        !           304:   SendDlgItemMessage (hwnd, DID_LISTBOX, LB_RESETCONTENT, 0, 0);
        !           305: 
        !           306:   for (j = 0; j < dwMaxPrt; j++)
        !           307:   {
        !           308:     //
        !           309:     // Stick PRINTER_INFO_1  data in listbox
        !           310:     //
        !           311: 
        !           312:     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_INSERTSTRING, (UINT)-1,
        !           313:                         (LONG) gaEnumPrt[0]);
        !           314: 
        !           315:     outstr (gaEnumPrt[1], (pPrtInfo1 + j)->pDescription);
        !           316:     outstr (gaEnumPrt[2], (pPrtInfo1 + j)->pName);
        !           317:     outstr (gaEnumPrt[3], (pPrtInfo1 + j)->pComment);
        !           318: 
        !           319:     //
        !           320:     // Stick PRINTER_INFO_2  data in listbox
        !           321:     //
        !           322: 
        !           323:     SendDlgItemMessage (hwnd, DID_LISTBOX, LB_INSERTSTRING, (UINT)-1,
        !           324:                         (LONG) gaEnumPrt[4]);
        !           325: 
        !           326:     outstr (gaEnumPrt[5],  (pPrtInfo2 + j)->pServerName);
        !           327:     outstr (gaEnumPrt[6],  (pPrtInfo2 + j)->pPrinterName);
        !           328:     outstr (gaEnumPrt[7],  (pPrtInfo2 + j)->pShareName);
        !           329:     outstr (gaEnumPrt[8],  (pPrtInfo2 + j)->pPortName);
        !           330:     outstr (gaEnumPrt[9],  (pPrtInfo2 + j)->pDriverName);
        !           331:     outstr (gaEnumPrt[10], (pPrtInfo2 + j)->pComment);
        !           332:     outstr (gaEnumPrt[11], (pPrtInfo2 + j)->pLocation);
        !           333: 
        !           334:     if ((pPrtInfo2 + j)->pDevMode)
        !           335:     {
        !           336:       DWORD dwFields;
        !           337: 
        !           338:       outstr (gaEnumPrt[12], "");
        !           339:       outstr (gaEnumPrt[13], (pPrtInfo2 + j)->pDevMode->dmDeviceName);
        !           340:       outnum (gaEnumPrt[14], (pPrtInfo2 + j)->pDevMode->dmSpecVersion);
        !           341:       outnum (gaEnumPrt[15], (pPrtInfo2 + j)->pDevMode->dmDriverVersion);
        !           342:       outnum (gaEnumPrt[16], (pPrtInfo2 + j)->pDevMode->dmSize);
        !           343:       outnum (gaEnumPrt[17], (pPrtInfo2 + j)->pDevMode->dmDriverExtra);
        !           344: 
        !           345:       dwFields = (pPrtInfo2 + j)->pDevMode->dmFields;
        !           346:       ComplexEnumPrintersLine (hwnd, gaEnumPrt[18], gaFields, MAX_FIELDS,
        !           347:                                dwFields);
        !           348: 
        !           349:       if (dwFields & DM_ORIENTATION)
        !           350: 
        !           351:         ComplexEnumPrintersLine (hwnd, gaEnumPrt[19], gaOrientation,
        !           352:                                  MAX_ORIENTATION,
        !           353:                                  (DWORD)
        !           354:                                  (pPrtInfo2+j)->pDevMode->dmOrientation);
        !           355: 
        !           356:       if (dwFields & DM_PAPERSIZE)
        !           357: 
        !           358:         ComplexEnumPrintersLine (hwnd, gaEnumPrt[20], gaPaperSize,
        !           359:                                  MAX_PAPERSIZE,
        !           360:                                  (DWORD)(pPrtInfo2 + j)->pDevMode->dmPaperSize);
        !           361: 
        !           362:       if (dwFields & DM_PAPERLENGTH)
        !           363: 
        !           364:         outnum (gaEnumPrt[21], (pPrtInfo2 + j)->pDevMode->dmPaperLength);
        !           365: 
        !           366: 
        !           367:       if (dwFields & DM_PAPERWIDTH)
        !           368: 
        !           369:         outnum (gaEnumPrt[22], (pPrtInfo2 + j)->pDevMode->dmPaperWidth);
        !           370: 
        !           371:       if (dwFields & DM_SCALE)
        !           372: 
        !           373:         outnum (gaEnumPrt[23], (pPrtInfo2 + j)->pDevMode->dmScale);
        !           374: 
        !           375:       if (dwFields & DM_COPIES)
        !           376: 
        !           377:         outnum (gaEnumPrt[24], (pPrtInfo2 + j)->pDevMode->dmCopies);
        !           378: 
        !           379:       if (dwFields & DM_DEFAULTSOURCE)
        !           380: 
        !           381:         ComplexEnumPrintersLine (hwnd, gaEnumPrt[25], gaDefaultSource,
        !           382:                                  MAX_DEFAULTSOURCE,
        !           383:                                (DWORD)(pPrtInfo2+j)->pDevMode->dmDefaultSource);
        !           384: 
        !           385:       if (dwFields & DM_PRINTQUALITY)
        !           386: 
        !           387:         ComplexEnumPrintersLine (hwnd, gaEnumPrt[26], gaPrintQuality,
        !           388:                                  MAX_PRINTQUALITY,
        !           389:                                 (DWORD)(pPrtInfo2+j)->pDevMode->dmPrintQuality);
        !           390: 
        !           391:       if (dwFields & DM_COLOR)
        !           392: 
        !           393:         ComplexEnumPrintersLine (hwnd, gaEnumPrt[27], gaColor,
        !           394:                                  MAX_COLOR,
        !           395:                                  (DWORD)(pPrtInfo2 + j)->pDevMode->dmColor);
        !           396: 
        !           397:       if (dwFields & DM_DUPLEX)
        !           398: 
        !           399:         ComplexEnumPrintersLine (hwnd, gaEnumPrt[28], gaDuplex,
        !           400:                                  MAX_DUPLEX,
        !           401:                                  (DWORD)(pPrtInfo2 + j)->pDevMode->dmDuplex);
        !           402: 
        !           403:       if (dwFields & DM_YRESOLUTION)
        !           404: 
        !           405:         outnum (gaEnumPrt[29], NULL);
        !           406: 
        !           407:       if (dwFields & DM_TTOPTION)
        !           408: 
        !           409:         outnum (gaEnumPrt[29], NULL);
        !           410: 
        !           411:       if (dwFields & DM_COLLATE)
        !           412: 
        !           413:         outnum (gaEnumPrt[30], NULL);
        !           414: 
        !           415:       if (dwFields & DM_FORMNAME)
        !           416: 
        !           417:         outnum (gaEnumPrt[31], NULL);
        !           418:     }
        !           419:     else
        !           420:     {
        !           421:       outstr (gaEnumPrt[12], NULL);
        !           422:     }
        !           423: 
        !           424:     outstr (gaEnumPrt[33], (pPrtInfo2 + j)->pSepFile);
        !           425:     outstr (gaEnumPrt[34], (pPrtInfo2 + j)->pPrintProcessor);
        !           426:     outstr (gaEnumPrt[35], (pPrtInfo2 + j)->pDatatype);
        !           427:     outstr (gaEnumPrt[36], (pPrtInfo2 + j)->pParameters);
        !           428: 
        !           429:     ComplexEnumPrintersLine (hwnd, gaEnumPrt[37], gaAttributes,
        !           430:                              MAX_ATTRIBUTES,
        !           431:                              (pPrtInfo2 + j)->Attributes);
        !           432: 
        !           433:     for (i = 0; i < MAX_PRIORITIES; i++)
        !           434: 
        !           435:       if ((pPrtInfo2 + j)->Priority & gaPriorities[i].dwValue)
        !           436:       {
        !           437:         outstr (gaEnumPrt[38], gaPriorities[i].szValue);
        !           438:         break;
        !           439:       }
        !           440: 
        !           441:     if (i == MAX_PRIORITIES)
        !           442: 
        !           443:       outnum (gaEnumPrt[39], (pPrtInfo2 + j)->Priority);
        !           444: 
        !           445:     outnum (gaEnumPrt[40], (pPrtInfo2 + j)->DefaultPriority);
        !           446:     outnum (gaEnumPrt[41], (pPrtInfo2 + j)->StartTime);
        !           447:     outnum (gaEnumPrt[42], (pPrtInfo2 + j)->UntilTime);
        !           448: 
        !           449:     ComplexEnumPrintersLine (hwnd, gaEnumPrt[43], gaStatus, MAX_STATUS,
        !           450:                              (pPrtInfo2 + j)->Status);
        !           451: 
        !           452:     outnum (gaEnumPrt[44], (pPrtInfo2 + j)->cJobs);
        !           453:     outnum (gaEnumPrt[45], (pPrtInfo2 + j)->AveragePPM);
        !           454:   }
        !           455: }
        !           456: 
        !           457: 
        !           458: 
        !           459: /******************************************************************************\
        !           460: *
        !           461: *  FUNCTION:    ComplexEnumPrintersLine
        !           462: *
        !           463: *  INPUTS:      hwnd        - handle of the EnumPrinters dialog box
        !           464: *               pbuf        - pointer to buffer containing a cap-type
        !           465: *                              string
        !           466: *               pLkUp       - pointer to a CAPSLOOKUP table
        !           467: *               iMaxEntries - # of enries in table pointed at by pLkUp
        !           468: *               iValue      - an integer containing 1+ bit-value flags.
        !           469: *
        !           470: *  COMMENTS:    This function is used to expand an int containing
        !           471: *               multiple bit-values into a set of strings which are
        !           472: *               inserted into the DevCapsDlg listbox. The iValue
        !           473: *               parameter is checked against each iIndex entry in the
        !           474: *               CAPSLOOKUP table pointed at by pLkUp, and when matches
        !           475: *               are found the corresponding (lpszValue) string is
        !           476: *               inserted.
        !           477: *
        !           478: *               The buffer pointed to by pbuf will be destroyed.
        !           479: *
        !           480: \******************************************************************************/
        !           481: 
        !           482: void ComplexEnumPrintersLine (HWND hwnd, char  *pstr, ENUMPRTLOOKUP *pLkUp,
        !           483:                               int iMaxEntries, DWORD  dwValue)
        !           484: {
        !           485:   char buf [BUFSIZE];
        !           486:   int  i;
        !           487:   BOOL bNewLine = FALSE;
        !           488: 
        !           489:   strcpy (buf, pstr);
        !           490: 
        !           491:   for (i = 0; i < iMaxEntries; i++)
        !           492: 
        !           493:     if (dwValue & (pLkUp + i)->dwValue)
        !           494:     {
        !           495:       if (bNewLine)
        !           496:       {
        !           497:         //
        !           498:         // Keep the first symbolic constant on the same line as the
        !           499:         //   cap type, eg:  "TECHNOLOGY:     DT_RASDISPLAY".
        !           500:         //
        !           501: 
        !           502:         strcpy (buf, BLANKS);
        !           503:         strcat (buf, (pLkUp + i)->szValue);
        !           504:       }
        !           505:       else
        !           506:       {
        !           507:         //
        !           508:         // Put symbolic constant on new line, eg:
        !           509:         //                  "                DT_RASPRINTER".
        !           510:         //
        !           511: 
        !           512:         strcat (buf, (pLkUp + i)->szValue);
        !           513:         bNewLine = TRUE;
        !           514:       }
        !           515:       SendDlgItemMessage (hwnd, DID_LISTBOX, LB_INSERTSTRING,
        !           516:                           (UINT)-1, (LONG) buf);
        !           517:    }
        !           518: }
        !           519: 
        !           520: 
        !           521: 
        !           522: /******************************************************************************\
        !           523: *
        !           524: *  FUNCTION:    EnumPrinterDriversDlgProc (standard dlg proc INPUTS/RETURNS)
        !           525: *
        !           526: *  COMMENTS:    Processes messages for EnumPrinterDrivers dialog box
        !           527: *
        !           528: \******************************************************************************/
        !           529: 
        !           530: LRESULT CALLBACK EnumPrinterDriversDlgProc (HWND   hwnd,   UINT   msg,
        !           531:                                             WPARAM wParam, LPARAM lParam)
        !           532: {
        !           533:   switch (msg)
        !           534:   {
        !           535:     case WM_INITDIALOG:
        !           536:     {
        !           537:       BOOL bReturn;
        !           538: 
        !           539:       SetCursor (LoadCursor (NULL, IDC_WAIT));
        !           540:       bReturn = DisplayPrinterDriversInfo (hwnd);
        !           541:       SetCursor (LoadCursor (NULL, IDC_ARROW));
        !           542: 
        !           543:       if (!bReturn)
        !           544: 
        !           545:         EndDialog (hwnd, TRUE);
        !           546: 
        !           547:       else
        !           548: 
        !           549:         SetWindowText (hwnd, (LPCTSTR) "EnumPrinterDrivers");
        !           550: 
        !           551:       break;
        !           552:     }
        !           553: 
        !           554:     case WM_COMMAND:
        !           555: 
        !           556:       switch (LOWORD (wParam))
        !           557:       {
        !           558:         case DID_OK:
        !           559: 
        !           560:           EndDialog (hwnd, TRUE);
        !           561: 
        !           562:           return 1;
        !           563:       }
        !           564:       break;
        !           565:   }
        !           566:   return 0;
        !           567: }
        !           568: 
        !           569: 
        !           570: 
        !           571: /******************************************************************************\
        !           572: *
        !           573: *  FUNCTION:    DisplayPrinterDriversInfo
        !           574: *
        !           575: *  INPUTS:      hwnd - handle of the EnumPrinterDrivers dialog box
        !           576: *
        !           577: *  RETURNS:     TRUE if successful,
        !           578: *               FALSE otherwise
        !           579: *
        !           580: *  COMMENTS:    Retrieves EnumPrinterDrivers info, formats, & inserts
        !           581: *               in listbox.
        !           582: *
        !           583: \******************************************************************************/
        !           584: 
        !           585: BOOL DisplayPrinterDriversInfo (HWND hwnd)
        !           586: {
        !           587:   DWORD         dwBytesNeeded, dwDrvRet, i;
        !           588:   DRIVER_INFO_1 *pDriverInfo1;
        !           589:   DRIVER_INFO_2 *pDriverInfo2;
        !           590:   char          buf[BUFSIZE];
        !           591:   BOOL          bReturn = TRUE;
        !           592: 
        !           593:   //
        !           594:   // get byte count needed for buffer, alloc buffer, the enum the drivers
        !           595:   //
        !           596: 
        !           597:   EnumPrinterDrivers ((LPTSTR) NULL, (LPTSTR) NULL, 1, NULL,
        !           598:                       0, &dwBytesNeeded, &dwDrvRet);
        !           599: 
        !           600:   //
        !           601:   // simple error checking, if these work assume rest will too
        !           602:   //
        !           603: 
        !           604:   if (!(pDriverInfo1 = (DRIVER_INFO_1 *) LocalAlloc (LPTR, dwBytesNeeded)))
        !           605:   {
        !           606:     ErrMsgBox ("LocalAlloc failed", ERR_MOD_NAME);
        !           607:     bReturn = FALSE;
        !           608:     goto display_prt_drvs_info_done1;
        !           609:   }
        !           610: 
        !           611:   if (!EnumPrinterDrivers ((LPTSTR) NULL, (LPTSTR) NULL, 1,
        !           612:                            (LPBYTE) pDriverInfo1, dwBytesNeeded, &dwBytesNeeded,
        !           613:                            &dwDrvRet))
        !           614:   {
        !           615:     ErrMsgBox ("EnumPrinterDrivers returned 0 drivers", ERR_MOD_NAME);
        !           616:     bReturn = FALSE;
        !           617:     goto display_prt_drvs_info_done2;
        !           618:   }
        !           619: 
        !           620:   EnumPrinterDrivers ((LPTSTR) NULL,(LPTSTR) NULL, 2, NULL,
        !           621:                       0, &dwBytesNeeded, &dwDrvRet);
        !           622: 
        !           623:   pDriverInfo2 = (DRIVER_INFO_2 *) LocalAlloc (LPTR, dwBytesNeeded);
        !           624: 
        !           625:   EnumPrinterDrivers ((LPTSTR) NULL, (LPTSTR) NULL, 2,
        !           626:                       (LPBYTE) pDriverInfo2, dwBytesNeeded, &dwBytesNeeded,
        !           627:                       &dwDrvRet);
        !           628: 
        !           629:   if (!dwDrvRet)
        !           630:   {
        !           631:     ErrMsgBox ("EnumPrinterDrivers returned 0 drivers", "");
        !           632:     bReturn = FALSE;
        !           633:     goto display_prt_drvs_info_done3;
        !           634:   }
        !           635: 
        !           636:   //
        !           637:   // insert formatted info into listbox
        !           638:   //
        !           639: 
        !           640:   for (i = 0; i < dwDrvRet; i++)
        !           641:   {
        !           642:     sprintf (buf, gaDriverInfo[0]);
        !           643:     outstr3();
        !           644: 
        !           645:     sprintf (buf, gaDriverInfo[1], (pDriverInfo1 + i)->pName);
        !           646:     outstr3();
        !           647: 
        !           648:     sprintf (buf, gaDriverInfo[2]);
        !           649:     outstr3();
        !           650: 
        !           651:     sprintf (buf, gaDriverInfo[3], (pDriverInfo2 + i)->cVersion);
        !           652:     outstr3();
        !           653: 
        !           654:     sprintf (buf, gaDriverInfo[4], (pDriverInfo2 + i)->pName);
        !           655:     outstr3();
        !           656: 
        !           657:     sprintf (buf, gaDriverInfo[5], (pDriverInfo2 + i)->pEnvironment);
        !           658:     outstr3();
        !           659: 
        !           660:     sprintf (buf, gaDriverInfo[6], (pDriverInfo2 + i)->pDriverPath);
        !           661:     outstr3();
        !           662: 
        !           663:     sprintf (buf, gaDriverInfo[7], (pDriverInfo2 + i)->pDataFile);
        !           664:     outstr3();
        !           665: 
        !           666:     sprintf (buf, gaDriverInfo[8], (pDriverInfo2 + i)->pConfigFile);
        !           667:     outstr3();
        !           668: 
        !           669:   }
        !           670: 
        !           671: display_prt_drvs_info_done3:
        !           672: 
        !           673:   LocalFree (LocalHandle (pDriverInfo2));
        !           674: 
        !           675: display_prt_drvs_info_done2:
        !           676: 
        !           677:   LocalFree (LocalHandle (pDriverInfo1));
        !           678: 
        !           679: display_prt_drvs_info_done1:
        !           680: 
        !           681:   return bReturn;
        !           682: }

unix.superglobalmegacorp.com

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