Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

determine if printer can print colored docs

51 views
Skip to first unread message

Christoph Söllner

unread,
May 2, 2003, 4:25:39 AM5/2/03
to
Hi,

I wrote this function, but it always returns
false, even on color printers. maybe someone
could give me a hint, what's wrong?

Function PrinterSupportsColor(WhichOne : Integer): Boolean;
Var
Device, Driver, Port: Array [0..255] of Char;
hDevMode : THandle;
MyPtr : PDevMode;
Begin
//MyDrk is a global var
MyDrk.PrinterIndex := WhichOne;
MyDrk.GetPrinter(Device, Driver, Port, hDevmode);
MyPtr := GlobalLock(hDevMode);
MyPtr.dmFields := MyPtr.dmFields or dm_Color;
//ShowMessage(IntToStr(WhichOne) + ' ' + IntToStr(MyPtr.dmColor));
if (MyPtr^.dmColor = DMCOLOR_COLOR) then
Result := True
else
Result := False;
GlobalUnlock(hDevMode);
End;


Ignacio Vazquez

unread,
May 2, 2003, 9:48:26 AM5/2/03
to
"Christoph Söllner" <mcs...@despammed.com> wrote in message
news:b8ta23$qen$04$1...@news.t-online.com...

> Hi,
>
> I wrote this function, but it always returns
> false, even on color printers. maybe someone
> could give me a hint, what's wrong?

Try using the GetPrinter API function against the Printer global with a
level of 2 and then dereference DEVMODE and look at the dmFields field.

Cheers,
Ignacio

Christoph Söllner

unread,
May 2, 2003, 12:21:52 PM5/2/03
to
Yes, you were right. it works. for all of you,
who might have the same problem, here the source:
Maybe someone out there could rewrite it, it is...
well, kinda quick 'n dirty...

Var
GlobPrinterVar : TPrinter; //Create it in "form.create()".

function GetCurrentPrinterHandle: THandle;
Const
Defaults: TPrinterDefaults = (
pDatatype : nil;
pDevMode : nil;
DesiredAccess : PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER
);
Var
Device, Driver, Port : array[0..255] of char;
hDeviceMode: THandle;
Begin
GlobPrinterVar.GetPrinter(Device, Driver, Port, hDeviceMode);
If not OpenPrinter(@Device, Result, @Defaults) Then ShowMessage('Error in GetPrinterHandle.');
End;

Function PrinterSupportsColor(WhichOne : Integer): Boolean;
Var

hDevMode : THandle;
MyPtr : PDevMode;
pInfo : PPrinterInfo2;
bytesNeeded: DWORD;
hPrinter : THandle;
Begin
MyDrk.PrinterIndex := WhichOne;
hPrinter := GetCurrentPrinterHandle;
try
GetPrinter( hPrinter, 2, Nil, 0, @bytesNeeded );
pInfo := AllocMem( bytesNeeded );
try
GetPrinter( hPrinter, 2, pInfo, bytesNeeded, @bytesNeeded );
Result := True;
MyPtr := pInfo^.pDevMode;
finally
FreeMem( pInfo );
end;
finally
ClosePrinter( hPrinter );
end;

MyPtr^.dmFields := MyPtr^.dmFields or dm_Color;


if (MyPtr^.dmColor = DMCOLOR_COLOR) then
Result := True
else
Result := False;

End;

Peter Below (TeamB)

unread,
May 2, 2003, 12:39:12 PM5/2/03
to
In article <b8ta23$qen$04$1...@news.t-online.com>, Christoph Söllner
wrote:

> I wrote this function, but it always returns
> false, even on color printers. maybe someone
> could give me a hint, what's wrong?
>
> Function PrinterSupportsColor(WhichOne : Integer): Boolean;
> Var
> Device, Driver, Port: Array [0..255] of Char;
> hDevMode : THandle;
> MyPtr : PDevMode;
> Begin
> //MyDrk is a global var
> MyDrk.PrinterIndex := WhichOne;
> MyDrk.GetPrinter(Device, Driver, Port, hDevmode);
> MyPtr := GlobalLock(hDevMode);
> MyPtr.dmFields := MyPtr.dmFields or dm_Color;

THis is wrong, you do not *set* anything in the devmode, you want to
read something from it. So you test the dmFields field to see if the
field you are interested in has valid content:

If (MyPtr.dmFields and dm_Color) = dm_color Then
... can check the dmCOlor field.

You may find that the field has not been set by the driver.

It is usually better to use DeviceCapabilities to examine what the
printer supports.

uses printers, winspool;

Function PrinterSupportsColor: Boolean;


Var
Device, Driver, Port: Array [0..255] of Char;
hDevMode: THandle;

Begin
Printer.GetPrinter(Device, Driver, Port, hDevmode);
Result :=
WinSpool.DeviceCapabilities( Device, Port, DC_COLORDEVICE, Nil, Nil
) <> 0;
End;

Unfortunately this will only work on Win2K and XP, not on older
platforms.

--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

Joe C. Hecht

unread,
May 2, 2003, 3:56:47 PM5/2/03
to
Interesting side note:

Monochrome printers often report that they are color printers.

One way to universally tell is to create a compatible bitmap
and check the number of planes and bitdepth.

Joe
--
Delphi, graphics, and printing specialist available - $35/hr
http://www.code4sale.com/codeit/index.htm

"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message news:VA.00009da...@antispam.compuserve.com...

0 new messages