Недавно добавленные исходники

•  Animation Loaders  960

•  DeLiKaTeS Tetris (Тетрис)  5 896

•  TDictionary Custom Sort  7 848

•  Fast Watermark Sources  7 517

•  3D Designer  10 746

•  Sik Screen Capture  8 076

•  Patch Maker  8 277

•  Айболит (remote control)  8 323

•  ListBox Drag & Drop  7 159

•  Доска для игры Реверси  101 082

•  Графические эффекты  8 392

•  Рисование по маске  7 767

•  Перетаскивание изображений  6 362

•  Canvas Drawing  6 738

•  Рисование Луны  6 667

•  Поворот изображения  5 799

•  Рисование стержней  4 742

•  Paint on Shape  3 442

•  Генератор кроссвордов  4 434

•  Головоломка Paletto  3 577

•  Теорема Монжа об окружностях  4 375

•  Пазл Numbrix  2 833

•  Заборы и коммивояжеры  3 786

•  Игра HIP  2 552

•  Игра Go (Го)  2 558

•  Симулятор лифта  2 948

•  Программа укладки плитки  2 372

•  Генератор лабиринта  3 124

•  Проверка числового ввода  2 608

•  HEX View  3 014

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Вывести список установленных принтеров и установить принтер по умолчанию



Автор: Xavier Pacheco

unit MainFrm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TMainForm = class(TForm)
    cbPrinters: TComboBox;
    lblPrinter: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure cbPrintersChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation
uses IniFiles, Printers;

{$R *.DFM}

procedure TMainForm.FormCreate(Sender: TObject);
begin
  { Copy the printer names to the combobox and set the combobox to
    show the currently selected default printer }
  cbPrinters.Items.Assign(Printer.Printers);
  cbPrinters.Text := Printer.Printers[Printer.PrinterIndex];
  // Update the label to reflect the default printer
  lblPrinter.Caption := Printer.Printers[Printer.PrinterIndex];
end;

procedure TMainForm.cbPrintersChange(Sender: TObject);
var
  IniFile: TIniFile;
  TempStr1, TempStr2: string;
  S: array[0..64] of char;
begin
  with Printer do
  begin
    // Set the new printer based on the ComboBox's selected printer
    PrinterIndex := cbPrinters.ItemIndex;
    // Store the printer name into a temporary string
    TempStr1 := Printers[PrinterIndex];
    // Delete the unnecessary portion of the printer name
    System.Delete(TempStr1, Pos(' on ', TempStr1), Length(TempStr1));
    // Create a TIniFile class
    IniFile := TIniFile.Create('WIN.INI');
    try
      // Retrieve the device name of the selected printer
      TempStr2 := IniFile.ReadString('Devices', TempStr1, '');
      // Change the default printer to that chosen by the user
      IniFile.WriteString('windows', 'device', TempStr1 + ',' + TempStr2);
      // Tell all windows that the default printer changed.
      StrCopy(S, 'windows');
      SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@S));
    finally
      IniFile.Free;
    end;
  end;
  // Update the label to reflect the new printer selection
  lblPrinter.Caption := Printer.Printers[Printer.PrinterIndex];
end;

end.




Похожие по теме исходники

Список запущенных процессов

Список установленных устройств

Работа с принтером




Copyright © 2004-2026 "Delphi Sources" by «SiteAnalyzer». Delphi World FAQ

Группа ВКонтакте