0

Is there any way to embed Icons from Shell32 into an Access application?

Ideally I'd like to have them stored as images (perhaps in an ImageList) but it doesn't really matter, as long as I can use them in the application. It appears that the following code is CLOSE to what I want, but I can't adapt it to VBA since I have a limited knowledge of VB and APIs

Private Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" _
(ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long
Private Declare Function DrawIcon Lib "user32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function DestroyIcon Lib "user32" _
(ByVal hIcon As Long) As Long

Private Sub Form_Load()
Dim mIcon As Long
Dim n As Integer, iCount As Long
Dim xPos As Long, yPos As Long

iCount = ExtractIconEx("C:\Windows\System32\Shell32.dll", -1, 0&, 0&, 1)
For n = 0 To iCount
    ExtractIconEx "C:\Windows\System32\Shell32.dll", n, mIcon, 0&, 1&
    DrawIcon Me.hwnd, 0, 0, mIcon
    DestroyIcon mIcon
    xPos = xPos + 32
    xPos = 0
    yPos = yPos + 32
Next n

End Sub
Elbert Villarreal
  • 1,696
  • 1
  • 11
  • 22
Jiminy Cricket
  • 1,377
  • 2
  • 15
  • 24

1 Answers1

0

Use the function

ExtractAssociatedIcon 

and pass as a parameter the icon index.

See this post:

http://www.bigresource.com/VB-Extract-Associated-Icon-to-ImageList-8vp7SQUKBe.html

Oscar
  • 13,594
  • 8
  • 47
  • 75
  • Thanks for the reply. Will this port to VBA? I know APIs should, but I'm getting a debug error saying ListImage user type isn't present. Is there a missing reference, perhaps? – Jiminy Cricket Mar 26 '14 at 22:01
  • I don't think you need an image list, take this as just a sample and use it to suite your needs. You can extract the desired icon and assign it directly, even if without knowing your app is hard to tell. – Oscar Mar 26 '14 at 23:40
  • Apologies for not being able to get this. To be more specific, my application will run primarily in MS Access, as part of the specification, I would like to create an image on a form; the picture of which will be an icon from Shell32. I can't quite get the above code to work. Do you have any further advice? – Jiminy Cricket Mar 27 '14 at 08:57
  • I've found something similar (I think) - I've updated my question – Jiminy Cricket Mar 27 '14 at 13:22
  • Did you found anything that helps to extract the icons inside shell32.dll??? it seems that is not possible (by now) – Elbert Villarreal Mar 10 '16 at 17:30
  • @ElbertVillarreal It should be trivial. Try this one, but htere should be many more options: http://www.nirsoft.net/utils/iconsext.html – Oscar Mar 11 '16 at 09:43