whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

44 Visitors Online


 
...determine if a printer is a Dot-Matrix or Laser (or InkJet) ?
Autor: Sasa Zeman
Homepage: www.szutils.net
[ Print tip ]  

Tip Rating (16):  
     


{$APPTYPE CONSOLE}
uses Windows, Printers, WinSpool, Variants;
{
 Using only API calls, determinate which type is the active printer:
 Dot-Matrix or Laser (or InkJet)

 This example is distributed "AS IS", WITHOUT WARRANTY OF ANY KIND,
 either express or implied. You use it at your own risk!
}

function IsPrinterMatrix: Boolean;
var
  
DeviceMode: THandle;
  Device, Driver, Port: array [0..79] of Char;
  pDevice, pDriver, pPort: PChar;
begin

  
// Determinate that active printer is a Dot-Marix
  
Result:= False;
  pDevice := @Device;
  pDriver := @Driver;
  pPort   := @Port;

  Device  := #0;
  Driver  := #0;
  Port    := #0;

  Printer.GetPrinter(pDevice, pDriver, pPort, DeviceMode);

  // Printer can be dot-matrix when number of colors is maximum 16
  // and when printer is capable to print only for TRUETYPE
  // fonts as graphics (dot-matrix and PCL printers are capable for that).

  
if (GetDeviceCaps(Printer.Handle,NUMCOLORS)<=16) and
     
(DeviceCapabilities(pDevice, pPort,DC_TRUETYPE,nil,nil) = DCTT_BITMAP)
  then
    
Result := True;
end;

begin
  
writeln ('Active printer is ', Printer.Printers[Printer.PrinterIndex]);

  if IsPrinterMatrix then
    
writeln('This is a Dot-Matrix printer')
  else
    
writeln('This is a LaserJet or InkJet printer');
end.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners