1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
{
Author: Olivier Guilbaud
*****************************************************************************
This file is part of the Printer4Lazarus package
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Abstract:
This unit provide an access at Printers spool and other functions for manage
the printers on Win32
Documentations
- Wine project
- Microsoft MSDN Web
}
unit WinUtilPrn;
{$mode objfpc}{$H+}
interface
{$IFNDEF MSWindows}
{$FATAL This unit is reserved to Win32/Win64}
{$ENDIF}
uses
Windows, Types, Classes, SysUtils, LCLType, Printers;
const
{$i winutilprnconst.inc}
LibWinSpool = 'winspool.drv';
const
Win32Orientations: array [TPrinterOrientation] of SHORT = (
DMORIENT_PORTRAIT, DMORIENT_LANDSCAPE, DMORIENT_PORTRAIT, DMORIENT_LANDSCAPE);
type
TFcntHook = function(Wnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): UINT_PTR; stdcall;
// todo: remove when fpc will be released with them
{$ifndef win64}
{$packrecords 1}
{$endif}
tagPSD = record
lStructSize: DWORD;
hWndOwner: HWND;
hDevMode: HGLOBAL;
hDevNames: HGLOBAL;
Flags: DWORD;
ptPaperSize: TPOINT;
rtMinMargin: TRECT;
rtMargin: TRECT;
hInstance: HINST;
lCustData: LPARAM;
lpfnPageSetupHook: TFcntHook;
lpfnPagePaintHook: TFcntHook;
lpPageSetupTemplateName: PChar;
hPageSetupTemplate: HGLOBAL;
end;
PtagPSD = ^tagPSD;
tagPD = record
lStructSize: DWORD;
hWndOwner: HWND;
hDevMode: HGLOBAL;
hDevNames: HGLOBAL;
hDC: HDC;
Flags: DWORD;
nFromPage: word;
nToPage: word;
nMinPage: word;
nMaxPage: word;
nCopies: word;
hInstance: HINST;
lCustData: LPARAM;
lpfnPrintHook: TFcntHook;
lpfnSetupHook: TFcntHook;
lpPrintTemplateName: PChar;
lpSetupTemplateName: PChar;
hPrintTemplate: HGLOBAL;
hSetupTemplate: HGLOBAL;
end;
PtagPD = ^tagPD;
{
_PRINTER_DEFAULTSA = record
pDatatype : LPSTR;
pDevMode : LPDEVMODE;
DesiredAccess : ACCESS_MASK;
end;
PRINTER_DEFAULTSA = _PRINTER_DEFAULTSA;
PPRINTER_DEFAULTSA = ^_PRINTER_DEFAULTSA;
LPPRINTER_DEFAULTSA = ^_PRINTER_DEFAULTSA;
}
_PRINTER_DEFAULTSW = record
pDatatype: pwidechar;
pDevMode: LPDEVMODEW;
DesiredAccess: ACCESS_MASK;
end;
LPPRINTER_DEFAULTSW = ^_PRINTER_DEFAULTSW;
_PRINTER_INFO_2A = record
pServerName : LPTSTR;
pPrinterName : LPTSTR;
pShareName : LPTSTR;
pPortName : LPTSTR;
pDriverName : LPTSTR;
pComment : LPTSTR;
pLocation : LPTSTR;
pDevMode : LPDEVMODE;
pSepFile : LPTSTR;
pPrintProcessor : LPTSTR;
pDatatype : LPTSTR;
pParameters : LPTSTR;
pSecurityDescriptor : PSECURITY_DESCRIPTOR;
Attributes : DWORD;
Priority : DWORD;
DefaultPriority : DWORD;
StartTime : DWORD;
UntilTime : DWORD;
Status : DWORD;
cJobs : DWORD;
AveragePPM : DWORD;
end;
PRINTER_INFO_2A = _PRINTER_INFO_2A;
PPRINTER_INFO_2A = ^_PRINTER_INFO_2A;
LPPRINTER_INFO_2A = ^_PRINTER_INFO_2A;
PRINTER_INFO_2 = PRINTER_INFO_2A;
PPRINTER_INFO_2 = ^PRINTER_INFO_2;
LPPRINTER_INFO_2 = ^PRINTER_INFO_2;
_PRINTER_INFO_2W = record
pServerName : LPWSTR;
pPrinterName : LPWSTR;
pShareName : LPWSTR;
pPortName : LPWSTR;
pDriverName : LPWSTR;
pComment : LPWSTR;
pLocation : LPWSTR;
pDevMode : LPDEVMODEW;
pSepFile : LPWSTR;
pPrintProcessor : LPWSTR;
pDatatype : LPWSTR;
pParameters : LPWSTR;
pSecurityDescriptor : PSECURITY_DESCRIPTOR;
Attributes : DWORD;
Priority : DWORD;
DefaultPriority : DWORD;
StartTime : DWORD;
UntilTime : DWORD;
Status : DWORD;
cJobs : DWORD;
AveragePPM : DWORD;
end;
PRINTER_INFO_2W = _PRINTER_INFO_2W;
PPRINTER_INFO_2W = ^_PRINTER_INFO_2W;
LPPRINTER_INFO_2W = ^_PRINTER_INFO_2W;
//PRINTER_INFO_2 = PRINTER_INFO_2W;
//PPRINTER_INFO_2 = ^PRINTER_INFO_2;
//LPPRINTER_INFO_2 = ^PRINTER_INFO_2;
_PRINTER_INFO_4A = record
pPrinterName : LPSTR;
pServerName : LPSTR;
Attributes : DWORD;
end;
PRINTER_INFO_4A = _PRINTER_INFO_4A;
PPRINTER_INFO_4A = ^_PRINTER_INFO_4A;
LPPRINTER_INFO_4A = ^_PRINTER_INFO_4A;
PRINTER_INFO_4 = PRINTER_INFO_4A;
PPRINTER_INFO_4 = ^PRINTER_INFO_4;
LPPRINTER_INFO_4 = ^PRINTER_INFO_4;
_PRINTER_INFO_4W = record
pPrinterName : LPWSTR;
pServerName : LPWSTR;
Attributes : DWORD;
end;
PRINTER_INFO_4W = _PRINTER_INFO_4W;
PPRINTER_INFO_4W = ^_PRINTER_INFO_4W;
LPPRINTER_INFO_4W = ^_PRINTER_INFO_4W;
//PRINTER_INFO_4 = PRINTER_INFO_4W;
//PPRINTER_INFO_4 = ^PRINTER_INFO_4;
//LPPRINTER_INFO_4 = ^PRINTER_INFO_4;
type
{ TPrinterDevice }
TPrinterDevice = class
public
Name: string;
Driver: string;
Device: string;
Port: string;
DefaultPaperName: string;
DefaultPaper: Short;
DefaultBin: short;
DevModeW: PDeviceModeW;
DevModeSize: integer;
destructor Destroy; override;
end;
function DeviceCapabilities(pDevice, pPort: PChar; fwCapability: word;
pOutput: PChar; DevMode: PDeviceMode): integer; stdcall; external LibWinSpool Name 'DeviceCapabilitiesA';
function DeviceCapabilitiesW(pDevice, pPort: PWideChar; fwCapability: word;
pOutput: PWideChar; DevMode: PDeviceModeW): integer; stdcall; external LibWinSpool Name 'DeviceCapabilitiesW';
function GetProfileString(lpAppName: PChar; lpKeyName: PChar; lpDefault: PChar;
lpReturnedString: PChar; nSize: DWORD): DWORD; stdcall; external 'kernel32' Name 'GetProfileStringA';
//function PrintDlg(lppd: PtagPD): BOOL; stdcall; external 'comdlg32.dll' Name 'PrintDlgA';
function PrintDlgW(lppd: PTagPD): BOOL; stdcall; external 'comdlg32.dll' name 'PrintDlgW';
//function PageSetupDlg(lppd: PtagPSD): BOOL; stdcall; external 'comdlg32.dll' Name 'PageSetupDlgA';
function PageSetupDlgW(lppd: PtagPSD): BOOL; stdcall; external 'comdlg32.dll' Name 'PageSetupDlgW';
function CommDlgExtendedError: DWORD; stdcall; external 'comdlg32.dll' Name 'CommDlgExtendedError';
//function CreateIC(lpszDriver, lpszDevice, lpszOutput: PChar; lpdvmInit: PDeviceMode): HDC; stdcall; external 'gdi32.dll' Name 'CreateICA';
function CreateICW(lpszDriver, lpszDevice, lpszOutput: pwidechar; lpdvmInit: PDeviceModeW): HDC; stdcall; external 'gdi32.dll' Name 'CreateICW';
//function CreateDC(lpszDriver, lpszDevice, lpszOutput: PChar; lpdvmInit: PDeviceMode): HDC; stdcall; external 'gdi32.dll' Name 'CreateDCA';
function CreateDCW(lpszDriver, lpszDevice, lpszOutput: pwidechar; lpdvmInit: PDeviceModeW): HDC; stdcall; external 'gdi32.dll' Name 'CreateDCW';
function DeleteDC(DC: HDC): BOOL; stdcall; external 'gdi32.dll' Name 'DeleteDC';
function StartDoc(DC: HDC; Inf: PDocInfo): integer; stdcall; external 'gdi32.dll' Name 'StartDocA';
function EndDoc(DC: HDC): integer; stdcall; external 'gdi32.dll' Name 'EndDoc';
function StartPage(DC: HDC): integer; stdcall; external 'gdi32.dll' Name 'StartPage';
function EndPage(DC: HDC): integer; stdcall; external 'gdi32.dll' Name 'EndPage';
function AbortDoc(DC: HDC): integer; stdcall; external 'gdi32.dll' Name 'AbortDoc';
function GlobalFree(HMem: HGlobal): HGlobal; stdcall; external 'kernel32.dll' Name 'GlobalFree';
// todo: remove when WinSpool.pp will be released with fpc
//function OpenPrinter(_para1:LPSTR; _para2:PHANDLE; _para3:LPPRINTER_DEFAULTSA):BOOL;stdcall; external LibWinSpool name 'OpenPrinterA';
function OpenPrinterW(_para1:pwidechar; _para2:PHANDLE; _para3:LPPRINTER_DEFAULTSW):BOOL;stdcall; external LibWinSpool name 'OpenPrinterW';
function ClosePrinter(_para1:HANDLE):BOOL;stdcall; external LibWinSpool Name 'ClosePrinter';
//function DocumentProperties(_para1:HWND; _para2:HANDLE; _para3:LPSTR; _para4:PDEVMODE; _para5:PDEVMODE; _para6:DWORD):LONG;stdcall; external LibWinSpool name 'DocumentPropertiesA';
function DocumentPropertiesW(_para1:HWND; _para2:HANDLE; _para3:pwidechar; _para4:PDEVMODEW; _para5:PDEVMODEW; _para6:DWORD):LONG;stdcall; external LibWinSpool name 'DocumentPropertiesW';
//function EnumPrinters(_para1:DWORD; _para2:LPSTR; _para3:DWORD; _para4:PBYTE; _para5:DWORD; _para6:PDWORD; _para7:PDWORD):BOOL;stdcall; external LibWinSpool name 'EnumPrintersA';
function EnumPrintersW(_para1:DWORD; _para2:Pwidechar; _para3:DWORD; _para4:PBYTE; _para5:DWORD; _para6:PDWORD; _para7:PDWORD):BOOL;stdcall; external LibWinSpool name 'EnumPrintersW';
function GetPrinter(_para1:HANDLE; _para2:DWORD; _para3:PBYTE; _para4:DWORD; _para5:PDWORD):BOOL;stdcall; external LibWinSpool name 'GetPrinterA';
function StartDocPrinter(hPrinter: THANDLE; Level: DWORD; DocInfo: PByte): DWORD; stdcall; external LibWinSpool Name 'StartDocPrinterA';
function StartPagePrinter(_para1:HANDLE):BOOL;stdcall; external LibWinSpool name 'StartPagePrinter';
function EndDocPrinter(hprinter: THANDLE): BOOL; stdcall; external LibWinSpool Name 'EndDocPrinter';
function EndPagePrinter(hprinter: THANDLE): BOOL; stdcall; external LibWinSpool Name 'EndPagePrinter';
function AbortPrinter(hPrinter: THANDLE): BOOL; stdcall; external LibWinSpool Name 'AbortPrinter';
function WritePrinter(hPrinter: THANDLE; Buffer: Pointer; Count: DWord; Written: PDWORD): BOOL; stdcall; external LibWinSpool Name 'WritePrinter';
function ResetDCW(DC: HDC; const p2: TDeviceModeW):HDC; stdcall; external 'gdi32.dll' name 'ResetDCW';
implementation
{ TPrinterDevice }
destructor TPrinterDevice.Destroy;
begin
ReallocMem(DevModeW, 0);
inherited Destroy;
end;
end.
|