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