Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Oct 17, 2019 6:51 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: How can I get a picture object form a folderitem's icon?
PostPosted: Sat Nov 12, 2011 9:58 pm 
Offline

Joined: Fri Sep 30, 2005 10:49 pm
Posts: 504
Hello,
How can I get a picture object form a folderitem's icon?
Thanks.
Lennox


Top
 Profile  
Reply with quote  
 Post subject: Re: How can I get a picture object form a folderitem's icon?
PostPosted: Sun Nov 13, 2011 2:28 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
For the icons embedded into executables, the following function will return the icon of the requested size in a Picture, or Nil:

Function GetIcon(File As FolderItem, Size As Integer = 32) As Picture
Declare Function ExtractIconExW Lib "Shell32" (lpszFile As WString, ByVal nIconIndex As Integer, _
phiconLarge As Ptr, phiconSmall As Ptr, ByVal nIcons As Integer) As Integer
Declare Function DrawIconEx Lib "User32" (hDC As Integer, xLeft As Integer, yTop As Integer, _
hIcon As Integer, cxWidth As Integer, cyWidth As Integer, istepIfAniCur As Integer, hbrFlickerFreeDraw As Integer, diFlags As Integer) As Integer
Declare Function DestroyIcon Lib "User32" (hIcon As Integer) As Integer

If File = Nil Then Return Nil

Dim theIcon As New Picture(size, size, 32)
Dim icoLarge As New MemoryBlock(4)
Dim icoSmall As New MemoryBlock(4)

Call ExtractIconExW(File.AbsolutePath, 0, icoLarge, icoSmall, 1)
If icoLarge.Int32Value(0) = 0 Then
Return Nil
Else
Call DrawIconEx(theIcon.Graphics.Handle(Graphics.HandleTypeHDC), 0, 0, icoLarge.Int32Value(0), size, size, 0, 0, &H3)
End If

Call DestroyIcon(icoSmall.Int32Value(0))
Call DestroyIcon(icoLarge.Int32Value(0))

Return theIcon


Exception
Return Nil
End Function

_________________
Boredom Software


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group