1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39:
| uses ..., WinSpool;
procedure SetWinDefaultPrinter(const Name: String); var fnSetDefaultPrinter: function(pszPrinter: PChar): Bool; stdcall; H: THandle; Size, Dummy: Cardinal; PrinterInfo: PPrinterInfo2; begin if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion >= 5) then begin @fnSetDefaultPrinter := GetProcAddress(GetModuleHandle(winspl), 'SetDefaultPrinterA'); if (@fnSetDefaultPrinter = NIL) then RaiseLastOSError; if NOT fnSetDefaultPrinter(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(PrinterInfo, Size); try if NOT GetPrinter(H, 2, PrinterInfo, Size, @Dummy) then RaiseLastOSError; PrinterInfo^.Attributes := PrinterInfo^.Attributes or PRINTER_ATTRIBUTE_DEFAULT; if NOT SetPrinter(H, 2, PrinterInfo, PRINTER_CONTROL_SET_STATUS) then RaiseLastOSError; finally FreeMem(PrinterInfo); end; finally ClosePrinter(H); end; end; end; |