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:
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With