Delphi中设置默认打印机
点击次数:68 次 发布日期:2008-11-09 08:39:22 作者:源代码网
|
源代码网推荐 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 } 源代码网推荐 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 } 源代码网推荐 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 } 源代码网推荐 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 } 源代码网推荐 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= } 源代码网推荐 WriteProfileString("WINDOWS", 源代码网推荐 "DEVICE", 源代码网推荐 MyDevice ); 源代码网推荐 源代码网推荐 { tell all applications that the windows ini file has 源代码网推荐 changed, this will cause them all to recheck default 源代码网推荐 printer } 源代码网推荐 SendMessage(HWND_BROADCAST, 源代码网推荐 WM_WININICHANGE, 源代码网推荐 0, 源代码网推荐 LongInt(pChar("windows"))); 源代码网推荐 end; 源代码网推荐 end; 源代码网推荐 源代码网供稿. |
