如何得到默认打印机?在WIN32 SDK下编程,主要是如何把这个“默认”的找出来,谢谢!

解决方案 »

  1.   

    GetDefaultPrinter
    The GetDefaultPrinter function retrieves the printer name of the default printer for the current user on the local computer. BOOL GetDefaultPrinter(
      LPTSTR pszBuffer,   // printer name buffer
      LPDWORD pcchBuffer  // size of name buffer
    );
    Parameters
    pszBuffer 
    [in] Pointer to a buffer that receives a null-terminated character string containing the default printer name. If this parameter is NULL, the function fails and the variable pointed to by pcchBuffer returns the required buffer size, in characters. 
    pcchBuffer 
    [in/out] On input, specifies the size, in characters, of the pszBuffer buffer. On output, receives the size, in characters, of the printer name string, including the terminating null character. 
    Return Values
    If the function succeeds, the return value is a nonzero value and the variable pointed to by pcchBuffer contains the number of characters copied to the pszBuffer buffer, including the terminating null character.If the function fails, the return value is zero. To get extended error information, call GetLastError, which can return one of the following error codes.Value Meaning 
    ERROR_INSUFFICIENT_BUFFER The pszBuffer buffer is too small. The variable pointed to by pcchBuffer contains the required buffer size, in characters.  
    ERROR_FILE_NOT_FOUND There is no default printer. 
      

  2.   

    agree with bluebohe(薄荷) (MVP)use GetDefaultPrinter !
      

  3.   

    知道了default printer name还用着再得到吗此外在WIN32 APPLICATION 找不到这个函数,所以问题没有解决,继续请教。
      

  4.   

    BOOL EnumPrinters(
      DWORD Flags,         // printer object types
      LPTSTR Name,         // name of printer object
      DWORD Level,         // information level
      LPBYTE pPrinterEnum, // printer information buffer
      DWORD cbBuf,         // size of printer information buffer
      LPDWORD pcbNeeded,   // bytes received or required
      LPDWORD pcReturned   // number of printers enumerated
    );Flags  :
    PRINTER_ENUM_DEFAULT Windows 95: The function returns information about the default printer.
      

  5.   

    PRINTER_ENUM_DEFAULT 这表标志的话不就是默认的么?
      

  6.   

    以前我写的通过word进程获得当前默认打印机的方法,你参考一下吧!
    try
    {
    //ASSERT (NULL==m_objWord);
    m_objWord = new _ApplicationWord;

    if (!m_objWord->CreateDispatch("Word.Application", NULL))
    {
    AfxMessageBox("不能创建Word对象!", MB_ICONSTOP);
    delete m_objWord; m_objWord = NULL;
    throw 0;
    return;
    }
    else{
    // AfxMessageBox("成功创建Word对象!");
    m_sOldDefaultPrinter = m_objWord->GetActivePrinter();  // Verify the new
    if(m_sOldDefaultPrinter.Find(m_sNewPrinter)<0)
    {
    m_objWord->SetActivePrinter(m_sNewPrinter);  //设置当前打印机
    }
    }
    }
    catch(COleException *oe)
    {
    oe->ReportError();
    delete oe;
    }
      

  7.   

    PRINTER_ENUM_DEFAULT 只是在WIN95下设置有效,在WIN2000下这样设置还是查不出来。继续
      

  8.   

    通过word进程获得当前默认打印机的方法,这种方法对我来说恐怕不切实际,继续请教
      

  9.   

    建议你自己研究一下EnumPrinters函数和GetDefaultPrinter,后者在Win2000中需要更新SDK
    给你一个可用的方法
    static char szPrinter[80]; 
    char *szDevice,*szDriver,*szOutPut; 
    GetProfileString("windows","device",",,,",szPrinter,80); 
    szDevice=strtok(szPrinter,","); 
    szDriver=strtok(NULL,","); 
    szOutPut=strtok(NULL,","); 
    if(szDevice&&szDriver&&szOutPut) 

    // return CreateDC(szDriver,szDevice,szOutPut,NULL);