在windows2000下设置默认的打印机(100分)

  • 主题发起人 主题发起人 aerobull
  • 开始时间 开始时间
A

aerobull

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TsetDefaultPrinterDlg.setDefaultBtnClick(Sender: TObject);<br>var<br>&nbsp; PrinterName: array[0..255] of Char;<br>&nbsp; phPrinter: tHandle; <br>&nbsp; lpbPrinter: PPrinterInfo5; <br>&nbsp; port: string;<br>&nbsp; aPort: array[0..255] of char;<br>begin<br>&nbsp; strPCopy(PrinterName, printersLB.items[printersLB.itemIndex]);<br>&nbsp; if (openPrinter(PrinterName, phPrinter, nil)) then<br>&nbsp; begin<br>&nbsp; &nbsp; port := winIniFile.readString('devices', printersLB.items[printersLB.itemIndex], 'LPT1:');<br>&nbsp; &nbsp; port := copy(port, pos(',', port) + 1, length(port));<br>&nbsp; &nbsp; strPCopy(aPort, port);<br>&nbsp; &nbsp; lpbPrinter.pPrinterName := PrinterName; &nbsp; &nbsp; //此处开始出错。<br>&nbsp; &nbsp; lpbPrinter.pPortName := aPort; <br>&nbsp; &nbsp; lpbPrinter.Attributes := PRINTER_ATTRIBUTE_DEFAULT; <br>&nbsp; &nbsp; setPrinter(phPrinter, 5, lpbPrinter, 0);<br>&nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; messageDlg('Printer context not opened', mtError, [mbOK], 0);<br>&nbsp; currentPrinter.text := winIniFile.readString('windows', 'device', 'None Selected');<br>end;<br>各位,邦个忙。<br><br>thx<br>
 
不会呀,帮你UP
 
在Form上放一个Button和Combobox,在Uses中加入Printers,其余相关代码如下<br><br>procedure TForm1.FormActivate(Sender: TObject);<br>begin<br>ComboBox1.Items := Printer.Printers; {populates ComboBox}<br>ComboBox1.ItemIndex := Printer.PrinterIndex;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; Device: array[0..255] of Char;<br>&nbsp; Driver: array[0..255] of char;<br>&nbsp; Port: array[0..255] of char;<br>&nbsp; s : array[0..255] of Char;<br>&nbsp; hDeviceMode: THandle;<br>begin<br>&nbsp; Printer.PrinterIndex:= combobox1.ItemIndex;<br>&nbsp; Printer.GetPrinter (Device, Driver, Port, hDeviceMode);<br>&nbsp; StrCopy (s, Device);<br>&nbsp; StrCat (s, ',');<br>&nbsp; StrCat (s, Driver);<br>&nbsp; StrCat (s, ',');<br>&nbsp; StrCat (s, Port);<br>&nbsp; WriteProfileString ('windows', 'device', s);<br>&nbsp; StrCopy (s, 'windows');<br>&nbsp; SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@s));<br>end;<br><br>可在Win2000下设置默认打印机,已验证通过。
 
呵呵,楼上厉害。<br>我看了三遍,怎么都没看明白:<br>&nbsp; phPrinter: tHandle; <br>&nbsp; lpbPrinter: PPrinterInfo5;<br>&nbsp; strPCopy(PrinterName, printersLB.items[printersLB.itemIndex]);<br>只好回头。 :-)<br>
 
多人接受答案了。
 
后退
顶部