您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi中ShellExecute调用打印文档

时间:2011/9/3 15:31:25 点击:

  核心提示:打印指定格式文档:ShellExecute(Handle, 'print', PChar('c:\document.doc'), nil, nil, SW_HIDE) ;uses shellapi,...

打印指定格式文档:

ShellExecute(Handle, 'print', PChar('c:\document.doc'), nil, nil, SW_HIDE) ;
uses shellapi, printers;

procedure PrintDocument(const documentToPrint : string) ;
var
  printCommand : string;
  printerInfo : string;
  Device, Driver, Port: array[0..255] of Char;
  hDeviceMode: THandle;
begin

  if Printer.PrinterIndex = cboPrinter.ItemIndex then
  begin
    printCommand := 'print';
    printerInfo := '';
  end
  else
  begin

    printCommand := 'printto';
    Printer.PrinterIndex := cboPrinter.ItemIndex;
    Printer.GetPrinter(Device, Driver, Port, hDeviceMode) ;
    printerInfo := Format('"%s" "%s" "%s"', [Device, Driver, Port]) ;
  end;

  ShellExecute(Application.Handle, PChar(printCommand), PChar(documentToPrint), PChar(printerInfo), nil, SW_HIDE) ;
end;

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号