How do I fetch the folder icon on Windows 7 using Shell32.SHGetFileInfo

前端 未结 2 561
谎友^
谎友^ 2020-12-05 14:55

I have the following code which works on Windows XP and Vista - both 32 and 64 bit:

public static Icon GetFolderIcon(IconSize size, FolderType folderType)
{
         


        
2条回答
  •  心在旅途
    2020-12-05 15:34

    You shouldn't specify null as yur first parameter to SHGeFileInfo.

    That's right.

    Use the path to a folder instead (please note that some folders have different (non-standard) icons). You could use the temp folder or your application's root folder for example.

    It doesn't need to be a real (existing) folder path. Any non-empty string will do. e.g.:

    SHGetFileInfo("AnyNonEmptyStringWillDo", FILE_ATTRIBUTE_DIRECTORY, sfi,
          SizeOf(sfi), SHGFI_USEFILEATTRIBUTES or SHGFI_SYSICONINDEX)
    

提交回复
热议问题