Results 1 to 8 of 8

Thread: How store JGP in res file?

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 1999
    Location
    Brazil
    Posts
    144

    Post

    Can VB save JPGs or GIFs in .res files?

    Thanks in advance.
    Jefferson

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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).]

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    Is it possble to store JPEGs in the resource editor?

  4. #4
    Guest
    Put this in your RC file.
    Code:
    1000 CUSTOM PRELOAD myjpg.jpg

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You can use this function I wrote a while back:
    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
    Now you can use this function like this:
    Code:
    Private Sub Command2_Click()
        Image1.Picture = GetPictureFromResource(101)
    End Sub

  6. #6
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    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!
    Chemically Formulated As:
    Dr. Nitro

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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.

  8. #8
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Thanks Serge
    Chemically Formulated As:
    Dr. Nitro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width