Marshow
asked on
ExtractAssociatedIcon
Need some help with the ExtractAssociatedIcon function,
When I use the function the return value is the handle of the associated icon, but it is in 32x32 format which causes the icon to be blurry when i use the DrawIconEx at 16x16 size.
Therefore I chosed to extract the 16x16 icon manually by using the path that GetAssociatedIcon is supposeed to receive (IconExe variable and IconIndex variable).
but the problem is that the function always receive the "c:\windows\system\shell32 .dll" file?! instead of the actuall icon file. It causes the extracticonex to always receive the same icon.. why????
anyone have a solution?
----------------
'Declarations
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
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 DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Const DI_MASK = &H1
Const DI_IMAGE = &H2
Const DI_NORMAL = DI_MASK Or DI_IMAGE
Const MAX_PATH = 260
Dim mIcon As Long
Dim IconExe As String
Dim IconIndex As Long
Dim glLargeIcons() As Long
Dim glSmallicons() As Long
ReDim glLargeIcons(0)
ReDim glSmallicons(0)
Dim X As Integer
IconExe = "c:\myfile.txt"
IconExe = IconExe & Space(MAX_PATH - Len(IconExe))
IconIndex = 0
'Here is the problem, the fu**ing function doesn't work
mIcon = ExtractAssociatedIcon(App. hInstance, IconExe, IconIndex)
Call ExtractIconEx(IconExe, IconIndex, glLargeIcons(0), glSmallicons(0), 1)
DrawIconEx Picture1.hdc, 0, 0, glSmallicons(0), 16, 16, 0, 0, DI_NORMAL
DestroyIcon mIcon
For X = 0 To UBound(glLargeIcons)
DestroyIcon glLargeIcons(X)
DestroyIcon glSmallicons(X)
Next X
When I use the function the return value is the handle of the associated icon, but it is in 32x32 format which causes the icon to be blurry when i use the DrawIconEx at 16x16 size.
Therefore I chosed to extract the 16x16 icon manually by using the path that GetAssociatedIcon is supposeed to receive (IconExe variable and IconIndex variable).
but the problem is that the function always receive the "c:\windows\system\shell32
anyone have a solution?
----------------
'Declarations
Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long
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 DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Const DI_MASK = &H1
Const DI_IMAGE = &H2
Const DI_NORMAL = DI_MASK Or DI_IMAGE
Const MAX_PATH = 260
Dim mIcon As Long
Dim IconExe As String
Dim IconIndex As Long
Dim glLargeIcons() As Long
Dim glSmallicons() As Long
ReDim glLargeIcons(0)
ReDim glSmallicons(0)
Dim X As Integer
IconExe = "c:\myfile.txt"
IconExe = IconExe & Space(MAX_PATH - Len(IconExe))
IconIndex = 0
'Here is the problem, the fu**ing function doesn't work
mIcon = ExtractAssociatedIcon(App.
Call ExtractIconEx(IconExe, IconIndex, glLargeIcons(0), glSmallicons(0), 1)
DrawIconEx Picture1.hdc, 0, 0, glSmallicons(0), 16, 16, 0, 0, DI_NORMAL
DestroyIcon mIcon
For X = 0 To UBound(glLargeIcons)
DestroyIcon glLargeIcons(X)
DestroyIcon glSmallicons(X)
Next X
See this free tool: http://vbaccelerator.com/codelib/gfx/iconex.htm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"c:\windows\system\shell32 .dll" is where all (well most) of the windows standard icons are stored - so the function is working correctly - there are no ICO files for the standard filetype icons installed with windows.