Getting Started
Introduction
Sample Programs
IDEs
History
Advice
Mini-Tutorial
Tutorials
Code Snippets

Resources
Web Sites
More Tutorials
Forums
Vendors/Tools
Books
Magazines
Newsletters
NewsGroups
User Groups
Talk Shows
Blogs

Controls
Overview
Button
Check3State
Checkbox
ComboBox
Frame
Graphic
Image
ImageX
ImgButton
ImgButtonX
Label
Line
ListBox
ListView
Option
Progress Bar
Scrollbar
StatusBar
TAB
TextBox
Toolbar
TreeView

GBIC >> PowerBASIC >> Tutorials >> Resource Files

PowerBASIC Information Center Tutorials
These tutorials were written to help you get a quick, but thorough, understanding of PowerBASIC - the scope of the language as well as it's specific capabilities.

Introduction       Projects       Language           Messages       Functions           Advanced
  • Overview
  • Examples
  • IDE
  • Compilation
  • Distribution
  • Project Files
  • DDT Windows
  • Controls
  • Menus
  • Dialogs  
  • Help Files
  • Resources  
  • Templates  
  • Project Shell  
  • Syntax
  • Operators
  • Data Types
  • Variables
  • Scope
  • Declarations  
  • Procedures
  • Flow Control
  • Windows
  • Messages
  • Callbacks
  • Mouse
  • Keyboard
  • Dialogs
  • Controls
  • Subclassing
  • Arithmetic
  • Trig  
  • Strings
  • Arrays
  • Date/Time
  • Printing
  • Files
  • Folders
  • Keyboard
  • Mouse
  • Sound
  • System
  • Error Traps
  • Debugging
  • Objects
  • Graphics
  • Databases
  • API
  • DLLs
  • ASM
  • Threads
  • Resource Files
    Many applications use external files, such as data files and image files, that must be distributed with the application. Having such files reside on the user's PC can be an issue in at several ways. Users may be tempted to edit the files, possibly making the files unusable by the PowerBASIC application. Or, the update of an application is complicated by the presence of multiple application files.

    Resource files are a way to solve this problem. A resource file is simply a single file which stores the content of many other files.

    Even more useful is PowerBASIC's ability to embed a resource file into the EXE as well as being able to read content from the resource file just as though there it was a standalone file.

    Microsoft language applications also use resource files, but uses a different file format (*.res) than is needed by PowerBASIC applications (*.pbr). The PowerBASIC IDE, however, is able to convert Microsoft resource files to the PowerBASIC format.

    Resource Script File (*.RC)
    The good news is that both Microsoft and PowerBASIC use the same format for creating resource scripts - which are text files that list the resources to be placed in the resource file.

    The text file is called a resouce script and uses a *.rc extension.

    While both PowerBASIC and Microsoft both use the same format for *.rc script file formats, the format is owned by Microsoft. Documentation and tools for creating resource files must be downloaded from Microsoft's MSDN's Resource Compiler page.

    Creating a Resource File
    Even better news is that creating resource files that meet the needs of most PowerBASIC programmers can be done manually, using the PowerBASIC IDE as a text editor and using the file formats described in the next few paragraphs.

    There are at least 3 common uses for resource files - storing images, storing application version information, and storing tables of string data.

    • Storing Images
      To create a resource file containing images, simply create a text file, give it a .rc extension, and include lines similar to the following example.

          add       icon    "add.ico"
          bigger    icon    "bigger.ico"
          blank     icon    "blank.ico"
          bold      icon    "bold.ico"
          car       icon    "car.ico"
          004       icon    "check.ico"
          006       icon    "copy.ico"
          cowgirl   bitmap  "cowgirl.bmp"
          crop      icon    "crop.ico"
      

      Column 1 is the name, or number, of the resource. PowerBASIC supports both types of resource identifiers, so a programmer is free to use either type on each resource.

      Column two is the type of resource. Since PowerBASIC only supports icons and bitmaps, there are only two values you can use.

      Column three is the file name, relative to the *.rc file that has been opened in the PowerBASIC IDE.

    • String Tables
      ... in work

    • Version Information
      ... in work

    Compiling the Resource Script
    To compile a resource script (*.rc), simply open it in the PowerBASIC IDE, then select "Compile and Run" just as though an EXE was to be created.

    The PowerBASIC IDE will recognize the *.rc file extension and run it's resource compiler utilities. Both *.res (Microsoft format) and *.pbr (PowerBASIC format) files will be created.

    Embedding Resource Files
    A resource file may be included in an application by using the #Resource compiler directive, as in the following snippet from a PowerBASIC application.

        #Compile Dll
        #Dim All
        #Resource "prime.pbr"
    

    In this example, the #Resource line tells the compiler to embed the resource file "prime.pbr" into the compiled EXE. Once the compiler is run, the *.pbr file will be contained in the EXE file, ready to be accessed.

    If you have any suggestions or corrections, please let me know.