By: Jack Hoxley
Written: June 2000
Although not many people use
resource files, this is down to the common conception that they slow things
down, which at a certain point they will. However there are two main advantages:
- People, unless they have a
resource editor/decompiler cannot modify your pictures, or directly steal
- If the resources are located
in an ActiveX control you can replace the ActiveX control at a later date
to update graphics.
The two disadvantages are:
- The resources are compiled
into the EXE
- This makes the EXE big, which
after a certain point will slow the program down - not a good idea for a game.
It's up to you to choose if you
want to use them, it doesn't hurt to experiment...
One thing to note, you'll need
Visual basic 6 if you want to create your own resources within VB; otherwise
you'll have to do it seperately (VC++ for example).
The method for loading a bitmap
into a DirectDraw surface is done through the CreateSurfaceFromResource call,
which has the following parameters.
file As String, resName As String, ddsd As DDSURFACEDESC2) As DirectDrawSurface7
This is what you'll need to put
in the parameters:
Filename of the resource that is loaded onto the surface that is created. If
the resource is part of the executable, specifying an empty string for this
parameter locates the resource. This parameter can also be the name of an OCX
in which the resource is located.
Name of the resource that is loaded onto the surface that is created.
DDSURFACEDESC2 type that describes the requested surface. This will be
the same as when you create a normal surface.
An example of this;
is a DirectDraw7 variable, and should be initialised
Dim Mainsurf As DirectDrawSurface7
ddsd As DDSURFACEDESC2
Set Mainsurf = Nothing
'load the bitmap into a surface - backdrop.bmp
ddsd.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
ddsd.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
ddsd.lWidth = 'Width in pixels goes here
ddsd.lHeight = 'Height in pixels goes here
'This is our line for loading the resource Bitmap.
Set Mainsurf = dd.CreateSurfaceFromResource("", "101",
'This could be for loading
a resource from an ActiveX control. The control will need to be
'Registered with the system first.
'Set Mainsurf = dd.CreateSurfaceFromResource("C:\Windows\System\SomeControl.Ocx",
'You can now use this surface
the same as any other surface
One important thing to note;
if you run the program from the IDE (in visual Basic) you will get the error
DDERR_GENERIC, this is okay. DirectDraw will not find the resource if you're
not running from a compiled EXE. So, compile the EXE and run it outside of VB.