delphi修改默认打印机


本文整理自网络,侵删。

 

uses WinSpool ;

procedure ChangeDefaultPrinter(const Name: string) ;
var
    W2KSDP: function(pszPrinter: PChar): Boolean; stdcall;
    H: THandle;
    Size, Dummy: Cardinal;

 PI: PPrinterInfo2;
begin
    if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 5) then
    begin
      @W2KSDP := GetProcAddress(GetModuleHandle(winspl), 'SetDefaultPrinterA') ;
      if @W2KSDP = nil then RaiseLastOSError;
      if not W2KSDP(PChar(Name)) then RaiseLastOSError;
    end
    else
    begin
      if not OpenPrinter(PChar(Name), H, nil) then RaiseLastOSError;
      try
        GetPrinter(H, 2, nil, 0, @Size) ;
        if GetLastError <> ERROR_INSUFFICIENT_BUFFER then RaiseLastOSError;
        GetMem(PI, Size) ;
        try
          if not GetPrinter(H, 2, PI, Size, @Dummy) then RaiseLastOSError;
          PI^.Attributes := PI^.Attributes or PRINTER_ATTRIBUTE_DEFAULT;
          if not SetPrinter(H, 2, PI, PRINTER_CONTROL_SET_STATUS) then RaiseLastOSError;
        finally
          FreeMem(PI) ;
        end;
      finally
        ClosePrinter(H) ;
      end;
    end;
end; //ChangeDefaultPrinter www.3464.com

相关阅读 >>

Delphi 从url地址中获得文件名

Delphi 将strings合并成一个逗号分隔的字符串,用于sql

Delphi net.httpclient正则批量获取网页代码中的数值

Delphi写的验证身份证号有效性函数

Delphi cxgrid中回车键光标移到下列

Delphi 检测url地址是否有效

Delphi 不管什么datetime日期格式时间格式转换都不会错了

Delphi 程序动态改变皮肤

wmi使用的win32_类库名

Delphi xe mysql数据库操作类 mysqlhelper

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...