I’m looking for a way to get the icon of a folderitem as used by the operating system. Unfortunately, I found no cross-platform method (it should work on OS X and Windows) that does not involve some kind of commercial plugins.
I’m not familiar with system operating calls (“declares”), but maybe someone has written a solution and is willing to share it.
Thanks; but I can live with declares, since I also want to learn something about programming not how to use black boxes (not meant offending, please excuse).
BTW. I must confess that I find MBS quite overpriced, but that may be my personal opinion only.
I came in here to also say MBS does a great job of solving this.
And now I also want to say that considering what is available in MBS, the fact that you can buy it as a whole or buy individual pieces, and that it’s endlessly updated, it’s more than worth the money. Not starting a flame war, just supporting a harding working community member with my personal opinion.
To not start a fight here I’ll going to ignore any further replies asking to use commercial plugins. That’s just not my idea of programming nor do I think will it help people to really work productive. I had much trouble in the past as I relied upon others (closed-source) work.
In the meantime I found on macoslib two methods that are doing the job (for all interested in: see MacOSFolderItemExtension in the package on https://github.com/macoslib/macoslib.git . I will now try to understand what these methods do and then use them. Learned something new today.
However, I’m still looking for a method that works on Windows. I’m currently searching the Windows Functionality Suite on github, but can’t find something. Any help would be appreciated.
I’m looking for a way to get the icon of a folderitem as used by the operating system. Unfortunately, I found no cross-platform method (it should work on OS X and Windows) that does not involve some kind of commercial plugins.
I’m not familiar with system operating calls (“declares”), but maybe someone has written a solution and is willing to share it.
There is a difference between suggesting and asking. In the end, you do as you please.
You were the one asking for a solution. I merely suggested.
Good luck in your discovery.
For Windows, only executable such as EXE and DLL have icons in them. There is very little available about how to get the icon used by the system for each filetype.
Function DefaultIconForFile(File As FolderItem, Size As Integer = 32) As Picture
#If TargetWin32 Then
Declare Function SHGetFileInfoW Lib "Shell32" (FilePath As WString, Attribs As Integer, Info As Ptr, InfoSize As Integer, Flags As Integer) As Boolean
Declare Function DrawIconEx Lib "User32" (hDC As Integer, xLeft As Integer, yTop As Integer, hIcon As Integer, cxWidth As Integer, _
cyWidth As Integer, StepIfAniCur As Integer, FlickerFreeDraw As Integer, Flags As Integer) As Boolean
Declare Function DestroyIcon Lib "User32" (hIcon As Integer) As Integer
Const SHGFI_ICON = &h000000100
Dim info As New MemoryBlock(352) ' a SHFILEINFO structure
If Not SHGetFileInfoW(File.Name, 0, info, info.Size, SHGFI_ICON) Then Return Nil
Dim ico As New Picture(size, size, 32)
ico.Transparent = 1
Dim hIcon As Integer = info.Int32Value(0)
Call DrawIconEx(ico.Graphics.Handle(1), 0, 0, hIcon, size, size, 0, 0, &h3)
Call DestroyIcon(hIcon)
Return ico
#endif
End Function