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,
Printable View
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,
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? :)
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.
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.
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,
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
But this still uses the path to load the image.
I want to load the image into the picturebox using the handle.
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".