用winspool取得本机安装的打印机的详细信息

原创 2002年01月11日 17:35:00

用winspool取得本机安装的打印机的详细信息

在Delphi 6 Professional version on Windows 2000 Professional环境下测试过
窗体的名字为"FPrint",有TMemo 和 TCombobox 两个控件

unit unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, TabEdit, Printers, Buttons, WinSpool;

type
  TPrinterInfo = record
    SeverName         : PChar;
    PrinterName       : PChar;
    ShareName         : PChar;
    PortName          : PChar;
    DriverName        : PChar;
    Comment           : PChar;
    Location          : PChar;
    DeviceMode        : PDeviceModeA;
    SepFile           : PChar;
    PrintProcessor    : PChar;
    DataType          : PChar;
    Parameters        : PChar;
    SecurityDescriptor: PSecurityDescriptor;
    Attributes        : Cardinal;
    DefaultPriority   : Cardinal;
    StartTime         : Cardinal;
    UntilTime         : Cardinal;
    Status            : Cardinal;
    Jobs              : Cardinal;
    AveragePPM        : Cardinal;
  end;

  TFPrint = class(TForm)
    Memo1: TMemo;
    ComboBox1: TComboBox;
    procedure FormShow(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  function GetCurrentPrinterInformation: TPrinterInfo;
  function GetCurrentPrinterHandle: THandle;

var
  FPrint: TFPrint;

implementation

{$R *.dfm}

function GetCurrentPrinterHandle: THandle;
var
  Device, Driver, Port : array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  if not OpenPrinter(@Device, Result, nil) then
    RaiseLastWin32Error;
end;

function GetCurrentPrinterInformation: TPrinterInfo;
var
  hPrinter  : THandle;
  pInfo:  PPrinterInfo2;
  bytesNeeded: DWORD;
begin
  hprinter := GetCurrentPrinterHandle;
  try
    Winspool.GetPrinter( hPrinter, 2, Nil, 0, @bytesNeeded );
    pInfo := AllocMem( bytesNeeded );
    try
      Winspool.GetPrinter( hPrinter, 2, pInfo, bytesNeeded, @bytesNeeded );
       Result.SeverName          := pInfo^.pServerName;
       Result.PrinterName        := pInfo^.pPrinterName;
       Result.ShareName          := pInfo^.pShareName;
       Result.PortName           := pInfo^.pPortName;
       Result.DriverName         := pInfo^.pDriverName;
       Result.Comment            := pInfo^.pComment;
       Result.Location           := pInfo^.pLocation;
       Result.DeviceMode         := pInfo^.pDevMode;
       Result.SepFile            := pInfo^.pSepFile;
       Result.PrintProcessor     := pInfo^.pPrintProcessor;
       Result.DataType           := pInfo^.pDatatype;
       Result.Parameters         := pInfo^.pParameters;
       Result.SecurityDescriptor := pInfo^.pSecurityDescriptor;
       Result.Attributes         := pInfo^.Attributes;
       Result.DefaultPriority    := pInfo^.DefaultPriority;
       Result.StartTime          := pInfo^.StartTime;
       Result.UntilTime          := pInfo^.UntilTime;
       Result.Status             := pInfo^.Status;
       Result.Jobs               := pInfo^.cJobs;
       Result.AveragePPM         := pInfo^.AveragePPM;
    finally
      FreeMem( pInfo );
    end;
  finally
    ClosePrinter( hPrinter );
  end;
end;


procedure TFPrint.FormShow(Sender: TObject);
begin
  ComboBox1.Items.Assign(Printer.Printers);
  ComboBox1.ItemIndex := 0;
  ComboBox1.OnChange(nil);
end;

procedure TFPrint.ComboBox1Change(Sender: TObject);
var
  PrinterInfo: TPrinterInfo;
begin
  PrinterInfo := GetCurrentPrinterInformation;
  memo1.Clear;
  with memo1.Lines do
  begin
    Add('GENERAL INFORMATION');
    Add('');
    Add('ServerName: ' + PrinterInfo.SeverName);
    Add('PrinterName: ' + PrinterInfo.PrinterName);
    Add('ShareName: ' + PrinterInfo.ShareName);
    Add('PortName: ' + PrinterInfo.PortName);
    Add('DriverName: ' + PrinterInfo.DriverName);
    Add('Comment: ' + PrinterInfo.Comment);
    Add('Location: ' + PrinterInfo.Location);
    Add('SepFile: ' + PrinterInfo.SepFile);
    Add('PrintProcessor: ' + PrinterInfo.PrintProcessor);
    Add('DataType: ' + PrinterInfo.DataType);
    Add('Parameters: ' + PrinterInfo.Parameters);
    Add('Attributes: ' + IntToStr(PrinterInfo.Attributes));
    Add('DefaultPriority: ' + IntToStr(PrinterInfo.DefaultPriority));
    Add('StartTime: ' + IntToStr(PrinterInfo.StartTime));
    Add('UntilTime: ' + IntToStr(PrinterInfo.UntilTime));
    Add('Status: ' + IntToStr(PrinterInfo.Status));
    Add('Jobs: ' + IntToStr(PrinterInfo.Jobs));
    Add('AveragePPM: ' + IntToStr(PrinterInfo.AveragePPM));
    Add('');
    Add('DEVICEMODE INFORMATION');
    Add('');

    Add('DeviceName: ' + PrinterInfo.DeviceMode.dmDeviceName);
    Add('SpecVersion: ' + IntToStr(PrinterInfo.DeviceMode.dmSpecVersion));
    Add('DriverVersion: ' + IntToStr(PrinterInfo.DeviceMode.dmDriverVersion));
    Add('Size: ' + IntToStr(PrinterInfo.DeviceMode.dmSize));
    Add('DriverExtra: ' + IntToStr(PrinterInfo.DeviceMode.dmDriverExtra));
    Add('Fields: ' + IntToStr(PrinterInfo.DeviceMode.dmFields));
    Add('Orientation: ' + IntToStr(PrinterInfo.DeviceMode.dmOrientation));
    Add('PaperSize: ' + IntToStr(PrinterInfo.DeviceMode.dmPaperSize));
    Add('PaperLength: ' + IntToStr(PrinterInfo.DeviceMode.dmPaperLength));
    Add('PaperWidth: ' + IntToStr(PrinterInfo.DeviceMode.dmPaperWidth));
    Add('Scale: ' + IntToStr(PrinterInfo.DeviceMode.dmScale));
    Add('Copies: ' + IntToStr(PrinterInfo.DeviceMode.dmCopies));
    Add('DefaultSource: ' + IntToStr(PrinterInfo.DeviceMode.dmDefaultSource));
    Add('PrintQuality: ' + IntToStr(PrinterInfo.DeviceMode.dmPrintQuality));
    Add('Color: ' + IntToStr(PrinterInfo.DeviceMode.dmColor));
    Add('Duplex: ' + IntToStr(PrinterInfo.DeviceMode.dmDuplex));
    Add('YResolution: ' + IntToStr(PrinterInfo.DeviceMode.dmYResolution));
    Add('TTOption: ' + IntToStr(PrinterInfo.DeviceMode.dmTTOption));
    Add('Collate: ' + IntToStr(PrinterInfo.DeviceMode.dmCollate));
    Add('LogPixels: ' + IntToStr(PrinterInfo.DeviceMode.dmLogPixels));
    Add('BitsPerPel: ' + IntToStr(PrinterInfo.DeviceMode.dmBitsPerPel));
    Add('PelsWidth: ' + IntToStr(PrinterInfo.DeviceMode.dmPelsWidth));
    Add('PelsHeight: ' + IntToStr(PrinterInfo.DeviceMode.dmPelsHeight));
    Add('DisplayFlags: ' + IntToStr(PrinterInfo.DeviceMode.dmDisplayFlags));
    Add('DisplayFrequency: ' + IntToStr(PrinterInfo.DeviceMode.dmDisplayFrequency));
    Add('ICMMethod: ' + IntToStr(PrinterInfo.DeviceMode.dmICMMethod));
    Add('ICMintent: ' + IntToStr(PrinterInfo.DeviceMode.dmICMIntent));
    Add('MediaType: ' + IntToStr(PrinterInfo.DeviceMode.dmMediaType));
    Add('DitherType: ' + IntToStr(PrinterInfo.DeviceMode.dmDitherType));
    Add('ICCManufacturer: ' + IntToStr(PrinterInfo.DeviceMode.dmICCManufacturer));
    Add('ICCModel: ' + IntToStr(PrinterInfo.DeviceMode.dmICCModel));
    Add('PanningWidth: ' + IntToStr(PrinterInfo.DeviceMode.dmPanningWidth));
    Add('PanningHeight: ' + IntToStr(PrinterInfo.DeviceMode.dmPanningHeight));
  end;
end;

end.
//rock
//转载请保留此信息

delphi 取得本机打印机列表及打印机详细信息

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls...
  • delphi308
  • delphi308
  • 2013年08月07日 17:17
  • 2285

C#直接发送打印机命令到打印机及ZPL常用打印命令 - 条码打印机

using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServi...
  • smartsmile2012
  • smartsmile2012
  • 2014年03月26日 15:17
  • 21254

linux 安装打印机驱动

1、Linux 开源打印机驱动项目 http://www.openprinting.org/printers/  里面有所支持的打印机驱动。 2、HP 打印机 linux 驱动支持项目http://w...
  • u011997922
  • u011997922
  • 2015年09月04日 14:40
  • 3840

VM 中添加打印机

Window VM 打印设置。
  • dongdong_tcl
  • dongdong_tcl
  • 2015年07月17日 13:59
  • 668

Linux下安装HP打印机的驱动程序

前言在Linux下,我想通过惠普打印机打印文件,我房间的HP打印机型号为HP LaserJet 1020/1008。一开始通过命令行安装hplip及其相关插件,由于我的电脑是Fedora 22 Wor...
  • ws_20100
  • ws_20100
  • 2015年10月14日 09:03
  • 7509

网上邻居无法访问本机及打印机之解…

1.检查guest账户是否开启       XP默认情况下不开启guest账户,因此些为了其他人能浏览你的计算机,请启用guest账户。同时,为了安全请为guest设置密码或相应的权限。当然,也可以...
  • gufengaoyue
  • gufengaoyue
  • 2013年11月15日 16:38
  • 871

VC 打印位图的最新实现例子

#pragma comment(lib, "winspool.lib") #include "stdafx.h" #include   HANDLE m_hBitmap; /// TCHAR ...
  • xbsoul
  • xbsoul
  • 2017年01月03日 10:25
  • 773

Windows10系统添加打印机步骤

1.  打开控制面板→硬件和声音→查看设备和打印机选项。 2.  点击添加打印机选项。 3.  选择我所需的打印机未列出。 4.  选择使用TCP/IP地址或主机名添加打印机,点击下一步...
  • sdujava2011
  • sdujava2011
  • 2015年11月05日 19:53
  • 4241

打印机驱动安装打印机端口监视

Installing a Print Monitor 1 out of 3 rated this helpful - Rate this topic This sect...
  • kingmax54212008
  • kingmax54212008
  • 2013年08月22日 15:16
  • 3406

ubuntu下安装virtualbox并启用usb打印机

http://www.cnblogs.com/ericsun/archive/2013/06/10/3130679.html
  • sardtass
  • sardtass
  • 2014年09月17日 10:49
  • 1169
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:用winspool取得本机安装的打印机的详细信息
举报原因:
原因补充:

(最多只允许输入30个字)