Author: Jonas Bilinkevicius
How can I find out whether the current printer is ready to print in colour, rather
than just capable of printing in colour?
Answer:
Solve 1:
This works for some but not all printers, depending on the driver capabilities:
1 { ... }
2 var
3 Dev, Drv, Prt: array[0..255] of Char;
4 DM1: PDeviceMode;
5 DM2: PDeviceMode;
6 Sz: Integer;
7 DevM: THandle;
8 begin
9 Printer.PrinterIndex := -1;
10 Printer.GetPrinter(Dev, Drv, Prt, DevM);
11 DM1 := nil;
12 DM2 := nil;
13 Sz := DocumentProperties(0, 0, Dev, DM1^, DM2^, 0);
14 GetMem(DM1, Sz);
15 DocumentProperties(0, 0, Dev, DM1^, DM2^, DM_OUT_BUFFER);
16 if DM1^.dmColor > 1 then
17 Label1.Caption := Dev + ': Color'
18 else
19 Label1.Caption := Dev + ': Black and White';
20 if DM1^.dmFields and DM_Color <> 0 then
21 Label2.Caption := 'Printer supports color printing'
22 else
23 Label2.Caption := 'Printer does not support color printing';
24 FreeMem(DM1);
25 end;
Solve 2:
26 function IsColorPrinter: bool;
27 var
28 Device: array[0..MAX_PATH] of char;
29 Driver: array[0..MAX_PATH] of char;
30 Port: array[0..MAX_PATH] of char;
31 hDMode: THandle;
32 PDMode: PDEVMODE;
33 begin
34 result := False;
35 Printer.PrinterIndex := Printer.PrinterIndex;
36 Printer.GetPrinter(Device, Driver, Port, hDMode);
37 if hDMode <> 0 then
38 begin
39 pDMode := GlobalLock(hDMode);
40 if pDMode <> nil then
41 begin
42 if ((pDMode^.dmFields and dm_Color) = dm_Color) then
43 begin
44 result := True;
45 end;
46 GlobalUnlock(hDMode);
47 end;
48 end;
49 end;
50
51 function SetPrinterColorMode(InColor: bool): bool;
52 var
53 Device: array[0..MAX_PATH] of char;
54 Driver: array[0..MAX_PATH] of char;
55 Port: array[0..MAX_PATH] of char;
56 hDMode: THandle;
57 PDMode: PDEVMODE;
58 begin
59 result := False;
60 Printer.PrinterIndex := Printer.PrinterIndex;
61 Printer.GetPrinter(Device, Driver, Port, hDMode);
62 if hDMode <> 0 then
63 begin
64 pDMode := GlobalLock(hDMode);
65 if pDMode <> nil then
66 begin
67 if (pDMode^.dmFields and dm_Color) = dm_Color then
68 begin
69 if (InColor) then
70 begin
71 pDMode^.dmColor := DMCOLOR_COLOR;
72 end
73 else
74 begin
75 pDMode^.dmColor := DMCOLOR_MONOCHROME;
76 end;
77 result := True;
78 end;
79 GlobalUnlock(hDMode);
80 Printer.PrinterIndex := Printer.PrinterIndex;
81 end;
82 end;
83 end;
|