Announcement

Collapse
No announcement yet.

Making a resource file 101 - pls :)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making a resource file 101 - pls :)

    I want to include a small Ding.wav with my .exe so that all i ship is one file MyFile.exe. It can then play the .wav cos its included in it somehow.

    I believe what I need is a Resource file.

    This will be my first resource file ( so be gentle! ) and I have tried to get to grips with it.

    Over the last few weeks i have read Petzold Chap 10, Poffs on resources, rc.hlp, This forum and I still dont get it.

    When I run Rc.exe it launches and quits. I think it needs a script. but ill be damned if i can figure out all the steps. I know that MyFile.exe will have a #Include "myresource.res" or .h or .ddt or .something, and i have my Ding.Wav. But just how to get from A to B ... i give up.

    the rc.hlp says:
    1. Create individual resource files for cursors, icons, bitmaps, dialog boxes, and fonts. To do this, you can use Microsoft Image Editor and Dialog Editor (IMAGEDIT.EXE and DLGEDIT.EXE) and Microsoft Windows Font Editor (FONTEDIT.EXE).
    2. Create a resource-definition file (script) that describes all the resources used by the application.
    3. Compile the script into a resource (.RES) file with RC.
    4. Link the compiled resource files into the application's executable file.

    So i have step 1 allready done - i got my Ding.wav
    Step 4 I think I can do.
    Step 3 how do get Rc.exe to do that?
    Step 2: now what the heck is this?
    it says:
    · Preprocessing directives, which instruct RC to perform actions on the script before compiling it. Directives can also assign values to names.
    · Statements, which name and describe resources.
    OK so Then, I think I need:
    #include (filename)
    The #include directive causes Resource Compiler to process the file specified in the filename parameter. This file should be a header file that defines the constants used in the resource-definition file.

    So now I need a script, executed by rc.exe that wants a statement describing a header file that describes the file i want included??? - Jeeze could this be any harder?

    Could some kind person pretend im a 4yr old and tell me what to do pls.



    ------------------
    Kind Regards
    Mike

  • #2
    To solve problem with creating resource files, I have created a BAT
    file called "C.BAT" that looks like:
    Code:
    c:\pbdll60\bin\rc filename.rc
    c:\pbdll60\bin\pbres filename.res
    For each app where I need a resource file, I copy this bat file into
    the program's folder and change the filename part to whatever I want,
    like in following case, "sound.rc". Sound.rc only needs one line:
    Code:
    DING   SOUND  DING.WAV
    Above saved as "sound.rc", and then just run c.bat (typing just c at
    DOS prompt is enough) to create first .RES file and the the PBR file.

    Then, to play the sound:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Simple sample of how to play a sound from resource file
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    #RESOURCE "SOUND.PBR"
    'created from sound.rc, that looks like: (yes, one line only)
    'DING  SOUND  DING.WAV
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' The main callback function for all controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgCallback()
      IF CBMSG = %WM_COMMAND AND CBCTL = 10 THEN
         CALL PlaySound("DING", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)
      END IF
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' PBMAIN - build dialog and controls
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN
        DIM hDlg AS LONG
     
        DIALOG NEW 0, "Play sound..",,, 90, 30, %WS_CAPTION OR %WS_SYSMENU TO hDlg
        CONTROL ADD BUTTON, hDlg, 10, "Play sound", 10, 4,  70, 14
     
        DIALOG SHOW MODAL hDlg CALL DlgCallback
    END FUNCTION
    A tip for the rc file: if to include a menu, dialog or version resource,
    one has to add: #include "resource.h" to the top of it. By including full
    path to this file, there's no need to have to keep track of where it is,
    like: #include "c:\pbdll60\winapi\resource.h" (wherever you have it)

    Note1: RC.EXE is case sensitive, so "#include" statement must be with small
    letters. Common problem is when one opens an RC file in PB edit and UCASE
    keywords are set, because it then saves that line as #INCLUDE, after which
    RC.EXE will complain..

    Note2. If to only add simple resource, like bitmap, icon or sound, no need
    for resource.h - like in sample above.

    Note3. This attempt to explain probably will qualify under "clear as mud",
    to use one of Lance's favourite expresions. Hope you still will be able
    to understand some of it..


    ------------------


    [This message has been edited by Borje Hagsten (edited April 19, 2001).]

    Comment


    • #3
      Borje,

      That was very clear. I really like the .BAT to avoid that nasty dos prompt. That works great.

      Im still not clear what a .h file is or is for yet.

      Also why do I need to make two files?
      What is a .PBR file
      What is a .res file?
      do they both comprise the "resource"

      If want to include say 3 .wavs in my program I assume the .rc file has 3 lines:
      DING SOUND DING.WAV
      DONG SOUND DONG.WAV
      PING SOUND PING.WAV (why uppercase by the way?)

      and they would be accessed with:
      CALL PlaySound("DING", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)
      CALL PlaySound("DONG", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)
      CALL PlaySound("PING", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)

      whats the "OR %SND_SYNC" about?



      ------------------
      Kind Regards
      Mike

      Comment


      • #4
        DOS promps are beautiful. Make love, not war to your DOS prompt..

        A .h file is a header file. Resource.h contains declared functions and
        values, used by RC.EXE. As I said, not needed for simple resources, only
        when actual programming stuff like menus and dialogs, etc. is included,
        like in the PBnote sample.

        %SND_SYNC means the sound will be played synchronously, that is, whole
        sound will be played before you can play it again. You can also try
        with %SND_ASYNC, to play a-syncronously, that is, you can replay the
        sound right in the middle of last command, while sound still is playing.

        PBR is probably a clever abbreviation of Power Basic Resource. RES
        may be RESource and RC.. Resource Compiler? Wild guesses. Reason for
        two (actually three) files is probably because PB has implemented C
        style resource files in BASIC language in a clever way. While maybe not
        clever when it comes to creation, the idea behind it is very clever.

        Next version of PB's compiler will hopefully have all this built into
        the editor/designer. At least in my dreams it will..

        BTW, upper case because I have old, tired eyes. The more upper, the better.
        You can use lower case or any case you like. I'm positively sure about that,
        I think..


        ------------------

        Comment


        • #5
          In case you have not noticed it before, you can compile RC files into PBR's from within the PowerBASIC IDE... load/create your RC file and press Compile...

          The File|Open dialog has a drop down to select RC files, and the Window|Options dialog includes paths to the Resource Compiler (RC.EXE) and PBRES.EXE.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            I didn't know that...

            Thanks Lance

            ------------------
            Paul Dwyer
            Network Engineer
            Aussie in Tokyo

            Comment


            • #7
              Me neither. Once tried and it didn't work so I assumed it was by design.
              Must have been resource file error then and my mind was too tired to
              make the right assumption. See know that it works, but one must turn
              off UCASE syntax highlighing. Thanks for the tip Lance!

              Makes one wonder what other neat secrets one have missed over the years.
              Wish for next version: Manuals for all parts of the compiler package..


              ------------------

              Comment


              • #8
                mike,

                here is an easy way to make pbr files.

                see: http://www.powerbasic.com/support/pb...ad.php?t=22786

                regards,
                --bob

                ------------------
                "It was too lonely at the top".

                Comment


                • #9
                  Thx guys
                  I think I get it!

                  Now what I want to do is add snippets of data like:

                  "Date","Time","O","H","L","C","V","OI"
                  04/21/1982,1515,226.55,227.80,226.25,227.65,3696,412
                  04/22/1982,1515,227.20,228.60,227.20,228.10,2827,719
                  04/23/1982,1515,228.60,229.95,228.45,229.85,2933,946
                  04/26/1982,1515,229.50,230.80,228.85,230.75,2871,1084
                  04/27/1982,1515,230.40,230.55,228.60,229.05,3854,1142
                  04/28/1982,1515,228.75,229.50,227.90,228.35,3998,1306
                  04/29/1982,1515,227.70,228.35,227.45,227.80,3446,1219
                  04/30/1982,1515,227.75,228.60,227.60,227.70,2722,1295
                  05/03/1982,1515,227.30,227.70,227.00,227.35,2695,1585
                  05/04/1982,1515,227.45,228.25,227.45,228.00,2467,1537
                  05/05/1982,1515,228.05,228.50,227.25,227.75,2556,1662
                  05/06/1982,1515,228.25,229.40,228.25,229.30,4574,2078
                  etc
                  etc

                  each snippet forms a complex pattern on a chart and is needed by my app to produce a series of patterns and the like.

                  I could just include many .txt files but its messy. I would rather stuff them all into a resource and ship one neat little .EXE.

                  So how do I include them,
                  and how do I access them?

                  ------------------
                  Kind Regards
                  Mike

                  Comment


                  • #10
                    just copying and pasting for ya, for the wav file, I use multiple wav files in my nuclear clock program (Hey, what fun is it if you don't hear a nuke exploding?)


                    Code:
                      posted October 02, 2000 05:40 PM              
                    --------------------------------------------------------------------------------
                    Here's how I do mine:
                    RESOURCE FILE:
                    '
                    'Does not seem to require a #define statement (??)
                    
                    WAVE1 WAV01 "AIRNUKE.WAV"
                    WAVE2 WAV02 "PING.WAV"
                    WAVE3 WAV03 "RESPONSE.WAV"
                    
                    
                    '
                    
                    PBDLL .BAS FILE:
                    
                    Declare Function PlayWavFromResource(hInstance As Long, WaveName As String, WaveType As String)As Long
                    
                    'To use:
                    WAV = "WAV"
                    g_Result = PlayWavFromResource(g_hInst,WAVE + "2",WAV + "02")
                    
                    '
                    '
                    '
                    Function PlayWavFromResource(hInstance As Long, WaveName As String, WaveType As String)As Long
                    'Function PlayWavFromResource(hInstance As Long, WaveName As Asciiz, WaveType As Asciiz)As Long
                    Local hRes As Long
                    Local lpWav As Byte Ptr
                    Local Wave1 As Asciiz * 10
                    Local Wav1 As Asciiz * 10
                    Wave1 = WaveName
                    Wav1 = WaveType
                    hRes = FindResource (hInstance, Wave1, Wav1)
                    If hRes Then
                    lpWav = LockResource (LoadResource (hInstance, hRes))
                    If lpWav Then Function = PlaySound(ByVal lpWav, hInstance, %SND_MEMORY Or %SND_ASYNC)
                    End If
                    End Function
                    
                    
                    ------------------
                    Scott
                    [email protected]
                    ------------------
                    Scott
                    Scott Turchin
                    MCSE, MCP+I
                    http://www.tngbbs.com
                    ----------------------
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                    Comment


                    • #11
                      Also I think a later post said something about releasing the resource, is that correct?


                      Scott

                      ------------------
                      Scott
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #12
                        For those following this thread later ... I now have two items in a resource file:
                        Ding.wav
                        Splash.bmp

                        the MyApp.rc file reads:
                        Ding SOUND Ding.WAV
                        Splash BITMAP Splash.bmp

                        the Make.bat file reads:
                        c:\pbdll60\bin\rc MyApp.rc
                        c:\pbdll60\bin\pbres MyApp.res

                        And in the resources are accessed in MyFile.bas with:
                        #RESOURCE "MyApp.PBR" ' Resources
                        '
                        '
                        hBmp = LoadImage(GetModuleHandle(BYVAL %NULL), "splash", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
                        '
                        '
                        CALL PlaySound("DING", BYVAL GetModuleHandle(BYVAL %NULL), %SND_RESOURCE OR %SND_SYNC)


                        anyone care to tell me how to add a buch of data to a resource?

                        ------------------
                        Kind Regards
                        Mike

                        Comment


                        • #13
                          You can embed a STRING table (although the strings are stored as Unicode in the compiled Resource file, so very large tables may inflate your EXE substantially.

                          You can also use the RCDATA type to embed 'binary' data... for more information, please consult the help files (RC.HLP and DLGEDIT.HLP).


                          ------------------
                          Lance
                          PowerBASIC Support
                          mailto:[email protected][email protected]</A>
                          Lance
                          mailto:[email protected]

                          Comment

                          Working...
                          X