I\'m trying to load the default HICON that explorer displays for:
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.
It's probably in explorer.exe.
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
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.
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"
In Visual Studio:
VS will open the file using the resource explorer. You can now look at all the icon & other resources embedded in shell32.dll.