Working With Resource File
Lesson 1
Accessing
BMP,
ICO and CUR files from your
Program
Now you have the resource file with all your
image files in it.
But how can you access them from your
program?
Start a new Project, add 1 Picture Box (named Picture1) to
your form, and add the following code to the form:
Private Sub Form_Load()
Picture1.Picture = LoadResPicture(101, vbResBitmap)
End
Sub
This code will load
the Bitmap that found under the Bitmap "Folder" in the resource file, with the
ID 101, to the Picture Box.
Explanation of this code:
LoadResPicture function load a picture
from the resource file.
101 - the ID of the picture you want to
load. if there is no Bitmap in your resource file with the ID 101, an error
will occur.
If your picture ID is a word like "Cube" instead of number
like 101, you should write:
Picture1.Picture = LoadResPicture("Cube",
vbResBitmap)
Note that the "Cube" is in quotes, and when the ID was a
number it was not in quotes.
vbResBitmap - Because the picture you want
to load is a Bitmap, and it's under the Bitmap "Folder" in the resource
file.
If you want to load an icon with the ID
"myIcon", use LoadResPicture("myIcon", vbResIcon)
and if you want to load
an cursor with the ID "myCursor" use
LoadResPicture("myCursor",
vbResCursor)
Summary:
To load BMP, Ico or Cur
file from resource file use:
LoadResPicture ("MyImageID",
vbRes...)
Where vbRes...=vbResBitmap if it's Bitmap
file,
vbRes...=vbResIcon if it's Icon file,
and
vbRes...=vbResCursor if it's cursor file.
Examples in the next page...