Page 172 - DCAP408_WEB_PROGRAMMING
P. 172
Windows Programming
Notes
Did u know? To use the icons in a program, we use a VB 6 “Load Resource” function.
There are several of “Load Resource” functions to choose from:
LoadResPicture(index, format) for bitmaps, icons, and cursors
Use the VB predefined constants vbResBitmap for bitmaps, vbResIcon for icons, and vbResCursor
for cursors for the “format” parameter. This function returns a picture that you can use directly.
LoadResData (explained below) returns a string containing the actual bits in the file. We’ll see
how to use that after we demonstrate icons.
LoadResString(index) for strings
LoadResData(index, format) for anything up to 64K
!
Caution This function returns a string with the actual bits in the resource.
These are the values that can be used for format parameter here:
1. Cursor resource
2. Bitmap resource
3. Icon resource
4. Menu resource
5. Dialog box
6. String resource
7. Font directory resource
8. Font resource
9. Accelerator table
10. User-defined resource
11. Group cursor
12. Group icon
Since we have four icons in our About VB.RES resource file, let’s use LoadResPicture(index,
format) to assign these to the Picture property of a CommandButton in VB 6.
I created an application with four OptionButton components labeled Earth, Water, Air and Fire
and four Click events - one for each option. Then I added a CommandButton and changed the Style
property to “1 – Graphical”. This is necessary to be able to add a custom icon to the CommandButton.
The code for each OptionButton (and the Form Load event — to initialize it) looks like this (with
the Id and Caption changed accordingly for the other OptionButton Click events):
Private Sub Option1_Click()
Command1.Picture = _
LoadResPicture(101, vbResIcon)
Command1.Caption = _
“Earth”
End Sub
166 LOVELY PROFESSIONAL UNIVERSITY