PDA

Click to See Complete Forum and Search --> : How store JGP in res file?


JeffSM
Nov 10th, 1999, 05:55 AM
Can VB save JPGs or GIFs in .res files?

Thanks in advance.
Jefferson

Serge
Nov 10th, 1999, 05:50 PM
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


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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)



[This message has been edited by Serge (edited 11-11-1999).]

rammy
Sep 13th, 2000, 07:24 AM
Is it possble to store JPEGs in the resource editor?

Sep 13th, 2000, 04:45 PM
Put this in your RC file.

1000 CUSTOM PRELOAD myjpg.jpg

Serge
Sep 13th, 2000, 05:04 PM
You can use this function I wrote a while back:

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


Now you can use this function like this:

Private Sub Command2_Click()
Image1.Picture = GetPictureFromResource(101)
End Sub

Nitro
Sep 13th, 2000, 11:18 PM
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!

Serge
Sep 14th, 2000, 09:17 AM
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.

Nitro
Sep 14th, 2000, 11:59 AM
Thanks Serge