现有两台计算机A,B,他们都装有win2000,B上有一台打印机为共享;我的程序在A上,A上也接有打印机,现
在我的程序能使用本地接的打印机,但是B上共享的打印机确找不到,该怎么解决?我在使用EnumPrinters枚举打印机时Flags参数设为PRINTER_ENUM_LOCAL,Name参数为NULL,可以枚举本地所有的打印机;但是使用PRINTER_ENUM_NETWORK参数确得不到任何的打印机,请问各位该怎么解决?谢谢!

解决方案 »

  1.   

    PRINTER_ENUM_NETWORK是指的在本地添加的网络打印机,也就是说本地计算机需要安装网络打印机后,才能找到.
    我估计你对该参数的理解可能有些误解
      

  2.   

    DWORD            dwFlags = PRINTER_ENUM_FAVORITE | PRINTER_ENUM_LOCAL;
    LPPRINTER_INFO_2 pPrinters;
    DWORD            cbPrinters;
    DWORD            cReturned, i;
    char             buf[256];

    HWND hwndCombobox = ::GetDlgItem(m_hWnd,IDC_COMBO1);
    strcpy (buf, "Display");
    ::SendMessage (hwndCombobox, CB_INSERTSTRING, (UINT)-1, (LONG) buf);

    //
    // get byte count needed for buffer, alloc buffer, the enum the printers
    //

    EnumPrinters (dwFlags, NULL, 2, NULL, 0, &cbPrinters,
    &cReturned);

    if (!(pPrinters = (LPPRINTER_INFO_2) LocalAlloc (LPTR, cbPrinters + 4)))
    {
    ::MessageBox (m_hWnd, _T("error"),
    _T("error"), MB_OK | MB_ICONEXCLAMATION); }


    if (!EnumPrinters (dwFlags, NULL, 2, (LPBYTE) pPrinters,
    cbPrinters, &cbPrinters, &cReturned))
    {
    ::MessageBox (m_hWnd, _T("error"),
    _T("error"), MB_OK | MB_ICONEXCLAMATION);
    } if (cReturned > 0)

    for (i = 0; i < cReturned; i++)
    {
    //
    // for each printer in the PRINTER_INFO_2 array: build a string that
    //   looks like "DEVICE_NAME;PORT;DRIVER_NAME"
    //

    strcpy (buf, (pPrinters + i)->pPrinterName);
    strcat (buf, ";");
    strcat (buf, (pPrinters + i)->pPortName);
    strcat (buf, ";");
    strcat (buf, (pPrinters + i)->pDriverName);

    ::SendMessage (hwndCombobox, CB_INSERTSTRING, (UINT)-1, (LONG) buf);
    }
    else
    ::MessageBox (m_hWnd, _T("No printers listed"), _T("PRINTER.EXE"), MB_OK);

    ::SendMessage(hwndCombobox,CB_SETCURSEL,(UINT)0,(LONG)0);
      

  3.   

    you can research the example c:\samples\VC98\sdk\Graphics\GDI\printer
      

  4.   

    PRINTER_ENUM_FAVORITE是什么意思?
      

  5.   

    按taianmonkey()给出的代码加了个参数PRINTER_ENUM_FAVORITE,就可以解决我的问题了。谢谢taianmonkey()!