因为程序需要,一台打印机打印发票,一台打印单据。我已经装上两台打印机一台打印机名是
Epson_1,另一台打印机名是Epson_2.
同一时刻用用Epson_1 打印发票,用Epson_2打印单据.
有些大侠说通过修改修改默认的打印机。我试了一下,是在改默认打印机的时候CPU资源占用率达到100%(我用的是WIN2000),这一两秒时间,客户不会容忍的,而且打完以后还要改回来,又要一到两秒的CPU占用100%。这几秒时间很容易死机之类的问题。有无些方法可以直接指定打印机的,不通过修改默认打印机?需要Epson_1时用Epson_1打印,需要Epson_2时用Epson_2打印。或者有更加好的方法?请指教?

解决方案 »

  1.   

    试试用printer.SetPrinter(),
    要use printers单元
      

  2.   

    以下是Delphi,SetPrinter(),的帮助
    -------------------------
    The SetPrinter function sets the state of the specified printer by pausing printing, resuming printing, or clearing all print jobs. The function can also be used to set printer data. BOOL SetPrinter(    HANDLE hPrinter, // handle of printer object 
        DWORD Level, // structure level 
        LPBYTE pPrinter, // address of array containing printer data  
        DWORD Command  // printer-state command 
       );
     ParametershPrinterHandle to the printer of interest. LevelWindows 95: Specifies the type of data contained in pPrinter. This parameter must be 0, 2, 3, 4, or 5. This parameter must be zero if Command is not equal to zero.
    Windows NT: Specifies the type of data contained in pPrinter. This parameter must be 0, 2, 3, 5, or 6. This parameter must be zero if Command is not equal to zero.pPrinterThis is either a DWORD value indicating the printer status, or a pointer to an array of bytes that may contain printer data. 
    If Level is 0, and the Command parameter is PRINTER_CONTROL_SET_STATUS, pPrinter must contain a DWORD value that specifies the new printer status to set. For a list of the possible status values, see the Status member of the PRINTER_INFO_2 structure. Note that PRINTER_STATUS_PAUSED and PRINTER_STATUS_PENDING_DELETION are not valid status values to set. If Level is 0, but the Command parameter is not PRINTER_CONTROL_SET_STATUS, pPrinter must be NULL. 
    Windows 95: If Level is 2, 3, 4, or 5, pPrinter points to an array that contains PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, or PRINTER_INFO_5 structures, respectively.
    Windows NT: If Level is 2, 3, 5, or 6, pPrinter points to an array that contains PRINTER_INFO_2,  PRINTER_INFO_3, PRINTER_INFO_5, or PRINTER_INFO_6 structures, respectively.CommandThis parameter can be zero or one of the following values. If it is zero, the printer retains its original state and the printer data is reconfigured by using the structure to which pPrinter points. Value Meaning
    PRINTER_CONTROL_PAUSE Pauses the printer.
    PRINTER_CONTROL_PURGE Deletes all print jobs in the printer.
    PRINTER_CONTROL_RESUME Resumes a paused printer.
    PRINTER_CONTROL_SET_STATUS Sets the printer status.
     If Command is any of the above values, Level must be zero.Return ValuesIf the function succeeds, the return value is nonzero.
    If the function fails, the return value is zero. To get extended error information, call GetLastError. ResYou can obtain the handle hPrinter is by calling the OpenPrinter function. 
    To modify the current printer settings, an application should call GetPrinter to retrieve the current settings into a PRINTER_INFO_2 structure, modify the members of that structure as necessary, and then call the SetPrinter function. 
    The SetPrinter function ignores the following members of a PRINTER_INFO_2 structure: pServerName, AveragePPM, Status, and cJobs 
    Pausing a printer suspends scheduling of all print jobs for that printer, except for the one print job that may be currently printing. Print jobs can be submitted to a paused printer, but no jobs will be scheduled to print on that printer until printing is resumed. If a printer is cleared, all print jobs for that printer are deleted, except for the current print job. 
    If the printer data structure contains a pointer to a security descriptor, only those components of the security descriptor that the caller has permission to write should be present. An application that wants to write particular security descriptor components must open the printer with sufficient access permission to modify those components. The following table shows the security descriptor components that can be modified for particular access permission values: Access Permission Modifiable Security Descriptor Components 
    WRITE_OWNER Owner, primary proup
    WRITE_DAC Discretionary access-control list (ACL)
    ACCESS_SYSTEM_SECURITY System ACL
     If the calling application lacks a required permission, SetPrinter fails. Those components of a security descriptor that an application does not wish to modify should be NULL or not be present, as appropriate. If you do not want to modify the security descriptor, and are calling SetPrinter with a PRINTER_INFO_2 structure, set the pSecurityDescriptor member of that structure to NULL. 
    Windows 95: SetPrinter does not update the pShareName member in the PRINTER_INFO_2 structure.Windows 95: SetPrinter is not supported when called against a Windows NT printer from a Windows 95 machine using the printer's UNC name
    -------------------------
    英文水平有限,劳烦各位DX们,贴出 tonylk(=www.tonixsoft.com=) 例子。to WWWWA(aaaa) 改变默认的打印机实在太耗资源了。
      

  3.   

    一台打印机是用并口连,一台打印机是用USB(打印口转USB)连。
    我知道可以直接控制并口打印,但是可以直接控制USB打印吗?,或者控制串口打印。
      

  4.   

    使用QR的时候,如果系统有多台打印机,如果要使用某台指定的打印机的话,QR却把所有的打印人物都发送到默认的打印机上面去了,那么如何发送到指定的打印机呢?可以这样,直接指定输出打印机就可以了:Printer.PrinterIndex:=0; ///指定第一台打印机为输出设备Printer.PinnterIndex:=-1; ///默认打印机为输出设备
     
      

  5.   

    晕~,原来这么简单。
    谢谢,cow8063(天涯远不远?不远!人在天涯,天涯怎会远) 。
    I love you。^_^