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

3

6

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.

Schwarzwald answered 11/10, 2012 at 13:7 Comment(2)
When you say your solutions don't work, what icons do they actually return ? – Jacintajacinth
ExtractAssociatedIcon and ShellObject throw exceptions because the drive is not a file. SHGetFileInfo returns a low res generic icon, not the icon specific for each drive. – Schwarzwald
S
4

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.

Schwarzwald answered 12/10, 2012 at 15:42 Comment(1)
Link is obsolete πŸ˜• – Geny
P
2

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)

Pulmonary answered 11/10, 2012 at 13:10 Comment(1)
Thanks. I guess my real question is how to know which icon to use for each drive? – Schwarzwald
P
0

I believe they are embedded in here:

%SystemRoot%\system32\SHELL32.dll
Pericope answered 11/10, 2012 at 13:10 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.