home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / PRINTDC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.2 KB  |  126 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Implementation of TPrintDC
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_DC_H)
  11. # include <owl/dc.h>
  12. #endif
  13. #if !defined(OWL_MODULE_H)
  14. # include <owl/module.h>
  15. #endif
  16.  
  17. OWL_DIAGINFO;
  18.  
  19. //
  20. // Supply missing function definition and macros for newer Win32 function
  21. //
  22. #if defined(BI_PLAT_WIN32)
  23.   extern "C" {
  24.     int  WINAPI DeviceCapabilitiesExA(LPCSTR, LPCSTR, LPCSTR, WORD,
  25.                                       LPSTR, CONST DEVMODEA*);
  26.     int  WINAPI DeviceCapabilitiesExW(LPCWSTR, LPCWSTR, LPCWSTR, WORD,
  27.                                       LPWSTR, CONST DEVMODEW*);
  28.     #if defined(UNICODE)
  29.       #define DeviceCapabilitiesEx  DeviceCapabilitiesExW
  30.     #else
  31.       #define DeviceCapabilitiesEx  DeviceCapabilitiesExA
  32.     #endif // !UNICODE
  33.   }
  34.   #define PROC_DEVICECAPABILITIES MAKEINTRESOURCE(91)
  35. #endif
  36.  
  37. //
  38. //
  39. //
  40. class TPrinterDriverLibrary : public TModule {
  41.   public:
  42.     TPrinterDriverLibrary(const char far* drvName);
  43.  
  44. #if defined(BI_PLAT_WIN32)
  45.     TModuleProc5<int,LPCSTR,LPCSTR,WORD,LPSTR,const DEVMODEA*> DeviceCapabilities;
  46. #else
  47.     TModuleProc5<uint32,LPCSTR,LPCSTR,WORD,LPSTR,const DEVMODE far*> DeviceCapabilities;
  48. #endif
  49. };
  50.  
  51. //
  52. //
  53. //
  54. TPrinterDriverLibrary::TPrinterDriverLibrary(const char far* drvName)
  55. :
  56.   TModule(drvName, true, true),
  57.   DeviceCapabilities(*this,PROC_DEVICECAPABILITIES)
  58. {
  59. }
  60.  
  61. //
  62. //
  63. //
  64. TPrintDC::TPrintDC(HDC handle, TAutoDelete autoDelete)
  65. :
  66.   TCreatedDC(handle, autoDelete)
  67. {
  68.   memset(&DocInfo, 0, sizeof(DocInfo));
  69.   DocInfo.cbSize = sizeof(DocInfo);
  70.   DocInfo.lpszOutput = "";
  71. #if defined(BI_PLAT_WIN32)
  72.   DocInfo.lpszDatatype = "";
  73. #endif
  74. }
  75.  
  76. //
  77. //
  78. //
  79. TPrintDC::TPrintDC(const char far* driver, const char far* device,
  80.                    const char far* output, const DEVMODE far* initData)
  81. :
  82.   TCreatedDC(driver, device, output, initData)
  83. {
  84.   memset(&DocInfo, 0, sizeof(DocInfo));
  85.   DocInfo.cbSize = sizeof(DocInfo);
  86.   DocInfo.lpszOutput = "";
  87. #if defined(BI_PLAT_WIN32)
  88.   DocInfo.lpszDatatype = "";
  89. #endif
  90. }
  91.  
  92. //
  93. //
  94. //
  95. uint32
  96. TPrintDC::DeviceCapabilities(const char far* driver,
  97.                              const char far* device,
  98.                              const char far* port,
  99.                              int capability,
  100.                              char far* output,
  101.                              LPDEVMODE devmode)
  102. {
  103.   // Hand call DeviceCapabilities due to Win32s missing function!
  104.   //
  105.   uint32 caps = 0;
  106.  
  107. #if defined(BI_PLAT_WIN32)
  108.   // Try the Win32 DeviceCapabilitiesEx function
  109.   //
  110.   caps = ::DeviceCapabilitiesEx(driver, device, port, (uint16)capability, output, devmode);
  111.   if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  112.     return caps;
  113. #endif
  114.  
  115.   // Locate & call the DeviceCapabilities function within the printer driver
  116.   // itself.
  117.   //
  118.   try {
  119.     TPrinterDriverLibrary driverLib(driver);
  120.     caps = driverLib.DeviceCapabilities(device, port, (uint16)capability, output, devmode);
  121.   }
  122.   catch (...) {
  123.   }
  124.   return caps;
  125. }
  126.