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