Resources with Embedded Images and Sounds


'Demo of loading image and sound from resource in your exe.
'This demo uses one bmp and one wave. You can add as many as you want.
'Make copy of runtime engine and give it your program name.
'Name copy of run.exe something like MYPROG.EXE
'Download reshacker.exe. It is available on many sites, including
'http://download.cnet.com/Resource-Hacker/3000-2352_4-10178587.html
'Use reshacker.exe to open your exe (MYPROG.EXE).
'Use Action menu to add bitmap resource. I added a smiley sprite
'    from LB's sprite folder.
'Give each bitmap a unique resource name. I used SMILEY.
'Use Action menu to add a wave resource. I added beep.wave
'    from LB's media folder.
'The type is WAVE, the name is BEEP in my demo MYPROG.EXE.
'Save the altered runtime engine, MYPROG.EXE
'Tokenize the following code and save it in the same
'    folder as the renamed runtime engine.
'    Name TKN the same as runtime. Mine is MYPROG.TKN
'Run program by running exe, not from IDE.
'You will see the smiley bmp in the graphicbox.
 
nomainwin
graphicbox #1.g, 0,0,200,200
button #1.b, "Play Wave",[play],UL,10,210,100,30
open "test" for window as #1
#1 "trapclose [quit]"
 
    hWin=hwnd(#1) 'program window handle
 
    CallDLL #user32, "GetWindowLongA",_
        hWin As ulong,_            'window handle
        _GWL_HINSTANCE As long,_   'flag for type
        hInstance As ulong         'returns instance handle
 
    calldll #user32, "LoadImageA",_
         hInstance as ulong,_     'instance handle
        "SMILEY" as ptr,_         'name given to image resource
        _IMAGE_BITMAP as long,_   'type of image
        50 as long,_              'desired width
        100 as long,_             'desired height
        _LR_CREATEDIBSECTION as long,_  'load flag
        hImage as Ulong             'handle of loaded image
 
    loadbmp "smiley",hImage
    #1.g "down; drawbmp smiley;flush"
    wait
 
[play]
    SND.SYNC = 0
    SND.ASYNC = 1
    SND.LOOP = 8 'must be used with SND.ASYNC
    SND.FILENAME = 131072
    SND.RESOURCE = 262148
 
    sFlags=SND.RESOURCE OR SND.ASYNC
    calldll #winmm, "PlaySound",_
        "BEEP" as ptr,_     'name of wave resource
        hInstance as ulong,_    'instance handle
        sFlags as ulong,_       'flags for playing sound
        result as long
 
        wait
 
[quit] close #1:end

Home

Source Code

Utilities

Internet

Games

Graphics

Media Demos

Snippets

DLL's

API Resources

Freeware

LB 4 Companion

Mastering LB 3

LB Workshop

Game Workshop

Links

Index