正在阅读:Delphi必学技巧:枚举打印机Delphi必学技巧:枚举打印机

2004-12-15 16:51 出处:CSDN 作者:apexchu 责任编辑:linjixiong


  case 6:
  return PRINTER_ENUM.SHARED;
  case 7:
  return PRINTER_ENUM.NETWORK;
  default:
  return PRINTER_ENUM.LOCAL ;
  }
  }
  }


  #region 打印机位置状态枚举 PRINTER_ENUM
  public enum PRINTER_ENUM
  {
  DEFAULT = 0x01,
  LOCAL = 0x02,
  CONNECTIONS = 0x04,
  NAME = 0x08,
  REMOTE = 0x10,
  SHARED = 0x20,
  NETWORK = 0x40
  }
  #endregion

  #region 异常派生 EnumPrinterException
  [Serializable]
  public class EnumPrinterException: ApplicationException
  {
  public EnumPrinterException() { }
  public EnumPrinterException (string message): base(message) { }
  public EnumPrinterException (string message, Exception inner):
  base(message, inner) {}
  protected EnumPrinterException (SerializationInfo info,
  StreamingContext context) : base(info, context)
  { }
  }
  #endregion

  //加上这个属性可以按导出到非托管对像的顺序排序
  [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
  public class PRINTER_INFO_1
  {
  public int flags;
  public IntPtr pDescription;
  public IntPtr pName;
  public IntPtr pComment;
  }

  public class PrinterSearcher
  {
  #region Search
  public PrinterInfo[] Search(PRINTER_ENUM printerKind)
  {
  PrinterInfo[] pInfo = new PrinterInfo[0];

  uint iNeeded = 0, iReturned = 0, iSize = 0;
  IntPtr printers = IntPtr.Zero;

  if (!EnumPrinters(printerKind, String.Empty,  1,  printers,  0, ref iNeeded, ref iReturned) )
  {


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品