use printers,WinSpool枚举打印机var Buffer,PrinterInfo
char;
Flags, Count, NumInfo: DWORD;
Level: Byte;
i:integer;
begin
Flags := PRINTER_ENUM_CONNECTIONS or PRINTER_ENUM_LOCAL;
Level := 2;
Count := 0;
EnumPrinters(Flags, nil, Level, nil, 0, Count, NumInfo);
if Count = 0 then
Exit;
GetMem(Buffer, Count);
try if not EnumPrinters(Flags, nil, Level, PByte(Buffer), Count, Count, NumInfo) then
//枚举打印机 Exit;
PrinterInfo := Buffer;
for I := 0 to NumInfo - 1do
begin
with PPrinterInfo2(PrinterInfo)^do
begin
ComboBox1.Items.Add(pPrinterName);
Inc(PrinterInfo, sizeof(TPrinterInfo2));
end;
end;
finally FreeMem(Buffer, Count);
end;
end;
按打印机名指定打印机printer.printerindex:=printer.printers.indexof(ComboBox1.Text)直接打印printer.begin
doc;printer.canvas.textout(0,0,'abc');//打印文字printer.canvas.draw(0,0,image1.picture.graphic);//打印图片printer.enddoc;