Hi SFSxOI,
i use resource in my project to load ico (PNG too).
First, you have to create a resource file (.rc) with notepad or notepad++ or with PelleC ide (etc.).
Resource manage language definitions, if you use icons without language managment, declare language as neutral.
Then define icon static id; those id must be the same as PB id to load ico.
Finally, for each id, define the path for ico file (you must put 2 \\, not only 1).
Here is an rc file example :
Code: Select all
// language definition
#define LANG_NEUTRAL 0
#define SUBLANG_NEUTRAL 0
// static ico id, same as PB enumeration
#define Ico_1 = 1
#define Ico_2 = 2
#define Ico_3 = 3
#define Ico_4 = 4
#define Ico_5 = 5
// language used for resource
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
// ico files to load in resource with static id
Ico_1 RCDATA "D:\\Icone_barre_outils\\Ico1.ico.png"
Ico_2 RCDATA "D:\\Icone_barre_outils\\Ico2.ico.png"
Ico_3 RCDATA "D:\\Icone_barre_outils\\Ico3.ico.png"
Ico_4 RCDATA "D:\\Icone_barre_outils\\Ico4.ico.png"
Ico_5 RCDATA "D:\\Icone_barre_outils\\Ico5.ico.png"
you must attach this rc file to your code with compiler option window, item resources.
following is a piece of code from my project (cleaned up and adapted for this example).
I use this for a while without problem (run on X86 & X64).
You may use Freeimage if needed.
Code: Select all
Define .i
EnableExplicit
Macro MAC_LOWORD(Value)
Value & $FFFF
EndMacro
Macro MAC_MAKEINTRESOURCE(Value)
MAC_LOWORD(Value)
EndMacro
Macro MAC_MAKELANGID(primary, sublang)
(((sublang)<<10) | (primary))
EndMacro
Macro MAC_SUBLANGID(lgid)
((lgid)>>10)
EndMacro
Macro MAC_PRIMARYLANGID(lgid)
((lgid)&$3FF)
EndMacro
#Return_Error = #False
;#LANG_NEUTRAL = 0
;#SUBLANG_NEUTRAL = 0
Enumeration 1 ; ico static id
#Ico_1
#Ico_2
#Ico_3
#Ico_4
#Ico_5
EndEnumeration
Global GLB_hInstance, i
Procedure InitMain()
GLB_hInstance = GetModuleHandle_(0)
EndProcedure
Procedure.i Get_RCDATA_Adress(id)
;// mémorise le handle du bloc d'informations du groupe d'icônes
Protected Find_Resource
;// mémorise le handle du bloc d'information des données de la ressource string
Protected LoadResource_RT_RCDATA
;// mémorise l'adresse mémoire du block d'informations de la ressource chargée en mémoire
Protected *LockResource
;// mémorise la taille des données de la ressource RT_String pour la langue choisie
Protected SizeofResource
Find_Resource = FindResourceEx_(GLB_hInstance, #RT_RCDATA, MAC_MAKEINTRESOURCE(id), MAC_MAKELANGID(#LANG_NEUTRAL, #SUBLANG_NEUTRAL))
If Find_Resource = #Return_Error
ProcedureReturn #Return_Error
EndIf
LoadResource_RT_RCDATA = LoadResource_(GLB_hInstance, Find_Resource)
If LoadResource_RT_RCDATA = #Return_Error
ProcedureReturn #Return_Error
EndIf
*LockResource = LockResource_(LoadResource_RT_RCDATA)
If *LockResource = #Return_Error
ProcedureReturn #Return_Error
EndIf
ProcedureReturn *LockResource
EndProcedure
Procedure.i CatchImageEx(img_static_id)
Protected *memory
*memory = Get_RCDATA_Adress(img_static_id)
If *memory <> #Return_Error
CatchImage(img_static_id, *memory)
EndIf
EndProcedure
InitMain()
If GLB_hInstance = #Null
MessageRequester("Error", "unable to continue", #PB_MessageRequester_Ok)
End
EndIf
OpenWindow(1,0,0,200,100,"test", #PB_Window_ScreenCentered)
;// load the 5 ico in resource
For i = 1 To 5
CatchImageEx(i)
;// check if ok, always check this !
If IsImage(i) = 0
MessageRequester("Error", "unable to continue", #PB_MessageRequester_Ok)
End
EndIf
Next
ImageGadget(1,5,5,32,32,ImageID(#Ico_1))
;etc.