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

前端 未结 8 1726
闹比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.

    0 讨论(0)
  • 2021-01-03 10:06

    It's probably in explorer.exe.

    0 讨论(0)
  • 2021-01-03 10:10

    Vista added SHGetStockIconInfo and so on NT6+ its the best way.

    Archive of MSDN documentation that shows the available icons

    On older platforms, SHGetFileInfo like Stefan says.

    If you want to use undocumented stuff, the first 5 or so icons in the system image list includes the default folder and application icon (system image list is NOT shared on NT, but for some reason, all the copies get the first 5 or so icons without asking for them with SHGetFileInfo)

    These default icons come from shell32.dll by default, but can be changed in the registry:

    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons

    0 讨论(0)
  • 2021-01-03 10:13

    I think they are in %windir%\system32\SHELL32.dll

    Found some code in the internet, try if that works:

    HINSTANCE hDll;
    hDll = LoadLibrary ( "SHELL32.dll" );
    wincl.hIcon   = LoadIcon (hDll , MAKEINTRESOURCE ( 1 ));
    wincl.hIconSm = LoadIcon (hDll, MAKEINTRESOURCE ( 2 ));
    

    Edit: Windows has a lot more icons in the "moricons.dll", but I think the file and folder icons should all be in the shell32.dll. Remind, that icons in Vista have different resolutions, up to 256x256, so the icon you are looking at a resolution 32x32 might look different then the full resolution version of the same icon.

    0 讨论(0)
  • 2021-01-03 10:14

    If you are in MFC, following code for loading icons should work.

    
        HICON hicon;
        hicon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1));   
    

    In the above example, AfxGetResourceHandle() is the only thing where MFC is used, otherwise LoadIcon is an API call as far as I remember.

    Icons are available in windows\system32\shell32.dll

    If you have visual studio installed, then visual studio is also shipped with a set of icons at a path like this "C:\Program Files\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary"

    0 讨论(0)
  • 2021-01-03 10:17

    In Visual Studio:

    1. click on File|Open
    2. select C:\WINDOWS\System32\Shell32.dll

    VS will open the file using the resource explorer. You can now look at all the icon & other resources embedded in shell32.dll.

    0 讨论(0)
提交回复
热议问题