Hi,
resource files are not really needed with PureBasic, because there is another way of working and they are windows related. Nevertheless, you can work with resource files just like in other programming languages. Whether this is useful or not, I would leave to you.
Here is a small example how it can work.
I only use the stringtable and the language to display texts depending on the system language.
ps. i have never used this productively.
you need 3 files stringtable.h, stringtable.rc, text-program.pb
Code: Select all
// stringtable.h
#define LANG_ENGLISH 0
#define LANG_GERMAN 1
#define SUBLANG_DEFAULT 0
#define txtHelloWorld 100
#define btnOk 101
#define btnCancel 102
The separation into h-file and rc-file is common, because the h-file is used in the source code. Under PB the content of the h-file can also be written directly in the rc-file (i guess, not tested).
Code: Select all
/*
* stringtable.rc
*/
#include "StringTable.h"
STRINGTABLE
LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
BEGIN
txtHelloWorld, "Hello World"
btnOk, "Ok"
btnCancel, "Cancel"
End
STRINGTABLE
LANGUAGE LANG_GERMAN, SUBLANG_DEFAULT
BEGIN
txtHelloWorld, "Hallo Welt"
btnOk, "Ok"
btnCancel, "Abbrechen"
End
Code: Select all
; ***************************************************************************
; *** File: Test_my_stringtable_resource.pb
; ***************************************************************************
Global ghInstance = GetModuleHandle_(#Null) ;' the handle to the application itself
Procedure.s Language(uID)
Protected result$, buf${#MAX_PATH} ;' #MAX_PATH == 260 -- existing constant in PB (as a lazy programmer)
If LoadString_(ghInstance, uID, @buf$, #MAX_PATH) ;' returns number of characters in the string resource
result$ = buf$
EndIf
ProcedureReturn result$
EndProcedure
Enumeration EWindows
#WND_Main
EndEnumeration
Enumeration EResourceConstants 100
#TXT_HelloWorld
#BTN_Ok
#BTN_Cancel
EndEnumeration
If OpenWindow(#WND_Main, #PB_Ignore, 0, 240, 200, "Test Resource.rc File", #PB_Window_SystemMenu)
TextGadget(#TXT_HelloWorld, 8, 8, 224, 20, Language(#TXT_HelloWorld))
ButtonGadget(#BTN_Ok, 120, 40, 95, 25, Language(#BTN_Ok))
ButtonGadget(#BTN_Cancel, 120, 70, 95, 25, Language(#BTN_Cancel))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If MessageRequester("DEBUG", "DEBUG" + #LF$ + "Close now?", #MB_YESNO) = #IDYES
Break
EndIf
Case #PB_Event_Gadget
If MessageRequester("DEBUG", "DEBUG" + #LF$ + "You pressed '" + Language(EventGadget()) + "' " + #LF$ + "Close now?", #MB_YESNO) = #IDYES
Break
EndIf
; Select EventGadget()
; Case #BTN_Cancel
; Break
; Case #BTN_Ok
; Break
; EndSelect
EndSelect
ForEver
EndIf ; OpenWindow
End
Steps to do:
1. Add the resource file (here: stringtable.rc) to the PB source (here: Test_my_stringtable_resource.pb)
use the Menu: Compiler | Compiler Options ... Tab: Resources
filetype is default PORC resource scripts (*.rc)
2. compile the pb-source file as usual
the PB tool chain is taking care of the rc file and compiles it to an .res file and linked it statically to the executable. (Thats how I believe its working under the hood.)
You can use the following MSDN help pages to get more information about resource definition (on windows)
https://docs.microsoft.com/en-us/window ... urce-files
and important could be the section about resource definition statements
https://docs.microsoft.com/en-us/window ... statements