Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to check if the current printer is ready to print in color Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-May-03
Category
Reporting /Printing
Language
Delphi 2.x
Views
182
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

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  
27  function IsColorPrinter: bool;
28  var
29    Device: array[0..MAX_PATH] of char;
30    Driver: array[0..MAX_PATH] of char;
31    Port: array[0..MAX_PATH] of char;
32    hDMode: THandle;
33    PDMode: PDEVMODE;
34  begin
35    result := False;
36    Printer.PrinterIndex := Printer.PrinterIndex;
37    Printer.GetPrinter(Device, Driver, Port, hDMode);
38    if hDMode <> 0 then
39    begin
40      pDMode := GlobalLock(hDMode);
41      if pDMode <> nil then
42      begin
43        if ((pDMode^.dmFields and dm_Color) = dm_Color) then
44        begin
45          result := True;
46        end;
47        GlobalUnlock(hDMode);
48      end;
49    end;
50  end;
51  
52  function SetPrinterColorMode(InColor: bool): bool;
53  var
54    Device: array[0..MAX_PATH] of char;
55    Driver: array[0..MAX_PATH] of char;
56    Port: array[0..MAX_PATH] of char;
57    hDMode: THandle;
58    PDMode: PDEVMODE;
59  begin
60    result := False;
61    Printer.PrinterIndex := Printer.PrinterIndex;
62    Printer.GetPrinter(Device, Driver, Port, hDMode);
63    if hDMode <> 0 then
64    begin
65      pDMode := GlobalLock(hDMode);
66      if pDMode <> nil then
67      begin
68        if (pDMode^.dmFields and dm_Color) = dm_Color then
69        begin
70          if (InColor) then
71          begin
72            pDMode^.dmColor := DMCOLOR_COLOR;
73          end
74          else
75          begin
76            pDMode^.dmColor := DMCOLOR_MONOCHROME;
77          end;
78          result := True;
79        end;
80        GlobalUnlock(hDMode);
81        Printer.PrinterIndex := Printer.PrinterIndex;
82      end;
83    end;
84  end;



Solve 3:

It is usually better to use DeviceCapabilities to examine what the printer 
supports. Unfortunately this will only work on Win2K and XP, not on older platforms.

85  uses
86    printers, winspool;
87  
88  function PrinterSupportsColor: Boolean;
89  var
90    Device, Driver, Port: array[0..255] of Char;
91    hDevMode: THandle;
92  begin
93    Printer.GetPrinter(Device, Driver, Port, hDevmode);
94    Result := WinSpool.DeviceCapabilities(Device, Port, DC_COLORDEVICE, nil, nil) <> 
95  0;
96  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC