Resource files

Everything else that doesn't fall into one of the other PB categories.
gedumer
User
User
Posts: 48
Joined: Wed Jun 03, 2009 9:04 pm

Resource files

Post by gedumer »

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?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

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
gedumer
User
User
Posts: 48
Joined: Wed Jun 03, 2009 9:04 pm

Post by gedumer »

Trond wrote:This should have been asked in coding questions.
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.

Thanks for the solution... so much to learn... so little time.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

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.
On second thoughts, the question about resource files could go in this forum.
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. :wink: (Maybe because I'm at forum instead of coding? ...)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

(Maybe because I'm at forum instead of coding? ...)
lol. :lol:
I may look like a mule, but I'm not a complete ass.
Denis
Enthusiast
Enthusiast
Posts: 704
Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France

Post by Denis »

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.

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"
and here is the code i use to load images

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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

I think that you go to make peepee in your pants another time
But i have again an hilarous question for you :oops:

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
ImageThe happiness is a road...
Not a destination
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Kwaï chang caïne wrote: I read you talk about file ressource ".RC"
Is it the same file that the RC of VB ??? :roll: p
Yes
Kwaï 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:
You can use the PORC.exe in PBCompilers Dir or simple Add the RC-Script
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.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Hello and thanks a lot MASTER TSSOFT for your explanation 8)
For a time KCC have not say a big dogshit :D

Well, i can take off my helmet ......because i don't like the shot in the head :lol:

Again thanks, i wish you a good day
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Like usually, i try to do a new thing and.......i don't can :D
Why my PC never do what i want :cry:

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 :-(
It's simple because, they are a generator of RES in VB :oops:

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 :cry:

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.
It's strange, because i have search example to use RC or PORC in the web, and i don't have find something interesting :cry:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Well i have created another file, and i have put the name of this another file in the try.txt

I'm happy, i have another and new error now :D
PORC: try.txt(2): warning: Unrecognized or misplaced token: EOF
The ".RES" is created but he is empty :cry:
ImageThe happiness is a road...
Not a destination
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

gedumer wrote:so much to learn... so little time.
Are you dying soon? :shock: Hope not! :wink:
I like logic, hence I dislike humans but love computers.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Perhaps me i died soon, with all the shot on my head against the wall, the fault of this ressource files :lol:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Yeeeaahh !!!
I have found like a grow :D

I confuse between STRINGTABLE and STRINGDATA
Now that's work fine for the STRINGDATA :D

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
And i try to create the same RES in PB.... :roll:
ImageThe happiness is a road...
Not a destination
Post Reply