Autor Beitrag
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 21.02.08 14:48 
Wie kann man den Standard-Drucker für Windows umstellen, nicht nur in der eigenen Anwendung?[meta]SetDefaultPrinter[/meta]

ausblenden volle Höhe Delphi-Quelltext
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 >= 5then begin
     @fnSetDefaultPrinter := GetProcAddress(GetModuleHandle(winspl), 'SetDefaultPrinterA');
     if (@fnSetDefaultPrinter = NILthen
       RaiseLastOSError;
     if NOT fnSetDefaultPrinter(PChar(Name)) then
       RaiseLastOSError;
   end
   else begin
     if NOT OpenPrinter(PChar(Name), H, NILthen
       RaiseLastOSError;
     try
       GetPrinter(H, 2NIL0, @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;


SetWinDefaultPrinter.zip  (1.57 KB) Download (Rev 0)
 (815x, 815x gesamt)
Beschreibung: Demo-Projekt
SetWinDefaultPrinter.exe  (147.5 KB) Download (Rev 0)
 (768x, 768x gesamt)
Beschreibung: Demo-Programm
_________________
There are 10 types of people - those who understand binary and those who don´t.