|
-
Jul 6th, 2001, 09:19 AM
#1
Thread Starter
Member
WM_GETICON, IPictureDisp
Ok, anyone have any idea how i can turn a pointer to an icon (hIcon from a WM_GETICON) into an IPictureDisp object?
-
Jul 6th, 2001, 10:03 PM
#2
Fanatic Member
This should do it:
VB Code:
Public Declare Sub OleCreatePictureIndirect Lib "oleaut32.dll" (ByRef lpPICTDESC As PICTDESC, ByVal rIID As Long, ByVal fOwn As Long, ByVal lplpvObj As Long)
Public Type PICTDESC
cbSizeOfStruct As Long
picType As Long
hGDIObj As Long
hPalOrXYExt As Long 'this member isn't used for icons, but is for bitmaps
End Type
Public Type IID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Const hNull As Long = 0
Public Function IconToPicture(ByVal hIcon As Long) As IPicture
Dim ipic As IPicture
Dim picdes As PICTDESC
Dim iidIPicture As IID
If hIcon = hNull Then Exit Function
'Fill picture description
With picdes
.cbSizeOfStruct = Len(picdes)
.picType = vbPicTypeIcon
.hGDIObj = hIcon
End With
'Fill in magic IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
With iidIPicture
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(2) = &H0
.Data4(3) = &HAA
.Data4(4) = &H0
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With
'Create picture from icon handle
OleCreatePictureIndirect picdes, VarPtr(iidIPicture), True, VarPtr(ipic)
'Result will be valid a valid IPicture reference or Nothing
Set IconToPicture = ipic
End Function
Once you do this, you can do something like this:
VB Code:
Set PictureBox.Picture = IconToPicture(hIcon)
You can also modify this to take an hBitmap and return the object loaded with it. To do that, you'd say picdes.picType = vbPicTypeBitmap, picdes.hGDIObj = hBitmap, and you can include an optional parameter for in the function for hPal, and if passed in, put that into picdes.hPalOrXYExt. Then you'll get the object back with the bitmap rather than an icon.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Jul 7th, 2001, 02:06 PM
#3
Thread Starter
Member
that is perfect
Thank you, thats about all I can say. This is exactly what I needed.
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
|