Resource files
Resource files
I can't find any reference to "Resource" files (.rc) in the PB docs and the forum is so huge it's difficult to track down specific items. Is there such a thing in PB... if not, how do I include bitmap images (.jpg, .png, .bmp, etc) into my executable file so I don't have to load them at run time?
This should have been asked in coding questions.
Code: Select all
CatchImage(0, ?Image)
OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ImageGadget(0, 10, 10, 0, 0, ImageID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
DataSection
Image:
IncludeBinary "c:\map.bmp"
EndDataSection
On second thoughts, the question about resource files could go in this forum.Sorry about that... I've only been on the forum for a few days so I don't all the in's and out's yet.
However, the answer I provided took a different approach (with code) so I thought the question was a coding question. But now I realize you were actually asking about resource files.
Generally it's safe to put it in coding question if you're not sure, though.
Note that you can use actual resource files if you want to, but I have over 5000 posts and I still haven't needed it. (Maybe because I'm at forum instead of coding? ...)
gedumer,
there is an another way using real resource (RC file).
You have to declare in a rc file, your images with RC_DATA type and attach it to your PB file with the ide menu compiler options/resource.
Here is an exemple from my RC file, with PNG and ico format.
In that case ico are not the same as ico resource.
You have to use a language/sublanguage in the rc file anf for image, it's not critical, neutral language is enough.
and here is the code i use to load images
there is an another way using real resource (RC file).
You have to declare in a rc file, your images with RC_DATA type and attach it to your PB file with the ide menu compiler options/resource.
Here is an exemple from my RC file, with PNG and ico format.
In that case ico are not the same as ico resource.
You have to use a language/sublanguage in the rc file anf for image, it's not critical, neutral language is enough.
Code: Select all
#define folder_explorer 0
#define Extraire 1
#define Convertir 2
#define Favoris 3
#define Tools 4
#define Aide 5
#define Apropos 6
#define Quit 7
#define Icone_vierge 20
#define FlecheUp 21
#define FlecheDown 22
#define LANG_NEUTRAL 0
#define SUBLANG_NEUTRAL 0
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
// Les images PNG de la barre d'outils
folder_explorer RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Folder ouvrir.png"
Extraire RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Extraire.png"
Convertir RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Convertir.png"
Favoris RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Favoris.png"
Tools RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Tools.png"
Aide RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Aide.png"
Apropos RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\logo_PB.png"
Quit RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\exit_32x32.png"
// Les icônes
Icone_vierge RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\Icone_vierge.ico"
FlecheUp RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\ArrowUp.ico"
FlecheDown RCDATA "K:\\PureBasic\\Projets\\Editeur d icones\\PureIconManager\\PureIconManger_Tool\\EXAMPLES\\Icone_barre_outils\\ArrowDown.ico"
Code: Select all
#Return_Error = 0
#folder_explorer = 1
Macro LOWORD(Value)
Value & $FFFF
EndMacro
Macro MAKEINTRESOURCE(INT)
LOWORD(INT)
EndMacro
Macro MAKELANGID(primary, sublang)
(((sublang)<<10) | (primary))
EndMacro
Procedure.i Get_RC_DATA_Adress(id)
;///////////////////////////////////////////////////////////////////////////////////////////////////
;//
;// FONCTION: Get_RC_DATA_Adress()
;//
;// BUT: Retourne l'adresse de la ressource RC_DATA de l'id passé en paramètre
;//
;// PARAMS: id - identifiant statique de la ressource RC_DATA
;//
;// RETOURNE: l'adresse mémoire des données
;// Retourne #Return_Error en cas d'error
;//
;///////////////////////////////////////////////////////////////////////////////////////////////////
;// 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
;// mémorise l'instance du fichier
Protected hinst
hinst = GetModuleHandle_(0)
If hinst = 0
ProcedureReturn #Return_Error
EndIf
Find_Resource = FindResourceEx_(hinst, #RT_RCDATA, MAKEINTRESOURCE(id), MAKELANGID(#LANG_NEUTRAL, #SUBLANG_NEUTRAL))
If Find_Resource = #Return_Error
ProcedureReturn #Return_Error
EndIf
LoadResource_RT_RCDATA = LoadResource_(hinst, 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
; and the way to créate your PB image image
Procedure CatchImageEx(img_static_id)
;///////////////////////////////////////////////////////////////////////////////////////////////////
;//
;// FONCTION: CatchImageEx()
;//
;// BUT: charger une image depuis la resource RT_RCDATA
;//
;// PARAMS: img_static_id - identifiant statique de l'image, utilisé pour repérer la resource
;//
;// RETOURNE: rien
;//
;//
;///////////////////////////////////////////////////////////////////////////////////////////////////
;// mémorise l'adresse de la ressource
Protected *memory
*memory = Get_RC_DATA_Adress(img_static_id)
If *memory <> #Return_Error
CatchImage(img_static_id, *memory)
EndIf
EndProcedure
; and how to use it
; for exemple, if you use PNG images , don't forget to use PB image decoder
UsePNGImageDecoder()
CatchImageEX(#folder_explorer)
If IsImage(#folder_explorer) = 0
MessageRequester("Error/Erreur", "Unable to load image in memory", 16)
EndIf
; here display your image with ImageId(#folder_explorer) etc ....
A+
Denis
Denis
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
I think that you go to make peepee in your pants another time
But i have again an hilarous question for you
I read you talk about file ressource ".RC"
Is it the same file that the RC of VB ??? :roll:
Is it possible to convert a file text in ".RES" with PB or i'm forced to use the RC.EXE of VB ??? :roll:
Thanks for your help
But i have again an hilarous question for you
I read you talk about file ressource ".RC"
Is it the same file that the RC of VB ??? :roll:
Is it possible to convert a file text in ".RES" with PB or i'm forced to use the RC.EXE of VB ??? :roll:
Thanks for your help
The happiness is a road...
Not a destination
Not a destination
YesKwaï chang caïne wrote: I read you talk about file ressource ".RC"
Is it the same file that the RC of VB ??? :roll: p
You can use the PORC.exe in PBCompilers Dir or simple Add the RC-ScriptKwaï chang caïne wrote: Is it possible to convert a file text in ".RES" with PB or i'm forced to use the RC.EXE of VB ??? :roll:
to the Compileroptions and the IDE will do this for you
greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Like usually, i try to do a new thing and.......i don't can
Why my PC never do what i want
In VB, i have created a ".RES" with four simples lines in a txt.
For example:
It's simple because, they are a generator of RES in VB
But how can i do exactely, for create the same file with PORC ??? :roll:
I have create a file in "c:\Try.txt " where i have write the same text
I have write in CMD command this, and i have this answer
It's strange, because i have search example to use RC or PORC in the web, and i don't have find something interesting
Why my PC never do what i want
In VB, i have created a ".RES" with four simples lines in a txt.
For example:
Code: Select all
Hello i'm KCC
there are not only the woman
who resist to me...
but also the computer :-(
But how can i do exactely, for create the same file with PORC ??? :roll:
I have create a file in "c:\Try.txt " where i have write the same text
I have write in CMD command this, and i have this answer
Code: Select all
C:\>porc /r Try.txt
PORC: Try.txt(1): error: Unterminated string or char const.
PORC: Try.txt(4): warning: No newline at end of file.
PORC: Try.txt(2): error: File not found: 'there'.
PORC: Try.txt(2): error: File not found: 'woman'.
PORC: Try.txt(3): error: File not found: 'to'.
PORC: Try.txt(4): error: File not found: 'also'.
PORC: Try.txt(4): error: Syntaxe du nom de fichier, de répertoire ou de volume i
ncorrecte.
The happiness is a road...
Not a destination
Not a destination
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
- Kwai chang caine
- Always Here
- Posts: 5353
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Yeeeaahh !!!
I have found like a grow
I confuse between STRINGTABLE and STRINGDATA
Now that's work fine for the STRINGDATA
With VB, i include a file TXT.
And the instruction is :
And i try to create the same RES in PB.... :roll:
I have found like a grow
I confuse between STRINGTABLE and STRINGDATA
Now that's work fine for the STRINGDATA
With VB, i include a file TXT.
And the instruction is :
Code: Select all
Dim vData() As Byte
Dim strText As String
vData = LoadResData("NameOfFile", "NameOfFolder")
strText = Space$(UBound(vData) + 1)
Call CopyMemory(ByVal strText, vData(0), Len(strText))
MsgBox strText
The happiness is a road...
Not a destination
Not a destination