Usesa Printers ekliyoruz
fonksiyonumuz
function GetDefaultPrinter: string; var ResStr: array[0..255] of Char; begin GetProfileString('Windows', 'device', '', ResStr, 255); Result := StrPas(ResStr); end; procedure SetDefaultPrinter(NewDefPrinter: string); var ResStr: array[0..255] of Char; begin StrPCopy(ResStr, NewdefPrinter); WriteProfileString('windows', 'device', ResStr); StrCopy(ResStr, 'windows'); SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Longint(@ResStr)); end;
procedure TfrmMain.FormCreate(Sender: TObject); begin //Fill the combobox with all available printers Combobox1.Items.Clear; Combobox1.Items.AddStrings(Printer.Printers); // Get the Default Printer: label1.Caption := Format('Default Printer: %s',[GetDefaultPrinter]); end; procedure TfrmMain.Button2Click(Sender: TObject); begin //Set the selected printer in the combobox as default printer if Combobox1.Text <> '' then SetDefaultPrinter(Combobox1.Text) else ShowMessage('Choose a Printer first !'); end;
İndirmek için delphi_default_printer.