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;
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
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;
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
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...