1

I would like to retrieve icon of the installed printers. From what I could search, one of the approach is to retrieve the icon of the .dll or .exe and have it be the icon of the printer. However, it's easy to find printer installed through GUI at:

Control Panel\Hardware and Sound\Devices and Printers

But, is there a physical location on hard drive to this list ? Is this created on the fly ?

4

1 回答 1

3

There is no physical disk folder that contains a list of printers.

If you have the PIDL for the printer in the shell namespace you can easily get its icon using SHGetFileInfo. Getting the PIDL is a little harder but not impossible.

I have done this in the past with a function that enumerates the virtual printer folder (CSIDL_PRINTERS), and compares the name of each item within it against the name of the printer I am looking for. When you find a matching name you have the PIDL, and you can then get the icon.

For example (this code is not complete of course, you will need to flesh it out):

SHGetFolderLocation(hwnd, CSIDL_PRINTERS, 0, 0, &pidlPrinters);
SHBindToObject(0, pidlPrinters, 0, IID_IShellFolder, &psfPrinters);
psfPrinters->EnumObjects(hwnd, SHCONTF_NONFOLDERS, &pEnum);
while (pEnum->Next(1, &pidl, 0) == S_OK)
{
    psf->GetDisplayNameOf(pidl, SHGDN_NORMAL, &strName);
    StrRetToBuf(&strName, pidl, chBuf, _countof(chBuf));
    if (_wcsicmp(chBuf, pszPrinterToLookFor) == 0)
    {
        // printer matches
        // build full pidl (pidlPrinters + pidl)
        // pass to SHGetFileInfo with SHGFI_PIDL flag to get icon
    }
}
于 2012-09-01T01:37:17.440 回答