|
|
1.1.1.2 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: /******************************************************************************\ 13: * 14: * PROGRAM: GETPDRIV.C 15: * 16: * PURPOSE: Handles display of information returned by call to 17: * GetPrinterDriver. GetPrinterDriver is called for the 18: * currently selected printer (in the tool bar comobobox), 19: * and the results are formatted and displayed in a dialog 20: * box. 21: * 22: * FUNTIONS: GetPrinterDriverDlgProc - handles messages for dialog 23: * DisplayPrinterDriverInfo- retrieves & displays printer 24: * driver info 25: * 26: \******************************************************************************/ 27: 28: #include <windows.h> 29: #include <winspool.h> 30: #include <string.h> 31: #include <stdio.h> 32: #include <winspool.h> 33: #include "common.h" 34: #include "getpdriv.h" 35: 36: 37: /******************************************************************************\ 38: * 39: * FUNCTION: GetPrinterDriverDlgProc (standard dlg proc INPUTS/RETURNS) 40: * 41: * COMMENTS: Processes messages for getPrinterDriver dialog box 42: * 43: \******************************************************************************/ 44: 45: LRESULT CALLBACK GetPrinterDriverDlgProc (HWND hwnd, UINT msg, 46: WPARAM wParam, LPARAM lParam) 47: { 48: switch (msg) 49: { 50: case WM_INITDIALOG: 51: { 52: BOOL bReturn; 53: char buf[BUFSIZE]; 54: 55: // 56: // shove all the printer driver info in the list box 57: // 58: 59: SetCursor (LoadCursor (NULL, IDC_WAIT)); 60: bReturn = DisplayPrinterDriverInfo (hwnd); 61: SetCursor (LoadCursor (NULL, IDC_ARROW)); 62: 63: if (!bReturn) 64: { 65: EndDialog (hwnd, TRUE); 66: } 67: 68: // 69: // set window title to reflect current device 70: // 71: 72: else 73: { 74: sprintf (buf, "GetPrinterDriver: %s;%s;%s", gszDeviceName, gszPort, 75: gszDriverName); 76: 77: SetWindowText (hwnd, (LPCSTR) buf); 78: } 79: 80: break; 81: } 82: 83: case WM_COMMAND: 84: 85: switch (LOWORD (wParam)) 86: { 87: case DID_OK: 88: 89: EndDialog (hwnd, TRUE); 90: return 1; 91: } 92: break; 93: } 94: return 0; 95: } 96: 97: 98: 99: /******************************************************************************\ 100: * 101: * FUNCTION: DisplayPrinterDriverInfo 102: * 103: * INPUTS: hwnd - handle of GetPrinterDriver dialog box 104: * 105: * RETURNS: TRUE if successful, 106: * FALSE otherwise 107: * 108: \******************************************************************************/ 109: 110: 111: BOOL DisplayPrinterDriverInfo (HWND hwnd) 112: { 113: HANDLE hPrinter; 114: DWORD dwBytesNeeded; 115: DRIVER_INFO_1 *pDriverInfo1; 116: DRIVER_INFO_2 *pDriverInfo2; 117: char buf[BUFSIZE]; 118: char pEnvironment[BUFSIZE] = ""; 119: BOOL bReturn = TRUE; 120: 121: // 122: // open selected printer & alloc buffers & get sundry info, close printer 123: // 124: 125: OpenPrinter (gszDeviceName, &hPrinter, NULL); 126: 127: if (!hPrinter) 128: { 129: char buf[BUFSIZE]; 130: 131: sprintf (buf, "OpenPrinter (%s) failed", gszDeviceName); 132: ErrMsgBox ((LPCSTR) buf, ERR_MOD_NAME); 133: bReturn = FALSE; 134: goto display_prt_drv_info_done1; 135: } 136: 137: GetPrinterDriver (hPrinter, pEnvironment, 1, NULL, 0, &dwBytesNeeded); 138: 139: // 140: // simple error checking, if these work assume rest will too 141: // 142: 143: if (!(pDriverInfo1 = (DRIVER_INFO_1 *) LocalAlloc (LPTR, dwBytesNeeded))) 144: { 145: ErrMsgBox ("LocalAlloc failed", ERR_MOD_NAME); 146: bReturn = FALSE; 147: goto display_prt_drv_info_done1; 148: } 149: 150: if (!GetPrinterDriver (hPrinter, pEnvironment, 1, (LPBYTE) pDriverInfo1, 151: dwBytesNeeded, &dwBytesNeeded)) 152: { 153: ErrMsgBox ("GetPrinterDriver failed", ERR_MOD_NAME); 154: bReturn = FALSE; 155: goto display_prt_drv_info_done2; 156: } 157: 158: GetPrinterDriver (hPrinter, pEnvironment, 2, NULL, 0, &dwBytesNeeded); 159: pDriverInfo2 = (DRIVER_INFO_2 *) LocalAlloc (LPTR, dwBytesNeeded); 160: GetPrinterDriver (hPrinter, pEnvironment, 2, (LPBYTE) pDriverInfo2, 161: dwBytesNeeded, &dwBytesNeeded); 162: 163: ClosePrinter (hPrinter); 164: 165: // 166: // shove info in listbox 167: // 168: 169: sprintf (buf, gaDrvInfo[0]); 170: outstr(); 171: 172: sprintf (buf, gaDrvInfo[1], pDriverInfo1->pName); 173: outstr(); 174: 175: sprintf (buf, gaDrvInfo[2]); 176: outstr(); 177: 178: sprintf (buf, gaDrvInfo[3], pDriverInfo2->cVersion); 179: outstr(); 180: 181: sprintf (buf, gaDrvInfo[4], pDriverInfo2->pName); 182: outstr(); 183: 184: sprintf (buf, gaDrvInfo[5], pDriverInfo2->pEnvironment); 185: outstr(); 186: 187: sprintf (buf, gaDrvInfo[6], pDriverInfo2->pDriverPath); 188: outstr(); 189: 190: sprintf (buf, gaDrvInfo[7], pDriverInfo2->pDataFile); 191: outstr(); 192: 193: sprintf (buf, gaDrvInfo[8], pDriverInfo2->pConfigFile); 194: outstr(); 195: 196: LocalFree (LocalHandle (pDriverInfo2)); 197: 198: display_prt_drv_info_done2: 199: 200: LocalFree (LocalHandle (pDriverInfo1)); 201: 202: display_prt_drv_info_done1: 203: 204: return bReturn; 205: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.