Annotation of mstools/samples/mandel/printer.c, revision 1.1.1.1

1.1       root        1: /******************************Module*Header*******************************\
                      2: * Module Name: printer.c
                      3: *
                      4: * Contains functions for enermerating printers
                      5: *
                      6: * Created: 16-Apr-1992 11:19:00
                      7: * Author: Petrus Wong
                      8: *
                      9: * Copyright (c) 1990 Microsoft Corporation
                     10: *
                     11: * Before printing the bInitPrinter is called for enumerating printers
                     12: * and doing the setup for printing
                     13: *
                     14: * When Mandelbrot Dream exits, bCleanupPrinter is called to free up
                     15: * memory
                     16: *
                     17: * Dependencies:
                     18: *
                     19: *   (#defines)
                     20: *   (#includes)
                     21: *
                     22: \**************************************************************************/
                     23: #include <windows.h>
                     24: #include <winspool.h>
                     25: #include <drivinit.h>
                     26: #include "printer.h"
                     27: 
                     28: //
                     29: // Globals for printing
                     30: //
                     31: PPRINTER_INFO_1     gpPrinters       = NULL;
                     32: PSZ                *gpszPrinterNames = NULL;
                     33: PSZ                *gpszDeviceNames  = NULL;
                     34: 
                     35: BOOL bInitPrinter(HWND);
                     36: BOOL bCleanupPrinter(VOID);
                     37: 
                     38: extern HMENU  hPrinterMenu;
                     39: extern INT    giNPrinters;
                     40: extern HWND   ghwndMain;
                     41: 
                     42: /******************************Public*Routine******************************\
                     43: *
                     44: * bInitPrinter
                     45: *
                     46: * Effects: Enumerating printers...
                     47: *
                     48: * Warnings: Globals alert!!
                     49: *
                     50: * History:
                     51: *  16-Apr-1992 -by- Petrus Wong
                     52: *
                     53: \**************************************************************************/
                     54: 
                     55: BOOL bInitPrinter(HWND hwnd) {
                     56:     BOOL        bSuccess;
                     57:     DWORD       cbPrinters;
                     58:     DWORD       cbNeeded, cReturned, j;
                     59:     int         i;
                     60: 
                     61: 
                     62:     bSuccess = TRUE;
                     63:     cbPrinters = 4096L;
                     64:     
                     65:     if (!(gpPrinters = (PPRINTER_INFO_1)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT),
                     66:                                                   cbPrinters)))
                     67:     {
                     68:         MessageBox(ghwndMain, "InitPrint: LocalAlloc for gpPrinters failed.", "Error", MB_OK);
                     69:         return (FALSE);
                     70:     }
                     71: 
                     72:     if (!EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 1, (LPBYTE)gpPrinters,
                     73:                       cbPrinters, &cbNeeded, &cReturned))
                     74:     {
                     75:         if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) 
                     76:         {
                     77:             LocalFree((LOCALHANDLE)gpPrinters);
                     78:             gpPrinters = (PPRINTER_INFO_1)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT),
                     79:                                                cbNeeded);
                     80:             cbPrinters = cbNeeded;
                     81: 
                     82:             if (!EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 1, (LPBYTE)gpPrinters,
                     83:                               cbPrinters, &cbNeeded, &cReturned))
                     84:             {
                     85:                 MessageBox(ghwndMain, "Could not enumerate printers!", "Error", MB_OK);
                     86:                 return (FALSE);
                     87:             }
                     88: 
                     89:         } 
                     90:         else 
                     91:         {
                     92:             MessageBox(ghwndMain, "Could not enumerate printers!", "Error", MB_OK);
                     93:             return (FALSE);
                     94:         }
                     95:     }
                     96: 
                     97:     // allocate some memory.
                     98: 
                     99:     gpszPrinterNames = (PSZ *)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT),
                    100:                                         cReturned * (DWORD)sizeof(PSZ));
                    101: 
                    102:     gpszDeviceNames = (PSZ *)LocalAlloc((LMEM_FIXED | LMEM_ZEROINIT),
                    103:                                         cReturned * (DWORD)sizeof(PSZ));
                    104: 
                    105:     if (giNPrinters != 0) {
                    106:         for (i = 0; i < giNPrinters; i++) {
                    107:             RemoveMenu(hPrinterMenu, 3, MF_BYPOSITION);
                    108:         }
                    109:         giNPrinters = 0;
                    110:     }
                    111: 
                    112:     // insert each printer name into the menu.
                    113: 
                    114:     j = giNPrinters = cReturned;
                    115:     for (i = 0; i < (INT) cReturned; i++)
                    116:     {
                    117:         // insert into menu from bottom up.
                    118: 
                    119:         j--;        
                    120:         InsertMenu(hPrinterMenu, 4, MF_BYCOMMAND | MF_STRING,
                    121:                    MM_PRINTER + i, (LPSTR)gpPrinters[j].pName);
                    122: 
                    123:         // save a list of printer names, so we can associate them
                    124:         // with their menu indices later.
                    125: 
                    126:         gpszPrinterNames[i] = gpPrinters[j].pName;
                    127:         gpszDeviceNames[i] = gpPrinters[j].pDescription;
                    128:     }
                    129: #if 0
                    130:     //
                    131:     // Use this if this is called in the MDI child instead
                    132:     //
                    133:     DrawMenuBar(GetParent(GetParent(hwnd)));
                    134: #endif
                    135:     //
                    136:     // Use this instead if this is called in InitializeApp
                    137:     //
                    138:     DrawMenuBar(hwnd);
                    139:     return (bSuccess);
                    140: }
                    141: 
                    142: 
                    143: 
                    144: 
                    145: /******************************Public*Routine******************************\
                    146: *
                    147: * bCleanupPrinter
                    148: *
                    149: * Effects:  Local freeing
                    150: *
                    151: * Warnings: globals!!!
                    152: *
                    153: * History:
                    154: *  29-May-1992 -by- Petrus Wong
                    155: * Wrote it.
                    156: \**************************************************************************/
                    157: 
                    158: BOOL bCleanupPrinter(VOID)
                    159: {
                    160:     if (gpPrinters != NULL)
                    161:         LocalFree((LOCALHANDLE)gpPrinters);
                    162:     if (gpszPrinterNames != NULL)
                    163:         LocalFree((LOCALHANDLE)gpszPrinterNames);
                    164:     if (gpszDeviceNames  != NULL)
                    165:         LocalFree((LOCALHANDLE)gpszDeviceNames);
                    166: 
                    167:     return TRUE;
                    168: }

unix.superglobalmegacorp.com

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