Can VB save JPGs or GIFs in .res files?
Thanks in advance.
Jefferson
Printable View
Can VB save JPGs or GIFs in .res files?
Thanks in advance.
Jefferson
VB6 comes with Resource Editor Add-In. Select Add-In manager from the Add-In menu and double click on VB6 Resource Editor. Then select Add New Resource File from Project menu. You'll be given a choice to give a name for your new resource file. Then you will notice that your Project Browser will have that new resource file. Double click on it. Then click on the Add Custom Resource... button on the toolbar. Again, you will get the Common Dialog to select the file you want. Now, comes the the programming part. For testing purposes just drop a PictureBox and Command button on the form. (I inserted a GIF file into Resource File). Put this on Command1_Click event
Code:Private Sub Command1_Click()
Dim arrByte() As Byte
Dim iFFN As Integer
Dim strTempPath As String
arrByte = LoadResData(101, "CUSTOM")
strTempPath = App.Path & "\~pictemp.gif"
iFFN = FreeFile
Open strTempPath For Binary As iFFN
Put #iFFN, , arrByte
Close #iFFN
Picture1.Picture = LoadPicture(strTempPath)
Kill strTempPath
End Sub
Regards,
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 11-11-1999).]
Is it possble to store JPEGs in the resource editor?
Put this in your RC file.
Code:1000 CUSTOM PRELOAD myjpg.jpg
You can use this function I wrote a while back:
Now you can use this function like this:Code:Public Function GetPictureFromResource(p_lngResourceID As Integer) As IPictureDisp
Dim bytArr() As Byte
Dim intFFN As Integer
Dim strPath As String
bytArr = LoadResData(p_lngResourceID, "CUSTOM")
strPath = App.Path & IIf(Right(App.Path, 1) = "\", "MyPicture.tmp", "\MyPicture.tmp")
intFFN = FreeFile
Open strPath For Binary As intFFN
Put #intFFN, , bytArr
Close #intFFN
Set GetPictureFromResource = LoadPicture(strPath)
Kill strPath
End Function
Code:Private Sub Command2_Click()
Image1.Picture = GetPictureFromResource(101)
End Sub
Serge,
How do you get all the numbers{101,102,103,104) in the res file?
I want to add it to a listbox and just click on it.
Thanks!
Unfortunately, you can't enumerate resources, because you have to know their IDs before hand. But you can create IDs in the resource as plain numbers like 1, 2, 3 ...etc and then populate ListBox with available numbers. Then you can use the function that I've provided to show an image in Image control based on the ID in the ListBox.
Thanks Serge