Ok, anyone have any idea how i can turn a pointer to an icon (hIcon from a WM_GETICON) into an IPictureDisp object?
Printable View
Ok, anyone have any idea how i can turn a pointer to an icon (hIcon from a WM_GETICON) into an IPictureDisp object?
This should do it:
Once you do this, you can do something like this: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
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.
Thank you, thats about all I can say. This is exactly what I needed.