Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the drive icons as used in Windows Explorer?

Windows 7 has very nice icons for each drive when you view "Computer". It puts the right icon for CDs, SD cards, USB sticks, USB hard drives, etc.

It looks like this:

Driving

I would like to access those icons and use the right ones in my UI. I have tried various methods of accessing folder icons and file icons, but nothing works. What doesn't work:

  • Icon.ExtractAssociatedIcon("F:\")

  • SHGetFileInfo("F:\", 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);

  • ShellObject.FromParsingName("F:\").Thumbnail

What else can I try, or what am I doing wrong?

EDIT: I am not looking for a source of icons, I am trying to get the correct icon for each drive.

like image 850
Sugrue Avatar asked Oct 11 '12 13:10

Sugrue


2 Answers

After a lot of digging, I found this: https://tabbles.net/how-to-have-large-file-icons-with-shgetfileinfo-in-c/

The issue is that SHGetFileInfo can get small, pre-XP, style icons which are 16x16, but to get the larger modern Vista and Win7 'Jumbo' icons, which are up to 256x256, you need to use more complex multi-step method. The link provides code.

like image 189
Sugrue Avatar answered Oct 16 '22 22:10

Sugrue


You should be careful what icons you use since a lot of them cannot be licensed. But you sure are allowed to use the ones you find under

c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033\VS2010ImageLibrary.zip (example for Visual Studio 2010)

or

c:\Program Files (x86)\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary\VS2005ImageLibrary.zip (exampel for Visual Studio 2005)

like image 24
bitbonk Avatar answered Oct 16 '22 22:10

bitbonk