Make your own free website on Tripod.com
Working With Resource File

Lesson 2
Tutorials - Page 1 - Page 2 - Page 3 - Page 4 - Page 5

Accessing GIF and JPG files from your Program - Example
This example will show you how to use the LoadDataIntoFile function to load GIF or JPG file from resource file into Picture Box.

Add 1 Picture Box to your form (named Picture1) and add 1 GIF or JPG file to your Resouce File. Set the file ID to be 101.

Copy the following code to your form:

Public Sub LoadDataIntoFile(DataName As Integer, FileName As String)
    Dim myArray() As Byte
    Dim
myFile As Long
    If
Dir(FileName) = "" Then
        myArray = LoadResData(DataName, "CUSTOM")
        myFile = FreeFile
        Open FileName For Binary Access Write As #myFile
        Put #myFile, , myArray
        Close #myFile
    End If
End Sub


Private Sub
Form_Load()  
'this will copy the GIF/JPG file to c:\tmpfile.$$$
   
LoadDataIntoFile 101, "c:\tmpfile.$$$"
'this will load the c:\tmpfile.$$$ file to Picture1 Picture Box
    Picture1.Picture = LoadPicture("c:\tmpfile.$$$")
End Sub

Run the program. The Gif/JPG file will be displayed in the picture Box.


Back  Forward