thank you very much for pinpointing the error in my code that does
not take into account alphanumeric identifiers. And thanks for even
providing two files as examples and for your in depth explanation. I
have to appologize for my sloppiness because I didn't go into depth
and only modified an example from Mistrel for reading an icon from
an IconGroup:
http://www.purebasic.fr/english/viewtopic.php?t=35534
My own work with resources is already several years ago. Examining
my own old routines I discovered that I also took care of possible
alphanumeric identifiers...

In my previous example I only had to declare the linked list IconGroupID()
as String instead of Integer and change the EnumResNameProc() from
Code: Select all
Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
Shared IconGroupID()
AddElement(IconGroupID())
IconGroupID() = ResName
ProcedureReturn #True
EndProcedure
Code: Select all
Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
Shared IconGroupID()
AddElement(IconGroupID())
If ResName & $FFFF0000
IconGroupID() = PeekS(ResName)
Else
IconGroupID() = "#" + Str(ResName)
EndIf
ProcedureReturn #True
EndProcedure
IconGroup names and with the alphanumeric IconGroup names
of your two example files (again tested with PB 4.40 running on
Windows XP Prof SP2 and Windows 7 RC1):
Code: Select all
EnableExplicit
#WindowHeight = 180
#WindowWidth = 240
Define *GrpIconDir.GRPICONDIR
Define i.I
Define IconHandle.I
Define *IconImage.ICONIMAGE
Define LibHandle.I
Define LibName.S = #PB_Compiler_Home + "PureBASIC.Exe"
; Define LibName.S = "CPViewer.Exe"
; Define LibName.S = "ISignup.Exe"
Define MaxHeight.I
Define WindowDC.I
Define xLeft.I
Define yTop.I
NewList IconGroupID.S()
Procedure.I EnumResNameProc(ResHandle.I, ResType.I, ResName.I, AppParam.I)
Shared IconGroupID()
AddElement(IconGroupID())
If ResName & $FFFF0000
IconGroupID() = PeekS(ResName)
Else
IconGroupID() = "#" + Str(ResName)
EndIf
ProcedureReturn #True
EndProcedure
Procedure.I EnumResTypeProc(ResHandle.I, ResType.I, AppParam.I)
If ResType = #RT_GROUP_ICON
EnumResourceNames_(ResHandle, ResType, @EnumResNameProc(), 0)
EndIf
ProcedureReturn #True
EndProcedure
LibHandle = LoadLibraryEx_(@LibName, 0, #LOAD_LIBRARY_AS_DATAFILE)
If LibHandle = 0
MessageRequester("Error", "Unable to load library " + LibName, #MB_ICONERROR)
End
EndIf
EnumResourceTypes_(LibHandle, @EnumResTypeProc(), 0)
OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, "Icon-Library: " + GetFilePart(LibName), #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
yTop = 5
WindowDC = StartDrawing(WindowOutput(0))
ForEach IconGroupID()
*GrpIconDir = LoadResource_(LibHandle, FindResource_(LibHandle, IconGroupID(), #RT_GROUP_ICON))
If *GrpIconDir
xLeft = 5
DrawText(xLeft, yTop, "IconGroup " + IconGroupID() + ":", #Black, #White)
yTop + 25
For i = 0 To *GrpIconDir\idCount - 1
*IconImage = LoadResource_(LibHandle, FindResource_(LibHandle, *GrpIconDir\idEntries[i]\nID, #RT_ICON))
IconHandle = CreateIconFromResourceEx_(*IconImage, *IconImage\icHeader\biBitCount, #True, $00030000, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0)
DrawIconEx_(WindowDC, xLeft + 15, yTop, IconHandle, *GrpIconDir\idEntries[i]\bWidth, *GrpIconDir\idEntries[i]\bHeight, 0, 0, #DI_NORMAL)
DestroyIcon_(IconHandle)
DrawText(xLeft, yTop, "#" + Str(*GrpIconDir\idEntries[i]\nID), #Black, #White)
xLeft + *GrpIconDir\idEntries[i]\bWidth + 30
If MaxHeight < *GrpIconDir\idEntries[i]\bHeight
MaxHeight = *GrpIconDir\idEntries[i]\bHeight
EndIf
Next i
EndIf
yTop + MaxHeight + 10
Next
StopDrawing()
FreeLibrary_(LibHandle)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend