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

•  DeLiKaTeS Tetris (Тетрис)  3 940

•  TDictionary Custom Sort  6 048

•  Fast Watermark Sources  5 850

•  3D Designer  8 668

•  Sik Screen Capture  6 171

•  Patch Maker  6 607

•  Айболит (remote control)  6 600

•  ListBox Drag & Drop  5 458

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

•  Графические эффекты  6 809

•  Рисование по маске  6 000

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

•  Canvas Drawing  5 357

•  Рисование Луны  5 082

•  Поворот изображения  4 619

•  Рисование стержней  3 274

•  Paint on Shape  2 516

•  Генератор кроссвордов  3 408

•  Головоломка Paletto  2 717

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

•  Пазл Numbrix  2 307

•  Заборы и коммивояжеры  2 994

•  Игра HIP  1 951

•  Игра Go (Го)  1 870

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

•  Программа укладки плитки  1 935

•  Генератор лабиринта  2 374

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

•  HEX View  2 382

•  Физический маятник  2 015

 
скрыть

  Форум  

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-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

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