views:

265

answers:

0

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. Thanks very much!