在网上找资料说用OpenPrinter和GetPrinter这两个方法来获取打印机的状态
折腾了一阵子总算是能判断出打印机是否连接到电脑了
可是过了两天 我什么都没改 真的什么都没改 获取的打印机状态居然就变成4224了
这不是坑爹吗?
代码贴出来 希望各位高手能帮忙解答下...bool32 CXXXPrint::CheckPrinter( LPCTSTR pszPrinterName )
{
DWORD dwNeeded=0; 
PRINTER_INFO_6* pPrinterInfo= (PRINTER_INFO_6 *)malloc( 0 );  if ( !::OpenPrinter( m_szPrinterName, &m_hPrinter, NULL ) )
{
return FALSE;
} if( !::GetPrinter( m_hPrinter, 6, (LPBYTE)pPrinterInfo, 0, &dwNeeded) )
{
pPrinterInfo= (PRINTER_INFO_6 *)malloc( dwNeeded );
::GetPrinter( m_hPrinter, 6, (LPBYTE)pPrinterInfo, dwNeeded, &dwNeeded ); 
}
::ClosePrinter(m_hPrinter);  if ( PRINTER_STATUS_NOT_AVAILABLE == pPrinterInfo->dwStatus )
{
free(pPrinterInfo);
pPrinterInfo = NULL;
return FALSE;
}
else
{
free(pPrinterInfo);
pPrinterInfo = NULL;
return TRUE;
}
}本来pPrinterInfo->dwStatus是等于PRINTER_STATUS_NOT_AVAILABLE的 也就是16进制的1000
但是现在却变成了4224也就是1080
在winspool.h里面也没找到这个状态 郁闷啊
下面是打印机的状态
#define PRINTER_STATUS_PAUSED            0x00000001
#define PRINTER_STATUS_ERROR             0x00000002
#define PRINTER_STATUS_PENDING_DELETION  0x00000004
#define PRINTER_STATUS_PAPER_JAM         0x00000008
#define PRINTER_STATUS_PAPER_OUT         0x00000010
#define PRINTER_STATUS_MANUAL_FEED       0x00000020
#define PRINTER_STATUS_PAPER_PROBLEM     0x00000040
#define PRINTER_STATUS_OFFLINE           0x00000080
#define PRINTER_STATUS_IO_ACTIVE         0x00000100
#define PRINTER_STATUS_BUSY              0x00000200
#define PRINTER_STATUS_PRINTING          0x00000400
#define PRINTER_STATUS_OUTPUT_BIN_FULL   0x00000800
#define PRINTER_STATUS_NOT_AVAILABLE     0x00001000
#define PRINTER_STATUS_WAITING           0x00002000
#define PRINTER_STATUS_PROCESSING        0x00004000
#define PRINTER_STATUS_INITIALIZING      0x00008000
#define PRINTER_STATUS_WARMING_UP        0x00010000
#define PRINTER_STATUS_TONER_LOW         0x00020000
#define PRINTER_STATUS_NO_TONER          0x00040000
#define PRINTER_STATUS_PAGE_PUNT         0x00080000
#define PRINTER_STATUS_USER_INTERVENTION 0x00100000
#define PRINTER_STATUS_OUT_OF_MEMORY     0x00200000
#define PRINTER_STATUS_DOOR_OPEN         0x00400000
#define PRINTER_STATUS_SERVER_UNKNOWN    0x00800000
#define PRINTER_STATUS_POWER_SAVE        0x01000000
#define PRINTER_STATUS_SERVER_OFFLINE    0x02000000
#define PRINTER_STATUS_DRIVER_UPDATE_NEEDED    0x04000000

解决方案 »

  1.   

    #define PRINTER_STATUS_OFFLINE 0x00000080
    #define PRINTER_STATUS_NOT_AVAILABLE 0x00001000两个或一下,不就是1080了么
      

  2.   

    (PRINTER_STATUS_NOT_AVAILABLE | PRINTER_STATUS_OFFLINE) 0x00001080
      

  3.   

    我现在也在获取打印机状态,要知道打印机是否联机、缺纸或者暂停,我用getprinter函数返回的状态就只有两个一个是0一个是1不知道为什么
      

  4.   

    我用GetPrinter获取的状态也都是0,可能是我的打印机是LQ防真的,我用1600K驱动的原因,LZ的打印机与驱动是否完全匹配啊