|
|
1.1 root 1: /******************************************************************************\
2: *
3: * PROGRAM: GETCAPS.C
4: *
5: * PURPOSE: Handles display of information returned by call to
6: * GetDeviceCaps. GetDeviceCaps is called for the
7: * currently selected deivce (in the tool bar comobobox),
8: * and the results are formatted and displayed in a dialog
9: * box.
10: *
11: * FUNTIONS: GetDeviceCapsDlgProc - handles messages for dialog
12: * DisplayDeviceCapsInfo- retrieves device caps info
13: * TranslateDeviceCaps - displays a capability in listbox
14: * ComplexDeviceCapsLine- formats a bitfield capability
15: *
16: *
17: * Microsoft Developer Support
18: * Copyright (c) 1992 Microsoft Corporation
19: *
20: \******************************************************************************/
21:
22: #include <windows.h>
23: #include <winspool.h>
24: #include <string.h>
25: #include <stdio.h>
26: #include <winspool.h>
27: #include "common.h"
28: #include "getcaps.h"
29:
30:
31:
32: /******************************************************************************\
33: *
34: * FUNCTION: GetDeviceCapsDlgProc (standard dialog procedure INPUTS/RETURNS)
35: *
36: * COMMENTS: Processes messages for GetDeviceCaps dialog box
37: *
38: \******************************************************************************/
39:
40: LRESULT CALLBACK GetDeviceCapsDlgProc (HWND hwnd, UINT msg, WPARAM wParam,
41: LPARAM lParam)
42: {
43: switch (msg)
44: {
45: case WM_INITDIALOG:
46: {
47: BOOL bReturn;
48: char buf[BUFSIZE];
49:
50: ghwndDevCaps = hwnd;
51:
52: //
53: // shove all the caps info in the list box
54: //
55:
56: SetCursor (LoadCursor (NULL, IDC_WAIT));
57: bReturn = DisplayDeviceCapsInfo ();
58: SetCursor (LoadCursor (NULL, IDC_ARROW));
59:
60: if (!bReturn)
61: {
62: EndDialog (hwnd, TRUE);
63: }
64:
65: //
66: // set window title to reflect current device
67: //
68:
69: else
70: {
71: sprintf (buf, "GetDeviceCaps: %s;%s;%s", gszDeviceName, gszPort,
72: gszDriverName);
73:
74: SetWindowText (hwnd, (LPCSTR) buf);
75: }
76:
77: break;
78: }
79:
80: case WM_COMMAND:
81:
82: switch (LOWORD (wParam))
83: {
84: case DID_OK:
85:
86: EndDialog (hwnd, TRUE);
87: return 1;
88: }
89: break;
90: }
91: return 0;
92: }
93:
94:
95:
96: /******************************************************************************\
97: *
98: * FUNCTION: DisplayDeviceCapsInfo
99: *
100: * RETURNS: TRUE if successful,
101: * FALSE otherwise
102: *
103: * COMMENTS: Retrieves all device caps for current deivce & calls
104: * TranslateCaps to insert them in the dialog's listbox.
105: *
106: \******************************************************************************/
107:
108: BOOL DisplayDeviceCapsInfo ()
109: {
110: HDC hdc;
111: int i, iValue;
112:
113: if (!strcmp (gszDeviceName, "Display"))
114: {
115: if (!(hdc = GetDC (ghwndDevCaps)))
116: {
117: ErrMsgBox ("GetDC failed", ERR_MOD_NAME);
118: return FALSE;
119: }
120: }
121:
122: else
123: {
124: if (!(hdc = CreateDC (gszDriverName, gszDeviceName, gszPort, NULL)))
125: {
126: char buf[BUFSIZE];
127:
128: sprintf (buf, "CreateDC (%s, %s, %s, NULL) failed",
129: gszDriverName, gszDeviceName, gszPort);
130: ErrMsgBox (buf, ERR_MOD_NAME);
131: return FALSE;
132: }
133: }
134:
135: for (i = 0; i < MAX_DEVICE_CAPS; i++)
136: {
137: iValue = GetDeviceCaps (hdc, gaCaps[i].iValue);
138: TranslateDeviceCaps (i, gaCaps[i].iValue, iValue);
139: }
140: DeleteDC (hdc);
141:
142: return TRUE;
143: }
144:
145:
146:
147: /******************************************************************************\
148: *
149: * FUNCTION: TranslateDeviceCaps
150: *
151: * INPUTS: arrayIndex - index into gaCaps[]
152: * capIndex - devcap index (eg. TECHNOLOGY, CURVECAPS)
153: * iValue - value returned by GetDeviceCaps
154: *
155: * COMMENTS: For simple devcaps (eg. tjose with single numeric return
156: * value), appends caps value to string and inserts into
157: * listbox. For "complex" caps (those returning multiple
158: * bit-values) calls ComplexCapsLine which handles text
159: * formattting & insertion.
160: *
161: \******************************************************************************/
162:
163: void TranslateDeviceCaps (int arrayIndex, int capIndex, int iValue)
164: {
165: char buf[BUFSIZE];
166:
167: strcpy (buf, gaCaps[arrayIndex].szValue);
168:
169: switch (capIndex)
170: {
171: case TECHNOLOGY:
172:
173: ComplexDeviceCapsLine (buf, gaTechnologyCaps, MAX_TECHNOLOGY_CAPS,
174: iValue);
175: break;
176:
177: case CURVECAPS:
178:
179: ComplexDeviceCapsLine (buf, gaCurveCaps, MAX_CURVE_CAPS, iValue);
180: break;
181:
182: case LINECAPS:
183:
184: ComplexDeviceCapsLine (buf, gaLineCaps, MAX_LINE_CAPS, iValue);
185: break;
186:
187: case POLYGONALCAPS:
188:
189: ComplexDeviceCapsLine (buf, gaPolygonCaps, MAX_POLYGON_CAPS, iValue);
190: break;
191:
192: case TEXTCAPS:
193:
194: ComplexDeviceCapsLine (buf, gaTextCaps, MAX_TEXT_CAPS, iValue);
195: break;
196:
197: case CLIPCAPS:
198:
199: ComplexDeviceCapsLine (buf, gaClipCaps, MAX_CLIP_CAPS, iValue);
200: break;
201:
202: case RASTERCAPS:
203:
204: ComplexDeviceCapsLine (buf, gaRasterCaps, MAX_RASTER_CAPS, iValue);
205: break;
206:
207: default:
208:
209: wsprintf(buf, gaCaps[arrayIndex].szValue, iValue);
210:
211: SendDlgItemMessage (ghwndDevCaps, DID_LISTBOX, LB_INSERTSTRING,
212: (UINT)-1, (LONG) buf);
213: break;
214: }
215: }
216:
217:
218:
219: /******************************************************************************\
220: *
221: * FUNCTION: ComplexDeviceCapsLine
222: *
223: * INPUTS: pbuf - pointer to buffer containing a cap-type
224: * string
225: * pLkUp - pointer to a CAPSLOOKUP table
226: * iMaxEntries - # of enries in table pointed at by pLkUp
227: * iValue - an integer containing 1+ bit-value flags.
228: *
229: * COMMENTS: This function is used to expand an int containing
230: * multiple bit-values into a set of strings which are
231: * inserted into the DevCapsDlg listbox. The iValue
232: * parameter is checked against each iIndex entry in the
233: * CAPSLOOKUP table pointed at by pLkUp, and when matches
234: * are found the corresponding (lpszValue) string is
235: * inserted.
236: *
237: * The buffer pointed to by pbuf will be destroyed.
238: *
239: \******************************************************************************/
240:
241: void ComplexDeviceCapsLine (char *pbuf, CAPSLOOKUP *pLkUp, int iMaxEntries,
242: int iValue)
243: {
244: int i;
245: BOOL bNewLine = FALSE;
246:
247: for (i = 0; i < iMaxEntries; i++)
248:
249: if (iValue & (pLkUp + i)->iValue)
250: {
251: if (bNewLine)
252: {
253: //
254: // Keep the first symbolic constant on the same line as the
255: // cap type, eg: "TECHNOLOGY: DT_RASDISPLAY".
256: //
257:
258: strcpy (pbuf, BLANKS);
259: strcat (pbuf, (pLkUp + i)->szValue);
260: }
261: else
262: {
263: //
264: // Put symbolic constant on new line, eg:
265: // " DT_RASPRINTER".
266: //
267:
268: strcat (pbuf, (pLkUp + i)->szValue);
269: bNewLine = TRUE;
270: }
271: SendDlgItemMessage (ghwndDevCaps, DID_LISTBOX, LB_INSERTSTRING,
272: (UINT)-1, (LONG) pbuf);
273: }
274: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.