[原]delphi修改默认打印机

  • 主题发起人 主题发起人 SUNSTONE的Delphi笔记
  • 开始时间 开始时间
S

SUNSTONE的Delphi笔记

Unregistered / Unconfirmed
GUEST, unregistred user!
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

作者:sunstone 发表于 2011/06/10 20:59:00 原文链接 //blog.csdn.net/sunstone/article/details/6537253
阅读:3004

查看更多...
 

Similar threads

S
回复
0
查看
585
SUNSTONE的Delphi笔记
S
S
回复
0
查看
683
SUNSTONE的Delphi笔记
S
S
回复
0
查看
694
SUNSTONE的Delphi笔记
S
S
回复
0
查看
689
SUNSTONE的Delphi笔记
S
后退
顶部