It is currently Fri Dec 06, 2019 3:41 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Resource files
PostPosted: Wed Jun 10, 2009 4:27 pm 
Offline
User
User

Joined: Wed Jun 03, 2009 9:04 pm
Posts: 46
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?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 10, 2009 4:30 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7439
Location: Norway
This should have been asked in coding questions.

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 10, 2009 6:40 pm 
Offline
User
User

Joined: Wed Jun 03, 2009 9:04 pm
Posts: 46
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 10, 2009 8:04 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7439
Location: Norway
Quote:
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? ...)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 11, 2009 10:14 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10525
Location: Beyond the pale...
Quote:
(Maybe because I'm at forum instead of coding? ...)


lol. :lol:

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jun 12, 2009 5:41 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 507
Location: Doubs - France
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:
#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:
#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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 1:50 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
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 :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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 2:01 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5755
Location: Berlin - Germany
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.71 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.2 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 3:02 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 3:38 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
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:
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:
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 3:53 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
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

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 4:17 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 22, 2004 4:12 pm
Posts: 2448
Location: Norway
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 4:57 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 26, 2009 5:08 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
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:
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye