home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / PRINTDC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  3.0 KB  |  91 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1992, 1993 by Borland International
  3. //   source\owl\dc.cpp
  4. //   Implementation of TPrintDC
  5. //----------------------------------------------------------------------------
  6. #include <owl\owlpch.h>
  7. #include <owl\dc.h>
  8.  
  9. #if defined(__WIN32__)
  10.   extern "C" {
  11.     int  WINAPI DeviceCapabilitiesExA(LPCSTR, LPCSTR, LPCSTR, WORD,
  12.                                       LPSTR, CONST DEVMODEA*);
  13.     int  WINAPI DeviceCapabilitiesExW(LPCWSTR, LPCWSTR, LPCWSTR, WORD,
  14.                                       LPWSTR, CONST DEVMODEW*);
  15.     #if defined(UNICODE)
  16.       #define DeviceCapabilitiesEx  DeviceCapabilitiesExW
  17.     #else
  18.       #define DeviceCapabilitiesEx  DeviceCapabilitiesExA
  19.     #endif // !UNICODE
  20.   }
  21.   typedef int (WINAPI* DeviceCapabilitiesFcn)(LPCSTR, LPCSTR, WORD, LPSTR, CONST DEVMODEA*);
  22.   #define PROC_DEVICECAPABILITIES MAKEINTRESOURCE(91)
  23. #else
  24.   typedef DWORD (CALLBACK* DeviceCapabilitiesFcn)(LPCSTR, LPCSTR, WORD, LPSTR, const DEVMODE far*);
  25. #endif
  26.  
  27. TPrintDC::TPrintDC(HDC handle, TAutoDelete autoDelete) 
  28.   : TCreatedDC(handle, autoDelete)
  29. {
  30.   DocInfo.cbSize = sizeof(DocInfo);
  31. }
  32.  
  33. TPrintDC::TPrintDC(const char far* driver, const char far* device,
  34.                    const char far* output, const DEVMODE far* initData)
  35.   : TCreatedDC(driver, device, output, initData)
  36. {
  37.   DocInfo.cbSize = sizeof(DocInfo);
  38. }
  39.  
  40. DWORD
  41. TPrintDC::DeviceCapabilities(const char far* driver, 
  42.                              const char far* device, 
  43.                              const char far* port,
  44.                              int capability, 
  45.                              char far* output,
  46.                              LPDEVMODE devmode)
  47. {
  48.   //
  49.   // DeviceCapabilitiesEx not functional in this Win32 (NT) release
  50.   //
  51.   #if 0 && defined(__WIN32__)
  52.     return ::DeviceCapabilitiesEx(driver, device, port, capability, output, devmode);
  53.  
  54.   //
  55.   // DeviceCapabilities missing in Win32s
  56.   //
  57.   #elif 0 && defined(__WIN32__)
  58.     return ::DeviceCapabilities(device, port, (uint16)capability, output, devmode);
  59.  
  60.  
  61.   //
  62.   // Hand call DeviceCapabilities due to Win32s missing function!
  63.   //
  64.   #else
  65.     DWORD caps = 0;
  66.     #if defined(__WIN32__)
  67.       //
  68.       // Try the Win32 DeviceCapabilitiesEx function
  69.       //
  70.       caps = ::DeviceCapabilitiesEx(driver, device, port, (WORD)capability, output, devmode);
  71.       if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
  72.         return caps;
  73.     #endif
  74.  
  75.     //
  76.     // Locate & call the DeviceCapabilities function within the printer driver
  77.     // itself.
  78.     //
  79.     HINSTANCE driverInst = ::LoadLibrary(driver);
  80.  
  81.     if (driverInst) {
  82.       DeviceCapabilitiesFcn deviceCapabilities = 
  83.          (DeviceCapabilitiesFcn)::GetProcAddress(driverInst, PROC_DEVICECAPABILITIES);
  84.       if (deviceCapabilities)
  85.         caps = deviceCapabilities(device, port, (WORD)capability, output, devmode);
  86.       ::FreeLibrary(driverInst);
  87.     }
  88.     return caps;
  89.   #endif
  90. }
  91.