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

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

unix.superglobalmegacorp.com

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