如何获得windows中默认的打印机(50分)

  • 主题发起人 主题发起人 cao192
  • 开始时间 开始时间
C

cao192

Unregistered / Unconfirmed
GUEST, unregistred user!
请求答复,付费50
 
uses printers;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; &nbsp;Printer.PrinterIndex:=-1;<br>&nbsp; &nbsp;Label1.Caption:='默认打印机是'+Printer.Printers.Strings[Printer.PrinterIndex];<br>end;
 
非常感谢二位,另象这样的问题我应该看什么样的书呢?
 
英文好就看帮助,不好就看书:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1.delphi开发手册(潘爱民著)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.delphi5从入门到精通(marco cantu著)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.delphi高级开发指南(marco cantu著)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;4.delphi5开发人员指南<br><br>看完了,你要是没成为高手只管来骂我好了
 
VB的代码<br>'*********************************************************************<br>' Add a list of the available paper sources for &lt;PrinterName&gt; to<br>' the combobox &lt;cbo&gt;<br>'*********************************************************************<br>Public Sub EnumPrinterBins(PrinterName As String, cbo As ComboBox)<br>&nbsp; &nbsp; Dim prn As Printer<br>&nbsp; &nbsp; Dim hPrinter As Long &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;' Handle of the selected printer<br>&nbsp; &nbsp; Dim dwbins As Long &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;' The number of paperbins in the printer<br>&nbsp; &nbsp; Dim i As Long &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' counter<br>&nbsp; &nbsp; Dim nameslist As String &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' The string returned with all the bin names<br>&nbsp; &nbsp; Dim NameBin As String &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' The parsed bin name<br>&nbsp; &nbsp; Dim numBin() As Integer &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' Used as part of the DeviceCapabilities API call<br>&nbsp; &nbsp; Dim szBinID As String<br>&nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; cbo.Clear<br>&nbsp; &nbsp; For Each prn In Printers<br>&nbsp; &nbsp; &nbsp; &nbsp; ' Look through all the currently installed printers<br>&nbsp; &nbsp; &nbsp; &nbsp; If prn.DeviceName = PrinterName Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' We've found our printer -- open a handle to it<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If OpenPrinter(prn.DeviceName, hPrinter, 0) &lt;&gt; 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' Get the available bin numbers<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DC_BINS, ByVal vbNullString, 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ReDim numBin(1 To dwbins)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nameslist = String(24 * dwbins, 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; szBinID = String(1000, 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DC_BINS, numBin(1), 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dwbins = DeviceCapabilities(prn.DeviceName, prn.Port, _<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DC_BINNAMES, ByVal nameslist, 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'MsgBox Len(nameslist)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For i = 1 To dwbins<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' For each bin number, add its corresponding name<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' to our combo box<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NameBin = Mid(nameslist, 24 * (i - 1) + 1, 24)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NameBin = Left(NameBin, InStr(NameBin, Chr(0)) - 1)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbo.AddItem NameBin &amp; "/" &amp; numBin(i)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbo.ItemData(cbo.NewIndex) = numBin(i)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next i<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' Close the printer<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call ClosePrinter(hPrinter)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' OpenPrinter failed, so we can't retrieve information about it<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbo.AddItem prn.DeviceName &amp; " &nbsp;&lt;Unavailable&gt;"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br>&nbsp; &nbsp; &nbsp; &nbsp; End If<br>&nbsp; &nbsp; Next prn<br>End Sub<br>
 
好,谢谢各位。
 
后退
顶部