PrintingServicesWin32.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // Copyright (C) 2005 Novell, Inc. http://www.novell.com
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Author:
  24. //
  25. // Jordi Mas i Hernandez, [email protected]
  26. //
  27. using System.Runtime.InteropServices;
  28. using System.Collections;
  29. using System.Drawing.Printing;
  30. using System.ComponentModel;
  31. using System.Text;
  32. namespace System.Drawing.Printing
  33. {
  34. internal class PrintingServicesWin32 : PrintingServices
  35. {
  36. private string printer_name;
  37. private bool is_printer_valid;
  38. internal PrintingServicesWin32 ()
  39. {
  40. }
  41. internal override bool IsPrinterValid(string printer, bool force)
  42. {
  43. if (printer == null | printer == String.Empty)
  44. return false;
  45. if (!force && this.printer_name != null && String.Intern(this.printer_name).Equals(printer))
  46. return is_printer_valid;
  47. int ret = Win32DocumentProperties (IntPtr.Zero, IntPtr.Zero, printer, IntPtr.Zero, IntPtr.Zero, 0);
  48. is_printer_valid = (ret > 0);
  49. this.printer_name = printer;
  50. return is_printer_valid;
  51. }
  52. internal override void LoadPrinterSettings (string printer, PrinterSettings settings)
  53. {
  54. int ret;
  55. DEVMODE devmode;
  56. IntPtr hPrn = IntPtr.Zero;
  57. IntPtr ptr_dev = IntPtr.Zero;
  58. settings.maximum_copies = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_COPIES, IntPtr.Zero, IntPtr.Zero);
  59. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_DUPLEX, IntPtr.Zero, IntPtr.Zero);
  60. settings.can_duplex = (ret == 1) ? true : false;
  61. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_COLORDEVICE, IntPtr.Zero, IntPtr.Zero);
  62. settings.supports_color = (ret == 1) ? true : false;
  63. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ORIENTATION, IntPtr.Zero, IntPtr.Zero);
  64. if (ret != -1)
  65. settings.landscape_angle = ret;
  66. try {
  67. Win32OpenPrinter (printer, out hPrn, IntPtr.Zero);
  68. ret = Win32DocumentProperties (IntPtr.Zero, hPrn, null, IntPtr.Zero, IntPtr.Zero, 2);
  69. if (ret < 0)
  70. return;
  71. ptr_dev = Marshal.AllocHGlobal (ret);
  72. ret = Win32DocumentProperties (IntPtr.Zero, hPrn, null, ptr_dev, IntPtr.Zero, 2);
  73. devmode = (DEVMODE) Marshal.PtrToStructure (ptr_dev, typeof(DEVMODE));
  74. foreach (PaperSize paper_size in settings.PaperSizes) {
  75. if ((int) paper_size.Kind == devmode.dmPaperSize) {
  76. settings.DefaultPageSettings.PaperSize = paper_size;
  77. break;
  78. }
  79. }
  80. foreach (PaperSource paper_source in settings.PaperSources) {
  81. if ((int) paper_source.Kind == devmode.dmDefaultSource) {
  82. settings.DefaultPageSettings.PaperSource = paper_source;
  83. break;
  84. }
  85. }
  86. }
  87. finally {
  88. Win32ClosePrinter (hPrn);
  89. if (ptr_dev != IntPtr.Zero)
  90. Marshal.FreeHGlobal (ptr_dev);
  91. }
  92. }
  93. internal override void LoadPrinterResolutions (string printer, PrinterSettings settings)
  94. {
  95. int ret;
  96. IntPtr ptr, buff = IntPtr.Zero;
  97. settings.PrinterResolutions.Clear ();
  98. LoadDefaultResolutions (settings.PrinterResolutions);
  99. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ENUMRESOLUTIONS, IntPtr.Zero, IntPtr.Zero);
  100. if (ret == -1)
  101. return;
  102. ptr = buff = Marshal.AllocHGlobal (ret * 2 * Marshal.SizeOf (buff));
  103. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_ENUMRESOLUTIONS, buff, IntPtr.Zero);
  104. int x, y;
  105. if (ret != -1) {
  106. for (int i = 0; i < ret; i++) {
  107. x = Marshal.ReadInt32 (ptr);
  108. ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (x));
  109. y = Marshal.ReadInt32 (ptr);
  110. ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (y));
  111. settings.PrinterResolutions.Add (new PrinterResolution
  112. (x,y, PrinterResolutionKind.Custom));
  113. }
  114. }
  115. Marshal.FreeHGlobal (buff);
  116. }
  117. internal override void LoadPrinterPaperSizes (string printer, PrinterSettings settings)
  118. {
  119. int items, ret;
  120. IntPtr ptr_names, buff_names = IntPtr.Zero;
  121. IntPtr ptr_sizes, buff_sizes = IntPtr.Zero;
  122. IntPtr ptr_sizes_enum, buff_sizes_enum = IntPtr.Zero;
  123. string name;
  124. settings.PaperSizes.Clear ();
  125. items = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, IntPtr.Zero, IntPtr.Zero);
  126. if (items == -1)
  127. return;
  128. try {
  129. ptr_sizes = buff_sizes = Marshal.AllocHGlobal (items * 2 * 4);
  130. ptr_names = buff_names = Marshal.AllocHGlobal (items * 64 * 2);
  131. ptr_sizes_enum = buff_sizes_enum = Marshal.AllocHGlobal (items * 2);
  132. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERSIZE, buff_sizes, IntPtr.Zero);
  133. if (ret == -1) {
  134. // the finally clause will free the unmanaged memory before returning
  135. return;
  136. }
  137. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERS, buff_sizes_enum, IntPtr.Zero);
  138. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_PAPERNAMES, buff_names, IntPtr.Zero);
  139. int x, y;
  140. PaperSize ps;
  141. PaperKind kind;
  142. for (int i = 0; i < ret; i++) {
  143. x = Marshal.ReadInt32 (ptr_sizes, i * 4);
  144. y = Marshal.ReadInt32 (ptr_sizes, (i + 1) * 4);
  145. x = PrinterUnitConvert.Convert (x, PrinterUnit.TenthsOfAMillimeter,
  146. PrinterUnit.Display);
  147. y = PrinterUnitConvert.Convert (y, PrinterUnit.TenthsOfAMillimeter,
  148. PrinterUnit.Display);
  149. name = Marshal.PtrToStringUni (ptr_names);
  150. ptr_names = new IntPtr (ptr_names.ToInt64 () + 64 * 2);
  151. kind = (PaperKind) Marshal.ReadInt16 (ptr_sizes_enum);
  152. ptr_sizes_enum = new IntPtr (ptr_sizes_enum.ToInt64 () + 2);
  153. ps = new PaperSize (name, x,y);
  154. ps.SetKind (kind);
  155. settings.PaperSizes.Add (ps);
  156. }
  157. }
  158. finally {
  159. if (buff_names != IntPtr.Zero)
  160. Marshal.FreeHGlobal (buff_names);
  161. if (buff_sizes != IntPtr.Zero)
  162. Marshal.FreeHGlobal (buff_sizes);
  163. if (buff_sizes_enum != IntPtr.Zero)
  164. Marshal.FreeHGlobal (buff_sizes_enum);
  165. }
  166. }
  167. internal override bool StartDoc (GraphicsPrinter gr, string doc_name, string output_file)
  168. {
  169. DOCINFO di = new DOCINFO ();
  170. int ret;
  171. di.cbSize = Marshal.SizeOf (di);
  172. di.lpszDocName = Marshal.StringToHGlobalUni (doc_name);
  173. di.lpszOutput = IntPtr.Zero;
  174. di.lpszDatatype = IntPtr.Zero;
  175. di.fwType = 0;
  176. ret = Win32StartDoc (gr.Hdc, ref di);
  177. Marshal.FreeHGlobal (di.lpszDocName);
  178. return (ret > 0) ? true : false;
  179. }
  180. internal override void LoadPrinterPaperSources (string printer, PrinterSettings settings)
  181. {
  182. int items, ret;
  183. IntPtr ptr_names, buff_names = IntPtr.Zero;
  184. IntPtr ptr_bins, buff_bins = IntPtr.Zero;
  185. PaperSourceKind kind;
  186. string name;
  187. settings.PaperSources.Clear ();
  188. items = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_BINNAMES, IntPtr.Zero, IntPtr.Zero);
  189. if (items == -1)
  190. return;
  191. try {
  192. ptr_names = buff_names = Marshal.AllocHGlobal (items * 2 * 24);
  193. ptr_bins = buff_bins = Marshal.AllocHGlobal (items * 2);
  194. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_BINNAMES, buff_names, IntPtr.Zero);
  195. if (ret == -1) {
  196. // the finally clause will free the unmanaged memory before returning
  197. return;
  198. }
  199. ret = Win32DeviceCapabilities (printer, null, DCCapabilities.DC_BINS, buff_bins, IntPtr.Zero);
  200. for (int i = 0; i < ret; i++) {
  201. name = Marshal.PtrToStringUni (ptr_names);
  202. kind = (PaperSourceKind) Marshal.ReadInt16 (ptr_bins);
  203. settings.PaperSources.Add (new PaperSource (name, kind));
  204. ptr_names = new IntPtr (ptr_names.ToInt64 () + 24 * 2);
  205. ptr_bins = new IntPtr (ptr_bins.ToInt64 () + 2);
  206. }
  207. }
  208. finally {
  209. if (buff_names != IntPtr.Zero)
  210. Marshal.FreeHGlobal (buff_names);
  211. if (buff_bins != IntPtr.Zero)
  212. Marshal.FreeHGlobal (buff_bins);
  213. }
  214. }
  215. internal override bool StartPage (GraphicsPrinter gr)
  216. {
  217. int ret = Win32StartPage (gr.Hdc);
  218. return (ret > 0) ? true : false;
  219. }
  220. internal override bool EndPage (GraphicsPrinter gr)
  221. {
  222. int ret = Win32EndPage (gr.Hdc);
  223. return (ret > 0) ? true : false;
  224. }
  225. internal override bool EndDoc (GraphicsPrinter gr)
  226. {
  227. int ret = Win32EndDoc (gr.Hdc);
  228. Win32DeleteDC (gr.Hdc);
  229. gr.Graphics.Dispose ();
  230. return (ret > 0) ? true : false;
  231. }
  232. internal override IntPtr CreateGraphicsContext (PrinterSettings settings, PageSettings default_page_settings)
  233. {
  234. IntPtr dc = IntPtr.Zero;
  235. dc = Win32CreateDC (null, settings.PrinterName, null, IntPtr.Zero /* DEVMODE */);
  236. return dc;
  237. }
  238. // Properties
  239. internal override string DefaultPrinter {
  240. get {
  241. StringBuilder name = new StringBuilder (1024);
  242. int length = name.Capacity;
  243. if (Win32GetDefaultPrinter (name, ref length) > 0)
  244. if (this.IsPrinterValid(name.ToString(), false))
  245. return name.ToString ();
  246. return String.Empty;
  247. }
  248. }
  249. internal override PrinterSettings.StringCollection InstalledPrinters {
  250. get {
  251. PrinterSettings.StringCollection col = new PrinterSettings.StringCollection (new string[] {});
  252. PRINTER_INFO printer_info;
  253. uint cbNeeded = 0, printers = 0;
  254. IntPtr ptr, buff;
  255. string s;
  256. // Determine space need it
  257. Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */,
  258. null, 2, IntPtr.Zero, 0, ref cbNeeded, ref printers);
  259. if (cbNeeded <= 0)
  260. return col;
  261. ptr = buff = Marshal.AllocHGlobal ((int) cbNeeded);
  262. try {
  263. // Give us the printer list
  264. Win32EnumPrinters (2 /* PRINTER_ENUM_LOCAL */,
  265. null, 2, buff, (uint)cbNeeded, ref cbNeeded, ref printers);
  266. for (int i = 0; i < printers; i++) {
  267. printer_info = (PRINTER_INFO) Marshal.PtrToStructure (ptr, typeof (PRINTER_INFO));
  268. s = Marshal.PtrToStringUni (printer_info.pPrinterName);
  269. col.Add (s);
  270. ptr = new IntPtr (ptr.ToInt64 () + Marshal.SizeOf (printer_info));
  271. }
  272. }
  273. finally {
  274. Marshal.FreeHGlobal (buff);
  275. }
  276. return col;
  277. }
  278. }
  279. internal override void GetPrintDialogInfo (string printer, ref string port, ref string type, ref string status, ref string comment)
  280. {
  281. IntPtr hPrn;
  282. PRINTER_INFO printer_info = new PRINTER_INFO ();
  283. int needed = 0;
  284. IntPtr ptr;
  285. Win32OpenPrinter (printer, out hPrn, IntPtr.Zero);
  286. if (hPrn == IntPtr.Zero)
  287. return;
  288. Win32GetPrinter (hPrn, 2, IntPtr.Zero, 0, ref needed);
  289. ptr = Marshal.AllocHGlobal (needed);
  290. Win32GetPrinter (hPrn, 2, ptr, needed, ref needed);
  291. printer_info = (PRINTER_INFO) Marshal.PtrToStructure (ptr, typeof (PRINTER_INFO));
  292. Marshal.FreeHGlobal (ptr);
  293. port = Marshal.PtrToStringUni (printer_info.pPortName);
  294. comment = Marshal.PtrToStringUni (printer_info.pComment);
  295. type = Marshal.PtrToStringUni (printer_info.pDriverName);
  296. status = GetPrinterStatusMsg (printer_info.Status);
  297. Win32ClosePrinter (hPrn);
  298. }
  299. private string GetPrinterStatusMsg (uint status)
  300. {
  301. string rslt = string.Empty;
  302. if (status == 0)
  303. return "Ready";
  304. if ((status & (uint) PrinterStatus.PS_PAUSED) != 0) rslt += "Paused; ";
  305. if ((status & (uint) PrinterStatus.PS_ERROR) != 0) rslt += "Error; ";
  306. if ((status & (uint) PrinterStatus.PS_PENDING_DELETION) != 0) rslt += "Pending deletion; ";
  307. if ((status & (uint) PrinterStatus.PS_PAPER_JAM) != 0) rslt += "Paper jam; ";
  308. if ((status & (uint) PrinterStatus.PS_PAPER_OUT) != 0) rslt += "Paper out; ";
  309. if ((status & (uint) PrinterStatus.PS_MANUAL_FEED) != 0) rslt += "Manual feed; ";
  310. if ((status & (uint) PrinterStatus.PS_PAPER_PROBLEM) != 0) rslt += "Paper problem; ";
  311. if ((status & (uint) PrinterStatus.PS_OFFLINE) != 0) rslt += "Offline; ";
  312. if ((status & (uint) PrinterStatus.PS_IO_ACTIVE) != 0) rslt += "I/O active; ";
  313. if ((status & (uint) PrinterStatus.PS_BUSY) != 0) rslt += "Busy; ";
  314. if ((status & (uint) PrinterStatus.PS_PRINTING) != 0) rslt += "Printing; ";
  315. if ((status & (uint) PrinterStatus.PS_OUTPUT_BIN_FULL) != 0) rslt += "Output bin full; ";
  316. if ((status & (uint) PrinterStatus.PS_NOT_AVAILABLE) != 0) rslt += "Not available; ";
  317. if ((status & (uint) PrinterStatus.PS_WAITING) != 0) rslt += "Waiting; ";
  318. if ((status & (uint) PrinterStatus.PS_PROCESSING) != 0) rslt += "Processing; ";
  319. if ((status & (uint) PrinterStatus.PS_INITIALIZING) != 0) rslt += "Initializing; ";
  320. if ((status & (uint) PrinterStatus.PS_WARMING_UP) != 0) rslt += "Warming up; ";
  321. if ((status & (uint) PrinterStatus.PS_TONER_LOW) != 0) rslt += "Toner low; ";
  322. if ((status & (uint) PrinterStatus.PS_NO_TONER) != 0) rslt += "No toner; ";
  323. if ((status & (uint) PrinterStatus.PS_PAGE_PUNT) != 0) rslt += "Page punt; ";
  324. if ((status & (uint) PrinterStatus.PS_USER_INTERVENTION) != 0) rslt += "User intervention; ";
  325. if ((status & (uint) PrinterStatus.PS_OUT_OF_MEMORY) != 0) rslt += "Out of memory; ";
  326. if ((status & (uint) PrinterStatus.PS_DOOR_OPEN) != 0) rslt += "Door open; ";
  327. if ((status & (uint) PrinterStatus.PS_SERVER_UNKNOWN) != 0) rslt += "Server unkown; ";
  328. if ((status & (uint) PrinterStatus.PS_POWER_SAVE) != 0) rslt += "Power save; ";
  329. return rslt;
  330. }
  331. //
  332. // DllImports
  333. //
  334. [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="OpenPrinter", SetLastError=true)]
  335. static extern int Win32OpenPrinter (string pPrinterName, out IntPtr phPrinter, IntPtr pDefault);
  336. [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="GetPrinter", SetLastError=true)]
  337. static extern int Win32GetPrinter (IntPtr hPrinter, int level, IntPtr dwBuf, int size, ref int dwNeeded);
  338. [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="ClosePrinter", SetLastError=true)]
  339. static extern int Win32ClosePrinter (IntPtr hPrinter);
  340. [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="DeviceCapabilities", SetLastError=true)]
  341. static extern int Win32DeviceCapabilities (string device, string port, DCCapabilities cap, IntPtr outputBuffer, IntPtr deviceMode);
  342. [DllImport("winspool.drv", CharSet=CharSet.Unicode, EntryPoint="EnumPrinters", SetLastError=true)]
  343. static extern int Win32EnumPrinters (int Flags, string Name, uint Level, IntPtr pPrinterEnum, uint cbBuf,
  344. ref uint pcbNeeded, ref uint pcReturned);
  345. [DllImport("winspool.drv", EntryPoint="GetDefaultPrinter", CharSet=CharSet.Unicode, SetLastError=true)]
  346. private static extern int Win32GetDefaultPrinter (StringBuilder buffer, ref int bufferSize);
  347. [DllImport("winspool.drv", EntryPoint="DocumentProperties", CharSet=CharSet.Unicode, SetLastError=true)]
  348. private static extern int Win32DocumentProperties (IntPtr hwnd, IntPtr hPrinter, string pDeviceName,
  349. IntPtr pDevModeOutput, IntPtr pDevModeInput, int fMode);
  350. [DllImport("gdi32.dll", EntryPoint="CreateDC")]
  351. static extern IntPtr Win32CreateDC (string lpszDriver, string lpszDevice,
  352. string lpszOutput, IntPtr lpInitData);
  353. [DllImport("gdi32.dll", CharSet=CharSet.Unicode, EntryPoint="StartDoc")]
  354. static extern int Win32StartDoc (IntPtr hdc, [In] ref DOCINFO lpdi);
  355. [DllImport("gdi32.dll", EntryPoint="StartPage")]
  356. static extern int Win32StartPage (IntPtr hDC);
  357. [DllImport("gdi32.dll", EntryPoint="EndPage")]
  358. static extern int Win32EndPage (IntPtr hdc);
  359. [DllImport("gdi32.dll", EntryPoint="EndDoc")]
  360. static extern int Win32EndDoc (IntPtr hdc);
  361. [DllImport("gdi32.dll", EntryPoint="DeleteDC")]
  362. public static extern IntPtr Win32DeleteDC (IntPtr hDc);
  363. //
  364. // Structs
  365. //
  366. [StructLayout (LayoutKind.Sequential)]
  367. internal struct PRINTER_INFO
  368. {
  369. public IntPtr pServerName;
  370. public IntPtr pPrinterName;
  371. public IntPtr pShareName;
  372. public IntPtr pPortName;
  373. public IntPtr pDriverName;
  374. public IntPtr pComment;
  375. public IntPtr pLocation;
  376. public IntPtr pDevMode;
  377. public IntPtr pSepFile;
  378. public IntPtr pPrintProcessor;
  379. public IntPtr pDatatype;
  380. public IntPtr pParameters;
  381. public IntPtr pSecurityDescriptor;
  382. public uint Attributes;
  383. public uint Priority;
  384. public uint DefaultPriority;
  385. public uint StartTime;
  386. public uint UntilTime;
  387. public uint Status;
  388. public uint cJobs;
  389. public uint AveragePPM;
  390. }
  391. [StructLayout (LayoutKind.Sequential)]
  392. internal struct DOCINFO
  393. {
  394. public int cbSize;
  395. public IntPtr lpszDocName;
  396. public IntPtr lpszOutput;
  397. public IntPtr lpszDatatype;
  398. public int fwType;
  399. }
  400. [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
  401. internal struct DEVMODE
  402. {
  403. [MarshalAs(UnmanagedType.ByValTStr,SizeConst=32)]
  404. public string dmDeviceName;
  405. public short dmSpecVersion;
  406. public short dmDriverVersion;
  407. public short dmSize;
  408. public short dmDriverExtra;
  409. public int dmFields;
  410. public short dmOrientation;
  411. public short dmPaperSize;
  412. public short dmPaperLength;
  413. public short dmPaperWidth;
  414. public short dmScale;
  415. public short dmCopies;
  416. public short dmDefaultSource;
  417. public short dmPrintQuality;
  418. public short dmColor;
  419. public short dmDuplex;
  420. public short dmYResolution;
  421. public short dmTTOption;
  422. public short dmCollate;
  423. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
  424. public string dmFormName;
  425. public short dmLogPixels;
  426. public short dmBitsPerPel;
  427. public int dmPelsWidth;
  428. public int dmPelsHeight;
  429. public int dmDisplayFlags;
  430. public int dmDisplayFrequency;
  431. public int dmICMMethod;
  432. public int dmICMIntent;
  433. public int dmMediaType;
  434. public int dmDitherType;
  435. public int dmReserved1;
  436. public int dmReserved2;
  437. public int dmPanningWidth;
  438. public int dmPanningHeight;
  439. }
  440. // Enums
  441. internal enum DCCapabilities : short
  442. {
  443. DC_FIELDS = 1,
  444. DC_PAPERS = 2,
  445. DC_PAPERSIZE = 3,
  446. DC_MINEXTENT = 4,
  447. DC_MAXEXTENT = 5,
  448. DC_BINS = 6,
  449. DC_DUPLEX = 7,
  450. DC_SIZE = 8,
  451. DC_EXTRA = 9,
  452. DC_VERSION = 10,
  453. DC_DRIVER = 11,
  454. DC_BINNAMES = 12,
  455. DC_ENUMRESOLUTIONS = 13,
  456. DC_FILEDEPENDENCIES = 14,
  457. DC_TRUETYPE = 15,
  458. DC_PAPERNAMES = 16,
  459. DC_ORIENTATION = 17,
  460. DC_COPIES = 18,
  461. DC_BINADJUST = 19,
  462. DC_EMF_COMPLIANT = 20,
  463. DC_DATATYPE_PRODUCED = 21,
  464. DC_COLLATE = 22,
  465. DC_MANUFACTURER = 23,
  466. DC_MODEL = 24,
  467. DC_PERSONALITY = 25,
  468. DC_PRINTRATE = 26,
  469. DC_PRINTRATEUNIT = 27,
  470. DC_PRINTERMEM = 28,
  471. DC_MEDIAREADY = 29,
  472. DC_STAPLE = 30,
  473. DC_PRINTRATEPPM = 31,
  474. DC_COLORDEVICE = 32,
  475. DC_NUP = 33
  476. }
  477. [Flags]
  478. internal enum PrinterStatus : uint
  479. {
  480. PS_PAUSED = 0x00000001,
  481. PS_ERROR = 0x00000002,
  482. PS_PENDING_DELETION = 0x00000004,
  483. PS_PAPER_JAM = 0x00000008,
  484. PS_PAPER_OUT = 0x00000010,
  485. PS_MANUAL_FEED = 0x00000020,
  486. PS_PAPER_PROBLEM = 0x00000040,
  487. PS_OFFLINE = 0x00000080,
  488. PS_IO_ACTIVE = 0x00000100,
  489. PS_BUSY = 0x00000200,
  490. PS_PRINTING = 0x00000400,
  491. PS_OUTPUT_BIN_FULL = 0x00000800,
  492. PS_NOT_AVAILABLE = 0x00001000,
  493. PS_WAITING = 0x00002000,
  494. PS_PROCESSING = 0x00004000,
  495. PS_INITIALIZING = 0x00008000,
  496. PS_WARMING_UP = 0x00010000,
  497. PS_TONER_LOW = 0x00020000,
  498. PS_NO_TONER = 0x00040000,
  499. PS_PAGE_PUNT = 0x00080000,
  500. PS_USER_INTERVENTION = 0x00100000,
  501. PS_OUT_OF_MEMORY = 0x00200000,
  502. PS_DOOR_OPEN = 0x00400000,
  503. PS_SERVER_UNKNOWN = 0x00800000,
  504. PS_POWER_SAVE = 0x01000000
  505. }
  506. }
  507. }