Results 1 to 8 of 8

Thread: Images

  1. #1

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Images

    Hey,

    Did anyone ever load an image in VB6 using a handle that's provided by the image/picture box conrol?
    I want to be able to return a handle from my function so I can load the image using a handle as oppose to the path.

    Thanks,
    Don't anthropomorphize computers -- they hate it

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Images

    I'm not sure I understand... A handle? What would that handle be? Generated from where? And most of all, why? What's the gain of this?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Images

    dim hdl as long
    hdl = LoadImage("SomePath").Handle

    I want to pass the handle back so the other function can load this image using the handle as oppose to teh path.
    Don't anthropomorphize computers -- they hate it

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Images

    reference Image.Picture which is IPictureDisp type, that way you can pass it in code.

    e.g.
    VB Code:
    1. Public Function ReturnImgRef(ImageControl as Image) as IPictureDisp
    2.     ReturnImgRef = ImageControl.Picture
    3. .....

    If you want to load a picture from a path, in code, then load it quickly into other image controls, use
    VB Code:
    1. Dim Images(0 to x) as IPictureDisp
    2. Image1.Picture= Images(x).Picture
    3. ...etc.

  5. #5

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Images

    The problem is that it's one application calling another.
    So this is the scenario.

    Application 1 calls a function in application 2 to get an image.
    right now, application 2 returns the path of the image.
    I want to return teh handle so that application 1 can load the image using the handle as oppose to the path. That way I don't have to have the images on the hard drive but in a resource file.

    My problem is how do I load the image using the handle?
    Thanks,
    Don't anthropomorphize computers -- they hate it

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Images

    Assuming that Handle is a "handle to a bitmap gdi object", you can do load it into a PictureBox easy enough but not an Image control.

    Try this sample code.
    VB Code:
    1. Private Const IMAGE_BITMAP As Long = 0
    2. Private Const LR_LOADFROMFILE As Long = &H10
    3.  
    4. Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
    5. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    6. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    7.  
    8. Private mlngBmp As Long
    9. Private mlngOldBmp As Long
    10.  
    11. Private Sub Command1_Click()
    12.     Picture1.AutoRedraw = True
    13.     mlngBmp = LoadImage(0, "C:\SomeBitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
    14.     mlngOldBmp = SelectObject(Picture1.hdc, mlngBmp)
    15.     Picture1.Refresh
    16. End Sub
    17.  
    18. Private Sub Form_Unload(Cancel As Integer)
    19.     SelectObject Picture1.hdc, mlngOldBmp
    20.     DeleteObject mlngBmp
    21. End Sub

  7. #7

    Thread Starter
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950

    Re: Images

    But this still uses the path to load the image.
    I want to load the image into the picturebox using the handle.
    Don't anthropomorphize computers -- they hate it

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Images

    My code sample was just to show you how to load an image using the handle. I assumed you could figure out how to put the code which loads the image into "Application #2".

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