|
-
Feb 17th, 2005, 05:32 PM
#1
Thread Starter
Frenzied Member
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
-
Feb 17th, 2005, 06:01 PM
#2
-
Feb 17th, 2005, 06:06 PM
#3
Thread Starter
Frenzied Member
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
-
Feb 17th, 2005, 10:18 PM
#4
Re: Images
reference Image.Picture which is IPictureDisp type, that way you can pass it in code.
e.g.
VB Code:
Public Function ReturnImgRef(ImageControl as Image) as IPictureDisp
ReturnImgRef = ImageControl.Picture
.....
If you want to load a picture from a path, in code, then load it quickly into other image controls, use
VB Code:
Dim Images(0 to x) as IPictureDisp
Image1.Picture= Images(x).Picture
...etc.
-
Feb 18th, 2005, 10:59 AM
#5
Thread Starter
Frenzied Member
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
-
Feb 18th, 2005, 11:28 AM
#6
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:
Private Const IMAGE_BITMAP As Long = 0
Private Const LR_LOADFROMFILE As Long = &H10
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
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private mlngBmp As Long
Private mlngOldBmp As Long
Private Sub Command1_Click()
Picture1.AutoRedraw = True
mlngBmp = LoadImage(0, "C:\SomeBitmap.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
mlngOldBmp = SelectObject(Picture1.hdc, mlngBmp)
Picture1.Refresh
End Sub
Private Sub Form_Unload(Cancel As Integer)
SelectObject Picture1.hdc, mlngOldBmp
DeleteObject mlngBmp
End Sub
-
Feb 18th, 2005, 11:54 AM
#7
Thread Starter
Frenzied Member
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
-
Feb 18th, 2005, 01:47 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|