3

This is what I did:

LPMALLOC malloc;
LPITEMIDLIST pidl;
SHFILEINFO FileInfo;
SFGAOF sfGao;

if (SUCCEEDED(SHGetMalloc(&malloc))
{
    if (SUCCEEDED(SHParseDisplayName(strDirPath, NULL, &pidl, SFGAO_FOLDER, &sfGao)))
    {
        SHGetFileInfo((LPCWSTR)(PCHAR(pidl)), 0, &FileInfo, sizeof(FileInfo), SHGFI_PIDL | SHGFI_ICON);
        CDC* pDC = GetWindowDC();
        pDC->DrawIcon(10, 10, FileInfo.hIcon);
        ReleaseDC(pDC);
    }
    malloc->Free(pidl);
}
malloc->Release();

Here's the problem: I found that I can get the icon of a folder easily with this approach. But I could not get its open icon, when I set the fourth parameter of SHGetFileInfo method to be SHGFI_PIDL | SHGFI_OPENICON. The hIcon of FileInfo is always NULL, and I don't know why.

Can anyone tell me how to fix the problem?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
quantity
  • 4,051
  • 3
  • 23
  • 20
  • 2
    I have resolved the problem. Modify the fourth parameter from SHGFI_PIDL | SHGFI_OPENICON to SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_OPENICON, then I was able to retrieve the open icon of the specified folder. – quantity Jul 07 '09 at 07:39
  • 4
    Maybe you should add this as an answer to your own question. – tronda Jul 07 '09 at 12:41

1 Answers1

0

From the comments:

I have resolved the problem. Modify the fourth parameter from SHGFI_PIDL | SHGFI_OPENICON to SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_OPENICON, then I was able to retrieve the open icon of the specified folder.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203