Where can I find the default icons used for folders and applications?

前端 未结 8 1784
闹比i
闹比i 2021-01-03 09:49

I\'m trying to load the default HICON that explorer displays for:

  • An open folder
  • An exe that has no embedded default icon of its own. This can also
8条回答
  •  天命终不由人
    2021-01-03 10:04

    Use the SHGetFileInfo API.

    SHFILEINFO sfi;
    SecureZeroMemory(&sfi, sizeof sfi);
    
    SHGetFileInfo(
        _T("Doesn't matter"),
        FILE_ATTRIBUTE_DIRECTORY,
        &sfi, sizeof sfi,
        SHGFI_ICON | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
    

    will get you the icon handle to the folder icon.

    To get the 'open' icon (i.e., the icon where the folder is shown as open), also pass SHGFI_OPENICON in the last parameter to SHGetFileInfo().

    [edit]

    ignore all answers which tell you to poke around in the registry! Because that won't work reliably, will show the wrong icons if they're customized/skinned and might not work in future windows versions. Also, if you extract the icons from system dlls/exes you could get into legal troubles because they're copyrighted.

提交回复
热议问题