How to get the folder open icon using the SHGetFileInfo () method?

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 is the problem: I found that with this approach I can easily get the folder icon. But I could not get my open icon when I set the fourth method parameter SHGetFileInfoas SHGFI_PIDL | SHGFI_OPENICON. hIconof FileInfoalways NULL, and I don't know why.

Can someone tell me how to fix this problem?

+3
source share
1 answer

From the comments:

I solved the problem. Change the fourth parameter from SHGFI_PIDL | SHGFI_OPENICONto SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_ICON | SHGFI_OPENICON, after which I was able to get the open icon of the specified folder.

0
source

Source: https://habr.com/ru/post/1711973/


All Articles