码迷,mamicode.com
首页 > 其他好文 > 详细

(转)设置默认打印机

时间:2017-03-24 23:28:11      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:value   message   设置   ant   显示   文件   pch   received   sel   

type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

{...}

procedure TForm1.FormCreate(Sender: TObject);
begin
{ tell printer to go to the default by setting
the PrinterIndex value to -1 告诉打印机到默认设置
到 printerindex=-1}
Printer.PrinterIndex := -1;

{ make our combobox non-editable 让我们的组合框不可编辑的}
ComboBox1.Style := csDropDownList;

{ set our combobox items to the printer printers 设置我们的组合框项显示打印机打印机}
ComboBox1.Items := Printer.Printers;

{ set combobox to view the default printer according to printer printerindex as set above 设置组合框查看默认打印机
根据以上printerindex设置打印机}
ComboBox1.ItemIndex := Printer.PrinterIndex;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle : THandle;
MyDevice,
MyDriver,
MyPort: array [0..255] of Char;
begin
{ set printer to the selected according to the
combobox itemendex 将打印机设置为根据
组合框itemendex}
Printer.PrinterIndex := ComboBox1.ItemIndex;

{ get our printer properties 获取打印机属性}
Printer.GetPrinter(MyDevice,
MyDriver,
MyPort,
MyHandle);

{ create string of exactly what WriteProfileString()
wants to see by concat each of the above received
character arrays 创建接收WriteProfileString()字符串到的字符数组 }
StrCat( MyDevice, ‘,‘);
StrCat( MyDevice, MyDriver );
StrCat( MyDevice, ‘,‘);
StrCat( MyDevice, MyPort );

{ copy our new default printer into our windows ini file
to the [WINDOWS] section under DEVICE=
复制我们的新默认打印机到我们的Windows INI文件到windows部分下的DEVICE}
WriteProfileString(‘WINDOWS‘,
‘DEVICE‘,
MyDevice );

{ tell all applications that the windows ini file has
changed, this will cause them all to recheck default
printer 告诉所有的Windows INI文件的应用程序
改变,这将使他们所有的核对默认
打印机}
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(pChar(‘windows‘)));
end;
end;

(转)设置默认打印机

标签:value   message   设置   ant   显示   文件   pch   received   sel   

原文地址:http://www.cnblogs.com/bestlove/p/6613600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!