是想控制自己的打印信息,还是要去监控打印机?
获取所有要打印的信息(包括其他用户的打印)?

解决方案 »

  1.   

    是去监控打印机,不过是本机的打印机.也要监控通过网络在本机的打印信息.
      

  2.   

    using System;
    using System.Data;
    using System.Runtime.InteropServices;namespace EnumPrintjobstest
    {
    class Class1
    {
    [DllImport("winspool.drv",CharSet=CharSet.Auto)]
    static extern bool OpenPrinter(string name,out IntPtr hPrinter, IntPtr pDefault); [DllImport("winspool.drv",CharSet=CharSet.Auto)]
    static extern bool ClosePrinter(IntPtr hPrinter);// BOOL EnumJobs(
    // HANDLE hPrinter,    // handle to printer object
    // DWORD FirstJob,     // index of first job
    // DWORD NoJobs,       // number of jobs to enumerate
    // DWORD Level,        // information level
    // LPBYTE pJob,        // job information buffer
    // DWORD cbBuf,        // size of job information buffer
    // LPDWORD pcbNeeded,  // bytes received or required
    // LPDWORD pcReturned  // number of jobs received
    // );
    [DllImport("winspool.drv",CharSet=CharSet.Auto)]
    // static extern bool EnumJobs(IntPtr hPrinter,int FirstJob,int NoJobs,int Level,out IntPtr pJob,int cbBuf,out int pcbNeeded,out int pcReturned);
    static extern bool EnumJobs(IntPtr hPrinter,int FirstJob,int NoJobs,int Level,out IntPtr pJob,int cbBuf,out IntPtr pcbNeeded,out IntPtr pcReturned); [STAThread]
    static void Main(string[] args)
    {
    string PrintName="\\"+"\\"+"FRANK"+"\\"+"Epson LQ";
    EnumJobs(PrintName);
    // Console.Write(PrintName.ToString());
    string str=Console.ReadLine();

    } private static void EnumJobs(string StrPrintName)
    {
    bool bRet;
    int cbBuf=0;
    IntPtr pPrintHand= IntPtr.Zero;
    IntPtr Pdef= IntPtr.Zero;
    IntPtr pJob=IntPtr.Zero;
    // int dwNeeded,dwReturned;
    IntPtr dwNeeded,dwReturned;

    bRet = OpenPrinter(StrPrintName, out pPrintHand,  Pdef);

    Console.Write("PrintName:{0}\n",StrPrintName); //ok
    Console.Write("PrintHand:{0}\n",pPrintHand);    //ok if (bRet)
    {
    if( ! EnumJobs( pPrintHand, 0, 256,1,out pJob , 0, out dwNeeded,out dwReturned ) )
    {
    Console.Write("dwNeeded {0}",dwNeeded);        //ok
    Console.Write("dwReturned {0}",dwReturned);    //error ?
    // ......
    } }
    else
    {
    ClosePrinter(pPrintHand);
    Console.Write("PrintName error");
    }

    ClosePrinter(pPrintHand);

    }
    }