Autor |
Beitrag |
lenny Whatever
Hält's aus hier
Beiträge: 11
|
Verfasst: Di 07.08.07 19:11
Ich will eine Datei auf zwei unterschiedlichen Druckern drucken. Delphi lässt mich aber nur auf den default Drucker drucken. Den kann ich im code nicht ändern. (Kann ich schon, aber nur einmal. Dass heisst von A nach B ändern kann ich, aber dann nicht mehr nach A zurück...).
Hat irgendeiner eine Idee in der ich nicht zwei Computer brauche oder den default Drucker manuel ändere.
Lenny
|
|
arj
      
Beiträge: 378
Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
|
Verfasst: Mi 08.08.07 09:17
Bitte gib mal bisschen Sourcecode an. Wie du den Drucker wechselst usw.
|
|
lenny Whatever 
Hält's aus hier
Beiträge: 11
|
Verfasst: Mi 08.08.07 11:17
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: 40: 41: 42: 43:
| 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('A') ; richedit1.Print('A')
ChangeDefaultPrinter('B') ; richedit1.Print('B') |
Ich glaube dass Delphi den default Drucker nur einmal liest und dan für die session speichert.
Moderiert von Gausi: Delphi-Tags hinzugefügt
|
|
jaenicke
      
Beiträge: 19315
Erhaltene Danke: 1747
W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
|
Verfasst: Mi 08.08.07 11:34
Du setzt den ja systemweit anstatt nur für dein Programm...
Es gibt das Objekt Printer in Delphi, schau dir das mal an  .
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8:
| uses Printers;
ShowMessage(Printer.Printers.Text); Printer.PrinterIndex := 0; RichEdit1.Print('dd'); Printer.PrinterIndex := 2; RichEdit1.Print('dd'); |
So setzt du den für dein Programm und veränderst nix am System.
|
|
arj
      
Beiträge: 378
Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
|
Verfasst: Mi 08.08.07 11:36
Bitte Sourcecode in Delphi-Tags stellen!
|
|
lenny Whatever 
Hält's aus hier
Beiträge: 11
|
Verfasst: Mi 08.08.07 13:20
|
|
|