Get icon file - problem with SHGetFileInfo
Posted: Fri Jan 28, 2005 8:53 pm
Hello,
I need a function to get icon 16*16 or 32*32 associated to a file
But the function SHGetFileInfo don't work with all icon on XP
And it's the only function I know
The problem is the function SHgetFileInfo have a problem with the transparency level of the color.
See this example :
I create an icon 32*32 in a file. this icon is a red box this a custom transparency level.
And I display this icon with the function SHGetfileInfo
you can change the transparency level with the trackbar
If the transparency level is >= 128, no problem
But if the transparency level is < 128, the function SHGetFileInfo don't work correctly
I display my icon also with the function ExtractIconEx and I have no problem with this function but it's only work with *.ico, *.exe or *.dll file

The window explorer or GadgetExplorer have no problem with my icon.
How can i do the same ? Coule you help me.
thanks for your help (and sorry for mystakes)
I need a function to get icon 16*16 or 32*32 associated to a file
But the function SHGetFileInfo don't work with all icon on XP
And it's the only function I know
The problem is the function SHgetFileInfo have a problem with the transparency level of the color.
See this example :
I create an icon 32*32 in a file. this icon is a red box this a custom transparency level.
And I display this icon with the function SHGetfileInfo
you can change the transparency level with the trackbar
If the transparency level is >= 128, no problem
But if the transparency level is < 128, the function SHGetFileInfo don't work correctly
I display my icon also with the function ExtractIconEx and I have no problem with this function but it's only work with *.ico, *.exe or *.dll file

Code: Select all
Procedure CreateIcon(Transparency.l)
; This procedure create an icon
If CreateFile(0, "test" + Str(Transparency) + ".ico")
WriteLong(65536)
WriteWord(1)
WriteByte(32)
WriteByte(32)
WriteLong(65536)
WriteWord(32)
WriteLong(4264)
WriteLong(22)
WriteLong(40)
WriteLong(32)
WriteLong(64)
WriteWord(1)
WriteWord(32)
WriteLong(0)
WriteLong(4224)
WriteLong(0)
WriteLong(0)
WriteLong(0)
WriteLong(0)
For n = 1 To 32
For nn = 1 To 32
WriteByte(0)
WriteByte(0)
WriteByte(255)
WriteByte(Transparency)
Next
Next
For n = 1 To 32
WriteLong(0)
Next
CloseFile(0)
EndIf
EndProcedure
; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 500, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget, "Test") = 0 Or CreateGadgetList(WindowID()) = 0
End
EndIf
Transparency = 128
CreateIcon(Transparency)
IconPath.s = "test" + Str(Transparency) + ".ico"
SHGetFileInfo_(IconPath, 0, @InfosFile.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_ICON)
Icone1 = InfosFile\hIcon
ImageGadget(0, 10, 10, 32, 32, Icone1)
TextGadget(#PB_Any, 10, 50, 100, 50, "SHGetFileInfo")
ExtractIconEx_(IconPath, IconIndex, @Icone2, 0, 1)
ImageGadget(1, 110, 10, 32, 32, Icone2)
TextGadget(#PB_Any, 110, 50, 100, 50, "ExtractIconEx" + Chr(10) + "But there only works with *.ico, *.exe or *.dll")
TrackBarGadget(10, 10, 200, 480, 20, 1, 255)
SetGadgetState(10, Transparency)
TextGadget(11, 10, 230, 290, 15, "icon transparency = " + Str(Transparency))
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
Select EventGadgetID()
Case 10
DestroyIcon_(Icone1)
DestroyIcon_(Icone2)
DeleteFile("test" + Str(Transparency) + ".ico")
Transparency = GetGadgetState(10)
TextGadget(11, 10, 230, 290, 15, "icon transparency = " + Str(Transparency))
CreateIcon(Transparency)
IconPath.s = "test" + Str(Transparency) + ".ico"
SHGetFileInfo_(IconPath, 0, @InfosFile.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_ICON)
Icone1 = InfosFile\hIcon
SetGadgetState(0, Icone1)
ExtractIconEx_(IconPath, IconIndex, @Icone2, 0, 1)
SetGadgetState(1, Icone2)
InvalidateRect_(WindowID(), 0, 1)
UpdateWindow_(WindowID())
EndSelect
EndIf
Until Event = #PB_EventCloseWindow
DestroyIcon_(Icone1)
DestroyIcon_(Icone2)
DeleteFile("test" + Str(Transparency) + ".ico")
EndHow can i do the same ? Coule you help me.
thanks for your help (and sorry for mystakes)
