如何根据具体需求将某个打印机设置为“默认打印机”(100分)

  • 主题发起人 主题发起人 luojun
  • 开始时间 开始时间
Specifies a printer as the current printer.
procedure SetPrinter(ADevice, ADriver, APort: PChar;
ADeviceMode: THandle);
Description
Do not call SetPrinter directly. Instead, access the printer with the Printers property array. For more information, see the Windows API CreateDC function.

Lists all printers installed in Windows.
property Printers: TStrings;
Description
The list of installed printers is found in the Printers property. The value of the PrinterIndex property is the currently selected printer. The list of fonts supported by the current printer is found in the Fonts property.
 
在装好驱动后,用
printer.PrinterIndex 指定不同的打印机。
很容易的啦。
 
将某个打印机设置为“默认打印机”产生的结果是在“设置”“打印机”中,
我设置的默认打印机标志为“默认打印机”,并且该打印机一直为默认打印机
 
这个分数也给我吧,呵呵
//这个问题和你又提一次问题一样,呵呵
 
有一个方法:
  修改Win.ini文件。
对于默认的打印机,写在win.ini中的[windows]中的device部分;
而系统中的打印机,在win.ini文件中的[Devices]中有记录;
更改的时候,就将[Devices]中的打印机信息写入[windows]中!!
写完之后,向系统发一个WM_WININICHANGE消息,不就搞定了吗??
 
修改win.ini文件的内容,把win.ini中的windows段中的device值改为默认打印机的相应的值即可
 
上面改WIN。INI文件的方法不管用吧,在2K里面好像没有这种呀!
我加入WINDOWS这个段,打印设置对话框里没有改过来
 
在窗体中加入combobox和两个button
你自己TRY!
我测试通过!
procedure TForm1.Button1Click(Sender: TObject);
begin
ComboBox1.Items := Printer.Printers;
{populates ComboBox}
ComboBox1.ItemIndex := Printer.PrinterIndex;
{sets display to current printer}
end;

procedure TForm1.Button2Click(Sender: TObject);
var
Device: array[0..255] of Char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
s : array[0..255] of Char;
hDeviceMode: THandle;
begin

Printer.PrinterIndex := ComboBox1.ItemIndex;
Printer.GetPrinter (Device, Driver, Port, hDeviceMode);
StrCopy (s, Device);
StrCat (s, ',');
StrCat (s, Driver);
StrCat (s, ',');
StrCat (s, Port);
WriteProfileString ('windows', 'device', s);
StrCopy (s, 'windows');
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));
end;
 
后退
顶部