Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2005.06.29;
Скачать: [xml.tar.bz2];

Вниз

Как определить, что принтер не установлен ?   Найти похожие ветки 

 
Fanny   (2005-06-08 09:10) [0]

собственно, сабж.
вызов диалогов Печать и Установка печати происходит нормально, если в системе установлен хоть один принтер.
если принтера нет, то программа подвисает.
как определить, что принтер есть ?


 
Digitman ©   (2005-06-08 09:13) [1]

Printer.Printers.Count ?


 
Коля   (2005-06-08 09:16) [2]

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

Автор: 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.


 
Fanny   (2005-06-08 09:29) [3]

сенкс
буду пробовать


 
Fanny   (2005-06-08 10:23) [4]

а при вызове Printers[PrinterIndex], если принтер НЕ УСТАНОВЛЕН в системе, всё равно подвисает :(


 
Amoeba ©   (2005-06-08 11:18) [5]

Проверяй на условие
Printer.Printers.Count > 0


 
Vlad Oshin ©   (2005-06-08 12:45) [6]

enumprinters
или

function GetCurrentPrinterHandle: THandle;
var
 Device, Driver, Port: array[0..255] of Char;
 hDeviceMode: THandle;
begin
 Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
 if not OpenPrinter(addr(Device), Result, nil) then
   RaiseLastWin32Error;
end;

потому что если есть текущий, значит есть


 
Fanny   (2005-06-09 08:32) [7]

спсаибо


 
Anatoly Podgoretsky ©   (2005-06-09 08:45) [8]

Fanny   (08.06.05 10:23) [4]
А ты так больше не делай.



Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2005.06.29;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.035 c
14-1117925845
Piter
2005-06-05 02:57
2005.06.29
Реализация аналога file в PHP


3-1115878478
kyn66
2005-05-12 10:14
2005.06.29
Число десятичных знаков для поля в таблице Access?


14-1117482353
Juice
2005-05-30 23:45
2005.06.29
Ошибка - сеть не доступна


11-1099052914
Владимир Кладов
2004-10-29 16:28
2005.06.29
Версия 1.99


4-1115201596
balamutik
2005-05-04 14:13
2005.06.29
Получение текста из адресной строки explorera





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский