|
-
Feb 6th, 2004, 05:13 PM
#1
Thread Starter
Registered User
folder icons
is there a way to get the icon for a specific folder (if it has been customized in windows)?
and get icons for things like my computer / desktop / my documents / ???
thanks.
-
Feb 6th, 2004, 05:34 PM
#2
Lively Member
like to use on your form? search for *.ico under all files/folders... you should find all icons saved on ur comp then...
-
Feb 6th, 2004, 05:44 PM
#3
Hi.
This should work both for files and folders.
Just specify the path for the folder as filename.
VB Code:
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" (ByVal pszPath As String, ByVal dwFileAttributes As Integer, ByRef psfi As SHFileInfo, ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As IntPtr
Private Const SHGFI_ICON = &H100
Private Const SHGFI_LARGEICON = &H0
Private Const SHGFI_USEFILEATTRIBUTES = &H10
Private Structure SHFileInfo
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
Public Function ExtractIcon(ByVal Filename As String) As Drawing.Icon
Dim sh As New SHFileInfo()
Dim hwnd As IntPtr
hwnd = SHGetFileInfo(Filename, 0, sh, Marshal.SizeOf(sh), SHGFI_ICON Or SHGFI_LARGEICON Or SHGFI_USEFILEATTRIBUTES)
hwnd = Nothing
Return Drawing.Icon.FromHandle(sh.hIcon)
End Function
Last edited by pax; Feb 6th, 2004 at 06:12 PM.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 7th, 2004, 12:12 AM
#4
Frenzied Member
how do we need to return this? ifn a textfle? message box?
-
Feb 7th, 2004, 03:37 AM
#5
Originally posted by thephantom
how do we need to return this? ifn a textfle? message box?
I'm not sure I understand the question?!?
If you are refering to the function above, it just returns a System.Drawing.Icon object.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 7th, 2004, 08:31 AM
#6
Thread Starter
Registered User
i want it so that i can add it to a treenode as the image.
i think i need to use imagelist for that...
haven't looked into it yet, since i didn't know if it was possible to get folder icons...
now that i know how, i'll work on implementing it...
thanks for the code pax.
-
Feb 7th, 2004, 10:28 AM
#7
Frenzied Member
Why would you declare the struct private, but all it's members public?
-
Feb 7th, 2004, 09:18 PM
#8
Frenzied Member
Originally posted by pax
I'm not sure I understand the question?!?
If you are refering to the function above, it just returns a System.Drawing.Icon object.
I was trying to figure out how to use the function. Like, what would call the procedure? How do I use the return value? Is the return used as a property? like example: imageOfSomething = {the procedure call here}
I also can't figure out what folder or file you mention as the path. would that be a .dll such as system32.dll or similar that houses many icons?
can't really explain what I don't know very well lol
-
Feb 8th, 2004, 08:52 AM
#9
Oh, I think I get now...
To get the icon for a JPG image for example just call the function ExtractIcon("*.jpg")
That will return the same icon you'd expect to see in the explorer for a JPG image.
You could also call it with a folder like ExtractIcon("C:\Temp")
That should return the same icon as the C:\Temp folder has in the explorer.
This function can't get the icons from a icon resource file like DLL.
You need to use the ExtractIcon API for that, cos' you need to specify an index in case there are multiple icons.
I think it would be something like this:
VB Code:
Private Declare Function Extract_Icon Lib "shell32.dll" Alias "ExtractIconEx" (ByVal lpszExeFileName As String, ByVal nIconIndex As Integer, ByRef hIconLarge As IntPtr, ByRef hIconSmall As IntPtr, ByVal IconCount As Integer) As IntPtr
Public Function ExtractIconFromFile(ByVal Filename As String, ByVal IconIndex As Integer, ByVal IconSize As iSize) As Drawing.Icon
Dim hIconLarge As IntPtr
Dim hIconSmall As IntPtr
Extract_Icon(Filename, IconIndex, hIconLarge, hIconSmall, 1)
If IconSize = iSize.Large Then
Return Drawing.Icon.FromHandle(hIconLarge)
Else
Return Drawing.Icon.FromHandle(hIconSmall)
End If
End Function
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 9th, 2004, 12:56 PM
#10
Frenzied Member
I see now, that makes a lot of sense.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|