Please support our sponsor:
Welcome To DirectX 4 VB! Multimedia Visual Basic at its best...




DirectDraw: Using Resources
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:

  1. People, unless they have a resource editor/decompiler cannot modify your pictures, or directly steal the files.
  2. 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:

  1. The resources are compiled into the EXE
  2. 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.

DirectDraw7.CreateSurfaceFromFile( file As String, resName As String, ddsd As DDSURFACEDESC2) As DirectDrawSurface7

This is what you'll need to put in the parameters:

file
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.
resName
Name of the resource that is loaded onto the surface that is created.
ddsd
DDSURFACEDESC2 type that describes the requested surface
. This will be the same as when you create a normal surface.

An example of this;

'dd is a DirectDraw7 variable, and should be initialised
Dim Mainsurf As DirectDrawSurface7

Dim 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", ddsd)

'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", "101", ddsd)


'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.

DirectX 4 VB © 2000 Jack Hoxley. All rights reserved.
Reproduction of this site and it's contents, in whole or in part, is prohibited,
except where explicitly stated otherwise.
Design by Mateo
Contact Webmaster
This site is hosted by Exhedra Solutions, Inc., the parent company of RentACoder.com and PlanetSourceCode.com